Skip to content

Commit ce62f0a

Browse files
authored
Merge pull request #1997 from topecongiro/issue-1995
Fix a budget bug in Arg::rewrite()
2 parents 26fa751 + dd0dcdf commit ce62f0a

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-5
lines changed

src/items.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1598,11 +1598,12 @@ impl Rewrite for ast::Arg {
15981598
if context.config.space_after_type_annotation_colon() {
15991599
result.push_str(" ");
16001600
}
1601-
let max_width = try_opt!(shape.width.checked_sub(result.len()));
1602-
let ty_str = try_opt!(self.ty.rewrite(
1603-
context,
1604-
Shape::legacy(max_width, shape.indent + result.len()),
1605-
));
1601+
let overhead = last_line_width(&result);
1602+
let max_width = try_opt!(shape.width.checked_sub(overhead));
1603+
let ty_str = try_opt!(
1604+
self.ty
1605+
.rewrite(context, Shape::legacy(max_width, shape.indent))
1606+
);
16061607
result.push_str(&ty_str);
16071608
}
16081609

tests/source/impls.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,16 @@ pub trait Number: Copy + Eq + Not<Output = Self> + Shl<u8, Output = Self> +
139139
pub trait SomeTrait : Clone + Eq + PartialEq + Ord + PartialOrd + Default + Hash + Debug + Display + Write + Read + FromStr {
140140
// comment
141141
}
142+
143+
// #1995
144+
impl Foo {
145+
fn f(
146+
S {
147+
aaaaaaaaaa: aaaaaaaaaa,
148+
bbbbbbbbbb: bbbbbbbbbb,
149+
cccccccccc: cccccccccc,
150+
}: S
151+
) -> u32{
152+
1
153+
}
154+
}

tests/target/impls.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,3 +202,16 @@ pub trait SomeTrait
202202
+ FromStr {
203203
// comment
204204
}
205+
206+
// #1995
207+
impl Foo {
208+
fn f(
209+
S {
210+
aaaaaaaaaa: aaaaaaaaaa,
211+
bbbbbbbbbb: bbbbbbbbbb,
212+
cccccccccc: cccccccccc,
213+
}: S,
214+
) -> u32 {
215+
1
216+
}
217+
}

0 commit comments

Comments
 (0)