From cab453250a3ceae5cf0cf7eac836c03b37e4ca8e Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Tue, 9 Jul 2019 09:26:50 -0400 Subject: Move pp::Printer helpers to direct impl --- src/libsyntax/parse/parser.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/libsyntax/parse/parser.rs') diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index a95b6891fb9..7dd7000b454 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -2571,7 +2571,6 @@ impl<'a> Parser<'a> { None => continue, }; let sugg = pprust::to_string(|s| { - use crate::print::pprust::PrintState; s.popen(); s.print_expr(&e); s.s.word( "."); @@ -4588,7 +4587,7 @@ impl<'a> Parser<'a> { stmt_span = stmt_span.with_hi(self.prev_span.hi()); } let sugg = pprust::to_string(|s| { - use crate::print::pprust::{PrintState, INDENT_UNIT}; + use crate::print::pprust::INDENT_UNIT; s.ibox(INDENT_UNIT); s.bopen(); s.print_stmt(&stmt); -- cgit 1.4.1-3-g733a5 From 63fdf1a5274d19865ba27742b3b5c4e0c94b1838 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Tue, 9 Jul 2019 09:30:08 -0400 Subject: Remove needless indent arguments We're always indenting by INDENT_UNIT anyway --- src/librustc/hir/print.rs | 23 +++++++---------------- src/libsyntax/parse/parser.rs | 2 +- src/libsyntax/print/pprust.rs | 19 ++++++++----------- 3 files changed, 16 insertions(+), 28 deletions(-) (limited to 'src/libsyntax/parse/parser.rs') diff --git a/src/librustc/hir/print.rs b/src/librustc/hir/print.rs index dd5d8ebde1c..f10efbacf2a 100644 --- a/src/librustc/hir/print.rs +++ b/src/librustc/hir/print.rs @@ -183,11 +183,10 @@ impl<'a> State<'a> { pub fn bclose_maybe_open(&mut self, span: syntax_pos::Span, - indented: usize, close_box: bool) { self.maybe_print_comment(span.hi()); - self.break_offset_if_not_bol(1, -(indented as isize)); + self.break_offset_if_not_bol(1, -(INDENT_UNIT as isize)); self.s.word("}"); if close_box { self.end(); // close the outer-box @@ -195,7 +194,7 @@ impl<'a> State<'a> { } pub fn bclose(&mut self, span: syntax_pos::Span) { - self.bclose_maybe_open(span, INDENT_UNIT, true) + self.bclose_maybe_open(span, true) } pub fn space_if_not_bol(&mut self) { @@ -963,26 +962,18 @@ impl<'a> State<'a> { } pub fn print_block_unclosed(&mut self, blk: &hir::Block) { - self.print_block_unclosed_indent(blk, INDENT_UNIT) - } - - pub fn print_block_unclosed_indent(&mut self, - blk: &hir::Block, - indented: usize) - { - self.print_block_maybe_unclosed(blk, indented, &[], false) + self.print_block_maybe_unclosed(blk, &[], false) } pub fn print_block_with_attrs(&mut self, blk: &hir::Block, attrs: &[ast::Attribute]) { - self.print_block_maybe_unclosed(blk, INDENT_UNIT, attrs, true) + self.print_block_maybe_unclosed(blk, attrs, true) } pub fn print_block_maybe_unclosed(&mut self, blk: &hir::Block, - indented: usize, attrs: &[ast::Attribute], close_box: bool) { @@ -1006,7 +997,7 @@ impl<'a> State<'a> { self.print_expr(&expr); self.maybe_print_trailing_comment(expr.span, Some(blk.span.hi())); } - self.bclose_maybe_open(blk.span, indented, close_box); + self.bclose_maybe_open(blk.span, close_box); self.ann.post(self, AnnNode::Block(blk)) } @@ -1263,7 +1254,7 @@ impl<'a> State<'a> { self.print_ident(temp); // Print `}`: - self.bclose_maybe_open(expr.span, INDENT_UNIT, true); + self.bclose_maybe_open(expr.span, true); } hir::ExprKind::Loop(ref blk, opt_label, _) => { if let Some(label) = opt_label { @@ -1819,7 +1810,7 @@ impl<'a> State<'a> { self.word_space(":"); } // the block will close the pattern's ibox - self.print_block_unclosed_indent(&blk, INDENT_UNIT); + self.print_block_unclosed(&blk); // If it is a user-provided unsafe block, print a comma after it if let hir::UnsafeBlock(hir::UserProvided) = blk.rules { diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 7dd7000b454..83dbff6b2d5 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -4591,7 +4591,7 @@ impl<'a> Parser<'a> { s.ibox(INDENT_UNIT); s.bopen(); s.print_stmt(&stmt); - s.bclose_maybe_open(stmt.span, INDENT_UNIT, false) + s.bclose_maybe_open(stmt.span, false) }); e.span_suggestion( stmt_span, diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 98c629addc8..eddd8700de6 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -743,17 +743,16 @@ impl<'a> State<'a> { self.end(); // close the head-box } - crate fn bclose_maybe_open(&mut self, span: syntax_pos::Span, - indented: usize, close_box: bool) { + crate fn bclose_maybe_open(&mut self, span: syntax_pos::Span, close_box: bool) { self.maybe_print_comment(span.hi()); - self.break_offset_if_not_bol(1, -(indented as isize)); + self.break_offset_if_not_bol(1, -(INDENT_UNIT as isize)); self.s.word("}"); if close_box { self.end(); // close the outer-box } } crate fn bclose(&mut self, span: syntax_pos::Span) { - self.bclose_maybe_open(span, INDENT_UNIT, true) + self.bclose_maybe_open(span, true) } crate fn break_offset_if_not_bol(&mut self, n: usize, @@ -1559,20 +1558,18 @@ impl<'a> State<'a> { self.print_block_with_attrs(blk, &[]) } - crate fn print_block_unclosed_indent(&mut self, blk: &ast::Block, - indented: usize) { - self.print_block_maybe_unclosed(blk, indented, &[], false) + crate fn print_block_unclosed_indent(&mut self, blk: &ast::Block) { + self.print_block_maybe_unclosed(blk, &[], false) } crate fn print_block_with_attrs(&mut self, blk: &ast::Block, attrs: &[ast::Attribute]) { - self.print_block_maybe_unclosed(blk, INDENT_UNIT, attrs, true) + self.print_block_maybe_unclosed(blk, attrs, true) } crate fn print_block_maybe_unclosed(&mut self, blk: &ast::Block, - indented: usize, attrs: &[ast::Attribute], close_box: bool) { match blk.rules { @@ -1597,7 +1594,7 @@ impl<'a> State<'a> { } } - self.bclose_maybe_open(blk.span, indented, close_box); + self.bclose_maybe_open(blk.span, close_box); self.ann.post(self, AnnNode::Block(blk)) } @@ -2519,7 +2516,7 @@ impl<'a> State<'a> { } // the block will close the pattern's ibox - self.print_block_unclosed_indent(blk, INDENT_UNIT); + self.print_block_unclosed_indent(blk); // If it is a user-provided unsafe block, print a comma after it if let BlockCheckMode::Unsafe(ast::UserProvided) = blk.rules { -- cgit 1.4.1-3-g733a5