diff --git a/src/shape.rs b/src/shape.rs index d793d99a3183a..5524a21f4b7fc 100644 --- a/src/shape.rs +++ b/src/shape.rs @@ -228,6 +228,10 @@ impl Shape { } } + pub fn saturating_sub_width(&self, width: usize) -> Shape { + self.sub_width(width).unwrap_or(Shape { width: 0, ..*self }) + } + pub fn sub_width(&self, width: usize) -> Option { Some(Shape { width: self.width.checked_sub(width)?, diff --git a/src/visitor.rs b/src/visitor.rs index 3bd5af3112de3..56a27889c201f 100644 --- a/src/visitor.rs +++ b/src/visitor.rs @@ -536,7 +536,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> { skip_out_of_file_lines_range_visitor!(self, mac.span); // 1 = ; - let shape = self.shape().sub_width(1).unwrap(); + let shape = self.shape().saturating_sub_width(1); let rewrite = self.with_context(|ctx| rewrite_macro(mac, ident, ctx, shape, pos)); self.push_rewrite(mac.span, rewrite); } diff --git a/tests/source/expr.rs b/tests/source/expr.rs index 514f755c6988b..1bb2d9014e2d1 100644 --- a/tests/source/expr.rs +++ b/tests/source/expr.rs @@ -479,3 +479,56 @@ fn issue3226() { } } } + +// #3457 +fn issue3457() { + { + { + { + { + { + { + { + { + { + { + { + { + { + { + { + { + { + { + { + { + { + { + { + { + println!("Test"); + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } +} diff --git a/tests/target/expr.rs b/tests/target/expr.rs index e46cb898232fc..88de6f7fb88c1 100644 --- a/tests/target/expr.rs +++ b/tests/target/expr.rs @@ -562,3 +562,56 @@ fn issue3226() { } } } + +// #3457 +fn issue3457() { + { + { + { + { + { + { + { + { + { + { + { + { + { + { + { + { + { + { + { + { + { + { + { + { + println!("Test"); + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } +}