Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 825207d

Browse files
authored
Merge pull request rust-lang#3126 from topecongiro/issue-3117
Use correct width when formatting type on local statement
2 parents a8d6874 + 086c183 commit 825207d

File tree

3 files changed

+54
-4
lines changed

3 files changed

+54
-4
lines changed

src/items.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,16 @@ impl Rewrite for ast::Local {
9494

9595
if let Some(ref ty) = self.ty {
9696
let separator = type_annotation_separator(context.config);
97-
let indent = shape.indent + last_line_width(&result) + separator.len();
98-
// 1 = ;
99-
let budget = shape.width.checked_sub(indent.width() + 1)?;
100-
let rewrite = ty.rewrite(context, Shape::legacy(budget, indent))?;
97+
let ty_shape = if pat_str.contains('\n') {
98+
shape.with_max_width(context.config)
99+
} else {
100+
shape
101+
}
102+
.offset_left(last_line_width(&result) + separator.len())?
103+
// 2 = ` =`
104+
.sub_width(2)?;
105+
106+
let rewrite = ty.rewrite(context, ty_shape)?;
101107

102108
infix.push_str(separator);
103109
infix.push_str(&rewrite);

tests/source/type.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,25 @@ macro_rules! foo {
9191
}
9292

9393
type Target = ( FooAPI ) + 'static;
94+
95+
// #3117
96+
fn issue3117() {
97+
{
98+
{
99+
{
100+
{
101+
{
102+
{
103+
{
104+
{
105+
let opt: &mut Option<MyLongTypeHere> =
106+
unsafe { &mut *self.future.get() };
107+
}
108+
}
109+
}
110+
}
111+
}
112+
}
113+
}
114+
}
115+
}

tests/target/type.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,25 @@ macro_rules! foo {
9090
}
9191

9292
type Target = (FooAPI) + 'static;
93+
94+
// #3117
95+
fn issue3117() {
96+
{
97+
{
98+
{
99+
{
100+
{
101+
{
102+
{
103+
{
104+
let opt: &mut Option<MyLongTypeHere> =
105+
unsafe { &mut *self.future.get() };
106+
}
107+
}
108+
}
109+
}
110+
}
111+
}
112+
}
113+
}
114+
}

0 commit comments

Comments
 (0)