Skip to content

Commit 09bd4a7

Browse files
committed
Avoid dangling )
1 parent c1fc693 commit 09bd4a7

File tree

2 files changed

+6
-26
lines changed

2 files changed

+6
-26
lines changed

src/expr.rs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -127,24 +127,13 @@ impl<'a> FmtVisitor<'a> {
127127

128128
fn rewrite_paren(&mut self, subexpr: &ast::Expr, width: usize, offset: usize) -> String {
129129
debug!("rewrite_paren, width: {}, offset: {}", width, offset);
130-
// 1 is for opening paren
131-
let subexpr_str = self.rewrite_expr(subexpr, width-1, offset+1);
130+
// 1 is for opening paren, 2 is for opening+closing, we want to keep the closing
131+
// paren on the same line as the subexpr
132+
let subexpr_str = self.rewrite_expr(subexpr, width-2, offset+1);
132133
debug!("rewrite_paren, subexpr_str: `{}`", subexpr_str);
133-
let mut lines = subexpr_str.rsplit('\n');
134-
let last_line_len = lines.next().unwrap().len();
135-
let last_line_offset = match lines.next() {
136-
None => offset+1,
137-
Some(_) => 0,
138-
};
139-
if width + offset - last_line_offset - last_line_len > 0 {
140-
format!("({})", subexpr_str)
141-
} else {
142-
// FIXME That's correct unless we have width < 2. Return an Option for such cases ?
143-
format!("({}\n{} )", subexpr_str, make_indent(offset))
144-
}
134+
format!("({})", subexpr_str)
145135
}
146136

147-
148137
pub fn rewrite_expr(&mut self, expr: &ast::Expr, width: usize, offset: usize) -> String {
149138
match expr.node {
150139
ast::Expr_::ExprLit(ref l) => {

tests/idem/paren.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,6 @@
22

33
fn foo() {
44
let very_long_variable_name = (a + first + simple + test);
5-
let very_long_variable_name = (write + something + here + to + fill + the + line + 12 + 34 + 567
6-
);
7-
let very_long_variable_name = (write + something + here + to + fill + the + line + 12 + 34 + 567
8-
+ 78);
9-
let very_long_variable_name = (write + something + here + to + fill + the + line + 12 + 34 + 567
10-
+ 78 + fill + another + line + AAAA + BBBBBBB + CCCCCCCCCCCCCCCCC
11-
);
12-
let very_long_variable_name = (write + something + here + to + fill + the + line + 12 + 34 + 567
13-
+ 78 + fill + another + line + AAAA + BBBBBBB + CCCCCCCCCCCCCCC +
14-
DDDDDDD + EEEEEE);
15-
5+
let very_long_variable_name = (a + first + simple + test + AAAAAAAAAAAAA + BBBBBBBBBBBBBBBBBB +
6+
b + c);
167
}

0 commit comments

Comments
 (0)