Avoid dangling )

This commit is contained in:
Gaëtan Cassiers 2015-05-24 23:46:02 +02:00
parent c1fc693c5e
commit 09bd4a74e4
2 changed files with 6 additions and 26 deletions

View File

@ -127,24 +127,13 @@ impl<'a> FmtVisitor<'a> {
fn rewrite_paren(&mut self, subexpr: &ast::Expr, width: usize, offset: usize) -> String {
debug!("rewrite_paren, width: {}, offset: {}", width, offset);
// 1 is for opening paren
let subexpr_str = self.rewrite_expr(subexpr, width-1, offset+1);
// 1 is for opening paren, 2 is for opening+closing, we want to keep the closing
// paren on the same line as the subexpr
let subexpr_str = self.rewrite_expr(subexpr, width-2, offset+1);
debug!("rewrite_paren, subexpr_str: `{}`", subexpr_str);
let mut lines = subexpr_str.rsplit('\n');
let last_line_len = lines.next().unwrap().len();
let last_line_offset = match lines.next() {
None => offset+1,
Some(_) => 0,
};
if width + offset - last_line_offset - last_line_len > 0 {
format!("({})", subexpr_str)
} else {
// FIXME That's correct unless we have width < 2. Return an Option for such cases ?
format!("({}\n{} )", subexpr_str, make_indent(offset))
}
format!("({})", subexpr_str)
}
pub fn rewrite_expr(&mut self, expr: &ast::Expr, width: usize, offset: usize) -> String {
match expr.node {
ast::Expr_::ExprLit(ref l) => {

View File

@ -2,15 +2,6 @@
fn foo() {
let very_long_variable_name = (a + first + simple + test);
let very_long_variable_name = (write + something + here + to + fill + the + line + 12 + 34 + 567
);
let very_long_variable_name = (write + something + here + to + fill + the + line + 12 + 34 + 567
+ 78);
let very_long_variable_name = (write + something + here + to + fill + the + line + 12 + 34 + 567
+ 78 + fill + another + line + AAAA + BBBBBBB + CCCCCCCCCCCCCCCCC
);
let very_long_variable_name = (write + something + here + to + fill + the + line + 12 + 34 + 567
+ 78 + fill + another + line + AAAA + BBBBBBB + CCCCCCCCCCCCCCC +
DDDDDDD + EEEEEE);
let very_long_variable_name = (a + first + simple + test + AAAAAAAAAAAAA + BBBBBBBBBBBBBBBBBB +
b + c);
}