Skip to content

Commit 8193fd2

Browse files
committed
types: don't put parentheses around display of outermost type
So e.g. (1 * 1) -> ((1 + 1) * 1) becomes 1 * 1 -> (1 + 1) * 1
1 parent 2adb0a8 commit 8193fd2

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

src/types/final_data.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,14 @@ impl fmt::Display for Final {
115115
f.write_str("1")?;
116116
}
117117
(CompleteBound::Sum(..), 0) | (CompleteBound::Product(..), 0) => {
118-
f.write_str("(")?;
118+
if data.index > 0 {
119+
f.write_str("(")?;
120+
}
119121
}
120122
(CompleteBound::Sum(..), 2) | (CompleteBound::Product(..), 2) => {
121-
f.write_str(")")?;
123+
if data.index > 0 {
124+
f.write_str(")")?;
125+
}
122126
}
123127
(CompleteBound::Sum(..), _) => f.write_str(" + ")?,
124128
(CompleteBound::Product(..), _) => f.write_str(" × ")?,
@@ -216,9 +220,9 @@ mod tests {
216220
assert_eq!(ty1.to_string(), "2^1024");
217221

218222
let sum = Final::sum(Final::two_two_n(5), Final::two_two_n(10));
219-
assert_eq!(sum.to_string(), "(2^32 + 2^1024)");
223+
assert_eq!(sum.to_string(), "2^32 + 2^1024");
220224

221225
let prod = Final::product(Final::two_two_n(5), Final::two_two_n(10));
222-
assert_eq!(prod.to_string(), "(2^32 × 2^1024)");
226+
assert_eq!(prod.to_string(), "2^32 × 2^1024");
223227
}
224228
}

src/types/mod.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,8 +332,16 @@ impl fmt::Display for Bound {
332332
match (&*data.node, data.n_children_yielded) {
333333
(Bound::Free(ref s), _) => f.write_str(s)?,
334334
(Bound::Complete(ref comp), _) => fmt::Display::fmt(comp, f)?,
335-
(Bound::Sum(..), 0) | (Bound::Product(..), 0) => f.write_str("(")?,
336-
(Bound::Sum(..), 2) | (Bound::Product(..), 2) => f.write_str(")")?,
335+
(Bound::Sum(..), 0) | (Bound::Product(..), 0) => {
336+
if data.index > 0 {
337+
f.write_str("(")?
338+
}
339+
}
340+
(Bound::Sum(..), 2) | (Bound::Product(..), 2) => {
341+
if data.index > 0 {
342+
f.write_str(")")?
343+
}
344+
}
337345
(Bound::Sum(..), _) => f.write_str(" + ")?,
338346
(Bound::Product(..), _) => f.write_str(" × ")?,
339347
}

0 commit comments

Comments
 (0)