Merge pull request from Kha/struct-lit-base

Fix negative overflow and missing '..' on struct lit base exprs
This commit is contained in:
Marcus Klaas de Vries 2015-09-20 17:42:23 +02:00
commit 0952d7354e
3 changed files with 23 additions and 3 deletions
src
tests
source
target

@ -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)))
}
}
},

@ -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 };
}

@ -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 };
}