diff --git a/src/items.rs b/src/items.rs index ee4cd866ac25..66fdaf50e5aa 100644 --- a/src/items.rs +++ b/src/items.rs @@ -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); diff --git a/tests/source/type.rs b/tests/source/type.rs index 2df68490d5d8..b622d4363f53 100644 --- a/tests/source/type.rs +++ b/tests/source/type.rs @@ -91,3 +91,25 @@ macro_rules! foo { } type Target = ( FooAPI ) + 'static; + +// #3117 +fn issue3117() { + { + { + { + { + { + { + { + { + let opt: &mut Option = + unsafe { &mut *self.future.get() }; + } + } + } + } + } + } + } + } +} diff --git a/tests/target/type.rs b/tests/target/type.rs index 7fb6e0fdf251..d2c09cc354ad 100644 --- a/tests/target/type.rs +++ b/tests/target/type.rs @@ -90,3 +90,25 @@ macro_rules! foo { } type Target = (FooAPI) + 'static; + +// #3117 +fn issue3117() { + { + { + { + { + { + { + { + { + let opt: &mut Option = + unsafe { &mut *self.future.get() }; + } + } + } + } + } + } + } + } +}