Merge pull request #1997 from topecongiro/issue-1995

Fix a budget bug in Arg::rewrite()
This commit is contained in:
Nick Cameron 2017-09-29 20:40:53 +08:00 committed by GitHub
commit ce62f0a7ec
3 changed files with 32 additions and 5 deletions

View File

@ -1598,11 +1598,12 @@ impl Rewrite for ast::Arg {
if context.config.space_after_type_annotation_colon() {
result.push_str(" ");
}
let max_width = try_opt!(shape.width.checked_sub(result.len()));
let ty_str = try_opt!(self.ty.rewrite(
context,
Shape::legacy(max_width, shape.indent + result.len()),
));
let overhead = last_line_width(&result);
let max_width = try_opt!(shape.width.checked_sub(overhead));
let ty_str = try_opt!(
self.ty
.rewrite(context, Shape::legacy(max_width, shape.indent))
);
result.push_str(&ty_str);
}

View File

@ -139,3 +139,16 @@ pub trait Number: Copy + Eq + Not<Output = Self> + Shl<u8, Output = Self> +
pub trait SomeTrait : Clone + Eq + PartialEq + Ord + PartialOrd + Default + Hash + Debug + Display + Write + Read + FromStr {
// comment
}
// #1995
impl Foo {
fn f(
S {
aaaaaaaaaa: aaaaaaaaaa,
bbbbbbbbbb: bbbbbbbbbb,
cccccccccc: cccccccccc,
}: S
) -> u32{
1
}
}

View File

@ -202,3 +202,16 @@ pub trait SomeTrait
+ FromStr {
// comment
}
// #1995
impl Foo {
fn f(
S {
aaaaaaaaaa: aaaaaaaaaa,
bbbbbbbbbb: bbbbbbbbbb,
cccccccccc: cccccccccc,
}: S,
) -> u32 {
1
}
}