Skip to content

Commit

Permalink
Fix negative overflow and missing '..' on struct lit base exprs
Browse files Browse the repository at this point in the history
  • Loading branch information
Kha committed Sep 20, 2015
1 parent ce2c4f6 commit 9bd502a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/expr.rs
Expand Up @@ -1108,9 +1108,14 @@ fn rewrite_struct_lit<'a>(context: &RewriteContext,
}
StructLitField::Base(ref expr) => {
// 2 = ..
expr.rewrite(inner_context, h_budget - 2, indent + 2)
.map(|s| format!("..{}", s))
.unwrap_or(context.snippet(expr.span))
format!("..{}",
h_budget.checked_sub(2)
.and_then(|h_budget| {
expr.rewrite(inner_context,
h_budget,
indent + 2)
})
.unwrap_or(context.snippet(expr.span)))
}
}
},
Expand Down
8 changes: 8 additions & 0 deletions tests/source/expr.rs
Expand Up @@ -173,3 +173,11 @@ fn arrays() {

[ 1 + 3, 4 , 5, 6, 7, 7, fncall::<Vec<_>>(3-1)]
}

fn struct_exprs() {
Foo
{ a : 1, b:f( 2)};
Foo{a:1,b:f(2),..g(3)};
// FIXME: should be wrapped (#231)
LoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooongStruct { ..base };
}
7 changes: 7 additions & 0 deletions tests/target/expr.rs
Expand Up @@ -183,3 +183,10 @@ fn arrays() {

[1 + 3, 4, 5, 6, 7, 7, fncall::<Vec<_>>(3 - 1)]
}

fn struct_exprs() {
Foo { a: 1, b: f(2) };
Foo { a: 1, b: f(2), ..g(3) };
// FIXME: should be wrapped (#231)
LoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooongStruct { ..base };
}

0 comments on commit 9bd502a

Please sign in to comment.