diff --git a/compiler/rustc_ast_pretty/src/pp.rs b/compiler/rustc_ast_pretty/src/pp.rs index e1f43cb20dc38..26d600cefc7c0 100644 --- a/compiler/rustc_ast_pretty/src/pp.rs +++ b/compiler/rustc_ast_pretty/src/pp.rs @@ -136,6 +136,7 @@ mod ring; use ring::RingBuffer; use std::borrow::Cow; +use std::cmp; use std::collections::VecDeque; use std::iter; @@ -199,10 +200,13 @@ enum PrintFrame { const SIZE_INFINITY: isize = 0xffff; +/// Target line width. +const MARGIN: isize = 78; +/// Every line is allowed at least this much space, even if highly indented. +const MIN_SPACE: isize = 60; + pub struct Printer { out: String, - /// Width of lines we're constrained to - margin: isize, /// Number of spaces left on line space: isize, /// Ring-buffer of tokens and calculated sizes @@ -237,11 +241,9 @@ struct BufEntry { impl Printer { pub fn new() -> Self { - let linewidth = 78; Printer { out: String::new(), - margin: linewidth as isize, - space: linewidth as isize, + space: MARGIN, buf: RingBuffer::new(), left_total: 0, right_total: 0, @@ -395,7 +397,7 @@ impl Printer { self.print_stack.push(PrintFrame::Broken { indent: self.indent, breaks: token.breaks }); self.indent = match token.indent { IndentStyle::Block { offset } => (self.indent as isize + offset) as usize, - IndentStyle::Visual => (self.margin - self.space) as usize, + IndentStyle::Visual => (MARGIN - self.space) as usize, }; } else { self.print_stack.push(PrintFrame::Fits); @@ -421,7 +423,7 @@ impl Printer { self.out.push('\n'); let indent = self.indent as isize + token.offset; self.pending_indentation = indent; - self.space = self.margin - indent; + self.space = cmp::max(MARGIN - indent, MIN_SPACE); } } diff --git a/src/test/pretty/issue-4264.pp b/src/test/pretty/issue-4264.pp index 3830c3aa6c9f1..ea74a267be81e 100644 --- a/src/test/pretty/issue-4264.pp +++ b/src/test/pretty/issue-4264.pp @@ -35,8 +35,7 @@ for<'r> fn(Arguments<'r>) -> String {format})(((::core::fmt::Arguments::new_v1 as fn(&[&'static str], &[ArgumentV1]) -> Arguments {Arguments::new_v1})((&([("test" - as &str)] as [&str; 1]) as - &[&str; 1]), + as &str)] as [&str; 1]) as &[&str; 1]), (&([] as [ArgumentV1; 0]) as &[ArgumentV1; 0])) as Arguments)) as String); (res as String) diff --git a/src/test/ui/match/issue-82392.stdout b/src/test/ui/match/issue-82392.stdout index 2054d43c40957..bcab76b7c6b69 100644 --- a/src/test/ui/match/issue-82392.stdout +++ b/src/test/ui/match/issue-82392.stdout @@ -11,7 +11,6 @@ pub fn main() ({ ({ } as ()) else if (let Some(a) = ((Some as - fn(i32) -> Option {Option::::Some})((3 - as i32)) as Option) as bool) ({ } as ()) - as ()) + fn(i32) -> Option {Option::::Some})((3 as i32)) as + Option) as bool) ({ } as ()) as ()) } as ()) diff --git a/src/test/ui/proc-macro/quote-debug.stdout b/src/test/ui/proc-macro/quote-debug.stdout index 79651f01b9534..a648d6b6d4b54 100644 --- a/src/test/ui/proc-macro/quote-debug.stdout +++ b/src/test/ui/proc-macro/quote-debug.stdout @@ -27,8 +27,7 @@ fn main() { crate::TokenStream::from(crate::TokenTree::Literal({ let mut iter = "\"world\"".parse::().unwrap().into_iter(); - if let (Some(crate::TokenTree::Literal(mut lit)), - None) = + if let (Some(crate::TokenTree::Literal(mut lit)), None) = (iter.next(), iter.next()) { lit.set_span(crate::Span::recover_proc_macro_span(2)); lit