Fix negative overflow and missing '..' on struct lit base exprs
This commit is contained in:
parent
ce2c4f6be6
commit
9bd502ad54
3 changed files with 23 additions and 3 deletions
11
src/expr.rs
11
src/expr.rs
|
@ -1108,9 +1108,14 @@ fn rewrite_struct_lit<'a>(context: &RewriteContext,
|
||||||
}
|
}
|
||||||
StructLitField::Base(ref expr) => {
|
StructLitField::Base(ref expr) => {
|
||||||
// 2 = ..
|
// 2 = ..
|
||||||
expr.rewrite(inner_context, h_budget - 2, indent + 2)
|
format!("..{}",
|
||||||
.map(|s| format!("..{}", s))
|
h_budget.checked_sub(2)
|
||||||
.unwrap_or(context.snippet(expr.span))
|
.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)]
|
[ 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)]
|
[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…
Add table
Add a link
Reference in a new issue