Merge pull request #335 from Kha/struct-lit-base
Fix negative overflow and missing '..' on struct lit base exprs
This commit is contained in:
commit
0952d7354e
11
src/expr.rs
11
src/expr.rs
@ -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 };
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user