Skip to content

Commit

Permalink
Merge pull request rust-lang#3126 from topecongiro/issue-3117
Browse files Browse the repository at this point in the history
Use correct width when formatting type on local statement
  • Loading branch information
nrc committed Oct 22, 2018
2 parents a8d6874 + 086c183 commit 825207d
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,16 @@ impl Rewrite for ast::Local {

if let Some(ref ty) = self.ty {
let separator = type_annotation_separator(context.config);
let indent = shape.indent + last_line_width(&result) + separator.len();
// 1 = ;
let budget = shape.width.checked_sub(indent.width() + 1)?;
let rewrite = ty.rewrite(context, Shape::legacy(budget, indent))?;
let ty_shape = if pat_str.contains('\n') {
shape.with_max_width(context.config)
} else {
shape
}
.offset_left(last_line_width(&result) + separator.len())?
// 2 = ` =`
.sub_width(2)?;

let rewrite = ty.rewrite(context, ty_shape)?;

infix.push_str(separator);
infix.push_str(&rewrite);
Expand Down
22 changes: 22 additions & 0 deletions tests/source/type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,25 @@ macro_rules! foo {
}

type Target = ( FooAPI ) + 'static;

// #3117
fn issue3117() {
{
{
{
{
{
{
{
{
let opt: &mut Option<MyLongTypeHere> =
unsafe { &mut *self.future.get() };
}
}
}
}
}
}
}
}
}
22 changes: 22 additions & 0 deletions tests/target/type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,25 @@ macro_rules! foo {
}

type Target = (FooAPI) + 'static;

// #3117
fn issue3117() {
{
{
{
{
{
{
{
{
let opt: &mut Option<MyLongTypeHere> =
unsafe { &mut *self.future.get() };
}
}
}
}
}
}
}
}
}

0 comments on commit 825207d

Please sign in to comment.