From 9b0ebfa4e9e4906497eed5c6848bcca3cca23464 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Wed, 26 Jun 2019 07:23:27 -0400 Subject: Move literal_to_string to fmt::Display --- src/libsyntax/parse/literal.rs | 2 +- src/libsyntax/parse/token.rs | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) (limited to 'src/libsyntax/parse') diff --git a/src/libsyntax/parse/literal.rs b/src/libsyntax/parse/literal.rs index ef55bf6b929..683d1641565 100644 --- a/src/libsyntax/parse/literal.rs +++ b/src/libsyntax/parse/literal.rs @@ -344,7 +344,7 @@ impl<'a> Parser<'a> { // Pack possible quotes and prefixes from the original literal into // the error literal's symbol so they can be pretty-printed faithfully. let suffixless_lit = token::Lit::new(lit.kind, lit.symbol, None); - let symbol = Symbol::intern(&pprust::literal_to_string(suffixless_lit)); + let symbol = Symbol::intern(&suffixless_lit.to_string()); let lit = token::Lit::new(token::Err, symbol, lit.suffix); Lit::from_lit_token(lit, span).map_err(|_| unreachable!()) } diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index ebd0decacb5..fccb556b95a 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -80,6 +80,34 @@ pub struct Lit { pub suffix: Option, } +impl fmt::Display for Lit { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let Lit { kind, symbol, suffix } = *self; + match kind { + Byte => write!(f, "b'{}'", symbol)?, + Char => write!(f, "'{}'", symbol)?, + Str => write!(f, "\"{}\"", symbol)?, + StrRaw(n) => write!(f, "r{delim}\"{string}\"{delim}", + delim="#".repeat(n as usize), + string=symbol)?, + ByteStr => write!(f, "b\"{}\"", symbol)?, + ByteStrRaw(n) => write!(f, "br{delim}\"{string}\"{delim}", + delim="#".repeat(n as usize), + string=symbol)?, + Integer | + Float | + Bool | + Err => write!(f, "{}", symbol)?, + } + + if let Some(suffix) = suffix { + write!(f, "{}", suffix)?; + } + + Ok(()) + } +} + impl LitKind { /// An English article for the literal token kind. crate fn article(self) -> &'static str { -- cgit 1.4.1-3-g733a5 From 0f10d114e447d5cdaf1de499e2d88b815aef7239 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Fri, 5 Jul 2019 12:16:41 -0400 Subject: Remove duplicate attr_to_string attribute_to_string exists. --- src/libsyntax/parse/token.rs | 2 +- src/libsyntax/print/pprust.rs | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) (limited to 'src/libsyntax/parse') diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index fccb556b95a..472e4b474d6 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -816,7 +816,7 @@ fn prepend_attrs(sess: &ParseSess, assert_eq!(attr.style, ast::AttrStyle::Outer, "inner attributes should prevent cached tokens from existing"); - let source = pprust::attr_to_string(attr); + let source = pprust::attribute_to_string(attr); let macro_filename = FileName::macro_expansion_source_code(&source); if attr.is_sugared_doc { let stream = parse_stream_from_source_str(macro_filename, source, sess, Some(span)); diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index a69dd94cfb6..4a3abe505ca 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -350,10 +350,6 @@ pub fn stmt_to_string(stmt: &ast::Stmt) -> String { to_string(|s| s.print_stmt(stmt)) } -pub fn attr_to_string(attr: &ast::Attribute) -> String { - to_string(|s| s.print_attribute(attr)) -} - pub fn item_to_string(i: &ast::Item) -> String { to_string(|s| s.print_item(i)) } -- cgit 1.4.1-3-g733a5 From 7e3791469fce12a95d5d85b9a8744a61a0970fe1 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Fri, 5 Jul 2019 17:12:11 -0400 Subject: Replace src: &mut dyn Read with String --- src/librustc/hir/print.rs | 5 ++--- src/librustc_driver/pretty.rs | 21 ++++++++++----------- src/libsyntax/parse/lexer/comments.rs | 5 +---- src/libsyntax/print/pprust.rs | 5 ++--- 4 files changed, 15 insertions(+), 21 deletions(-) (limited to 'src/libsyntax/parse') diff --git a/src/librustc/hir/print.rs b/src/librustc/hir/print.rs index 3af72dbb43c..fc3430566a0 100644 --- a/src/librustc/hir/print.rs +++ b/src/librustc/hir/print.rs @@ -16,7 +16,6 @@ use crate::hir::ptr::P; use std::borrow::Cow; use std::cell::Cell; -use std::io::Read; use std::vec; pub enum AnnNode<'a> { @@ -93,7 +92,7 @@ pub fn print_crate<'a>(cm: &'a SourceMap, sess: &ParseSess, krate: &hir::Crate, filename: FileName, - input: &mut dyn Read, + input: String, out: &'a mut String, ann: &'a dyn PpAnn) { @@ -111,7 +110,7 @@ impl<'a> State<'a> { pub fn new_from_input(cm: &'a SourceMap, sess: &ParseSess, filename: FileName, - input: &mut dyn Read, + input: String, out: &'a mut String, ann: &'a dyn PpAnn) -> State<'a> { diff --git a/src/librustc_driver/pretty.rs b/src/librustc_driver/pretty.rs index fc55d5ac355..df8dc3871b7 100644 --- a/src/librustc_driver/pretty.rs +++ b/src/librustc_driver/pretty.rs @@ -687,16 +687,14 @@ pub fn visit_crate(sess: &Session, krate: &mut ast::Crate, ppm: PpMode) { } } -fn get_source(input: &Input, sess: &Session) -> (Vec, FileName) { +fn get_source(input: &Input, sess: &Session) -> (String, FileName) { let src_name = source_name(input); - let src = sess.source_map() + let src = String::clone(&sess.source_map() .get_source_file(&src_name) .unwrap() .src .as_ref() - .unwrap() - .as_bytes() - .to_vec(); + .unwrap()); (src, src_name) } @@ -719,7 +717,6 @@ pub fn print_after_parsing(sess: &Session, ofile: Option<&Path>) { let (src, src_name) = get_source(input, sess); - let mut rdr = &*src; let mut out = String::new(); if let PpmSource(s) = ppm { @@ -732,7 +729,7 @@ pub fn print_after_parsing(sess: &Session, &sess.parse_sess, krate, src_name, - &mut rdr, + src, out, annotation.pp_ann(), false) @@ -764,13 +761,13 @@ pub fn print_after_hir_lowering<'tcx>( let (src, src_name) = get_source(input, tcx.sess); - let mut rdr = &src[..]; let mut out = String::new(); match (ppm, opt_uii) { (PpmSource(s), _) => { // Silently ignores an identified node. let out = &mut out; + let src = src.clone(); s.call_with_pp_support(tcx.sess, Some(tcx), move |annotation| { debug!("pretty printing source code {:?}", s); let sess = annotation.sess(); @@ -778,7 +775,7 @@ pub fn print_after_hir_lowering<'tcx>( &sess.parse_sess, krate, src_name, - &mut rdr, + src, out, annotation.pp_ann(), true) @@ -787,6 +784,7 @@ pub fn print_after_hir_lowering<'tcx>( (PpmHir(s), None) => { let out = &mut out; + let src = src.clone(); s.call_with_pp_support_hir(tcx, move |annotation, krate| { debug!("pretty printing source code {:?}", s); let sess = annotation.sess(); @@ -794,7 +792,7 @@ pub fn print_after_hir_lowering<'tcx>( &sess.parse_sess, krate, src_name, - &mut rdr, + src, out, annotation.pp_ann()) }) @@ -810,6 +808,7 @@ pub fn print_after_hir_lowering<'tcx>( (PpmHir(s), Some(uii)) => { let out = &mut out; + let src = src.clone(); s.call_with_pp_support_hir(tcx, move |annotation, _| { debug!("pretty printing source code {:?}", s); let sess = annotation.sess(); @@ -817,7 +816,7 @@ pub fn print_after_hir_lowering<'tcx>( let mut pp_state = pprust_hir::State::new_from_input(sess.source_map(), &sess.parse_sess, src_name, - &mut rdr, + src, out, annotation.pp_ann()); for node_id in uii.all_matching_node_ids(hir_map) { diff --git a/src/libsyntax/parse/lexer/comments.rs b/src/libsyntax/parse/lexer/comments.rs index 988f1aa38d9..6ed2a7adad1 100644 --- a/src/libsyntax/parse/lexer/comments.rs +++ b/src/libsyntax/parse/lexer/comments.rs @@ -8,7 +8,6 @@ use crate::parse::lexer::{self, ParseSess, StringReader}; use syntax_pos::{BytePos, CharPos, Pos, FileName}; use log::debug; -use std::io::Read; use std::usize; #[derive(Clone, Copy, PartialEq, Debug)] @@ -340,10 +339,8 @@ fn consume_comment(rdr: &mut StringReader<'_>, // it appears this function is called only from pprust... that's // probably not a good thing. -pub fn gather_comments(sess: &ParseSess, path: FileName, srdr: &mut dyn Read) -> Vec +pub fn gather_comments(sess: &ParseSess, path: FileName, src: String) -> Vec { - let mut src = String::new(); - srdr.read_to_string(&mut src).unwrap(); let cm = SourceMap::new(sess.source_map().path_mapping().clone()); let source_file = cm.new_source_file(path, src); let mut rdr = lexer::StringReader::new(sess, source_file, None); diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 638384acc4c..a6680ee02b5 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -21,7 +21,6 @@ use syntax_pos::{self, BytePos}; use syntax_pos::{DUMMY_SP, FileName, Span}; use std::borrow::Cow; -use std::io::Read; pub enum AnnNode<'a> { Ident(&'a ast::Ident), @@ -102,7 +101,7 @@ pub fn print_crate<'a>(cm: &'a SourceMap, sess: &ParseSess, krate: &ast::Crate, filename: FileName, - input: &mut dyn Read, + input: String, out: &mut String, ann: &'a dyn PpAnn, is_expanded: bool) { @@ -136,7 +135,7 @@ impl<'a> State<'a> { pub fn new_from_input(cm: &'a SourceMap, sess: &ParseSess, filename: FileName, - input: &mut dyn Read, + input: String, out: &'a mut String, ann: &'a dyn PpAnn, is_expanded: bool) -> State<'a> { -- cgit 1.4.1-3-g733a5 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/librustc/hir/map/mod.rs | 2 -- src/librustc/hir/print.rs | 13 +++++++++ src/librustc_borrowck/dataflow.rs | 1 - src/librustc_driver/pretty.rs | 1 - src/libsyntax/lib.rs | 1 + src/libsyntax/parse/diagnostics.rs | 2 -- src/libsyntax/parse/parser.rs | 3 +-- src/libsyntax/print/helpers.rs | 34 ++++++++++++++++++++++++ src/libsyntax/print/pp.rs | 6 ++--- src/libsyntax/print/pprust.rs | 54 +++++++++----------------------------- 10 files changed, 64 insertions(+), 53 deletions(-) create mode 100644 src/libsyntax/print/helpers.rs (limited to 'src/libsyntax/parse') diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index 63f60d0ab95..92898e9070b 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -1212,8 +1212,6 @@ impl<'a> print::State<'a> { Node::Pat(a) => self.print_pat(&a), Node::Arm(a) => self.print_arm(&a), Node::Block(a) => { - use syntax::print::pprust::PrintState; - // containing cbox, will be closed by print-block at } self.cbox(print::indent_unit); // head-ibox, will be closed by print-block after { diff --git a/src/librustc/hir/print.rs b/src/librustc/hir/print.rs index 246b3341a23..e014e7478db 100644 --- a/src/librustc/hir/print.rs +++ b/src/librustc/hir/print.rs @@ -73,6 +73,19 @@ pub struct State<'a> { ann: &'a (dyn PpAnn + 'a), } +impl std::ops::Deref for State<'_> { + type Target = pp::Printer; + fn deref(&self) -> &Self::Target { + &self.s + } +} + +impl std::ops::DerefMut for State<'_> { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.s + } +} + impl<'a> PrintState<'a> for State<'a> { fn writer(&mut self) -> &mut pp::Printer { &mut self.s diff --git a/src/librustc_borrowck/dataflow.rs b/src/librustc_borrowck/dataflow.rs index f1f9f3f71e4..6eea64e0e7a 100644 --- a/src/librustc_borrowck/dataflow.rs +++ b/src/librustc_borrowck/dataflow.rs @@ -8,7 +8,6 @@ use rustc::cfg::CFGIndex; use rustc::ty::TyCtxt; use std::mem; use std::usize; -use syntax::print::pprust::PrintState; use log::debug; use rustc_data_structures::graph::implementation::OUTGOING; diff --git a/src/librustc_driver/pretty.rs b/src/librustc_driver/pretty.rs index cd38eb695eb..51b161c3768 100644 --- a/src/librustc_driver/pretty.rs +++ b/src/librustc_driver/pretty.rs @@ -19,7 +19,6 @@ use rustc_mir::util::{write_mir_pretty, write_mir_graphviz}; use syntax::ast; use syntax::mut_visit::MutVisitor; use syntax::print::{pprust}; -use syntax::print::pprust::PrintState; use syntax_pos::FileName; use graphviz as dot; diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index a7c5ed158e0..ee7fb97ffd7 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -162,6 +162,7 @@ pub mod visit; pub mod print { pub mod pp; pub mod pprust; + mod helpers; } pub mod ext { diff --git a/src/libsyntax/parse/diagnostics.rs b/src/libsyntax/parse/diagnostics.rs index edcdb18a037..ae24047ac82 100644 --- a/src/libsyntax/parse/diagnostics.rs +++ b/src/libsyntax/parse/diagnostics.rs @@ -611,8 +611,6 @@ impl<'a> Parser<'a> { match ty.node { TyKind::Rptr(ref lifetime, ref mut_ty) => { let sum_with_parens = pprust::to_string(|s| { - use crate::print::pprust::PrintState; - s.s.word("&"); s.print_opt_lifetime(lifetime); s.print_mutability(mut_ty.mutbl); 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); diff --git a/src/libsyntax/print/helpers.rs b/src/libsyntax/print/helpers.rs new file mode 100644 index 00000000000..3449e07f456 --- /dev/null +++ b/src/libsyntax/print/helpers.rs @@ -0,0 +1,34 @@ +use std::borrow::Cow; +use crate::print::pp::Printer; + +impl Printer { + pub fn word_space>>(&mut self, w: W) { + self.word(w); + self.space(); + } + + pub fn popen(&mut self) { + self.word("("); + } + + pub fn pclose(&mut self) { + self.word(")"); + } + + pub fn hardbreak_if_not_bol(&mut self) { + if !self.is_beginning_of_line() { + self.hardbreak() + } + } + + pub fn space_if_not_bol(&mut self) { + if !self.is_beginning_of_line() { self.space(); } + } + + pub fn nbsp(&mut self) { self.word(" ") } + + pub fn word_nbsp>>(&mut self, w: S) { + self.word(w); + self.nbsp() + } +} diff --git a/src/libsyntax/print/pp.rs b/src/libsyntax/print/pp.rs index be5a0098578..660e77f77d0 100644 --- a/src/libsyntax/print/pp.rs +++ b/src/libsyntax/print/pp.rs @@ -597,7 +597,7 @@ impl Printer { // Convenience functions to talk to the printer. /// "raw box" - crate fn rbox(&mut self, indent: usize, b: Breaks) { + pub fn rbox(&mut self, indent: usize, b: Breaks) { self.scan_begin(BeginToken { offset: indent as isize, breaks: b @@ -605,7 +605,7 @@ impl Printer { } /// Inconsistent breaking box - crate fn ibox(&mut self, indent: usize) { + pub fn ibox(&mut self, indent: usize) { self.rbox(indent, Breaks::Inconsistent) } @@ -621,7 +621,7 @@ impl Printer { }) } - crate fn end(&mut self) { + pub fn end(&mut self) { self.scan_end() } diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 288417fcd89..98c629addc8 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -432,37 +432,22 @@ fn visibility_qualified(vis: &ast::Visibility, s: &str) -> String { format!("{}{}", to_string(|s| s.print_visibility(vis)), s) } -pub trait PrintState<'a> { - fn writer(&mut self) -> &mut pp::Printer; - fn comments(&mut self) -> &mut Option>; - - fn word_space>>(&mut self, w: S) { - self.writer().word(w); - self.writer().space() - } - - fn popen(&mut self) { self.writer().word("(") } - - fn pclose(&mut self) { self.writer().word(")") } - - fn hardbreak_if_not_bol(&mut self) { - if !self.writer().is_beginning_of_line() { - self.writer().hardbreak() - } - } - - // "raw box" - fn rbox(&mut self, u: usize, b: pp::Breaks) { - self.writer().rbox(u, b) +impl std::ops::Deref for State<'_> { + type Target = pp::Printer; + fn deref(&self) -> &Self::Target { + &self.s } +} - fn ibox(&mut self, u: usize) { - self.writer().ibox(u); +impl std::ops::DerefMut for State<'_> { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.s } +} - fn end(&mut self) { - self.writer().end() - } +pub trait PrintState<'a>: std::ops::Deref + std::ops::DerefMut { + fn writer(&mut self) -> &mut pp::Printer; + fn comments(&mut self) -> &mut Option>; fn commasep(&mut self, b: Breaks, elts: &[T], mut op: F) where F: FnMut(&mut Self, &T), @@ -728,12 +713,6 @@ pub trait PrintState<'a> { } self.end(); } - - fn space_if_not_bol(&mut self) { - if !self.writer().is_beginning_of_line() { self.writer().space(); } - } - - fn nbsp(&mut self) { self.writer().word(" ") } } impl<'a> PrintState<'a> for State<'a> { @@ -747,15 +726,6 @@ impl<'a> PrintState<'a> for State<'a> { } impl<'a> State<'a> { - pub fn cbox(&mut self, u: usize) { - self.s.cbox(u); - } - - crate fn word_nbsp>>(&mut self, w: S) { - self.s.word(w); - self.nbsp() - } - crate fn head>>(&mut self, w: S) { let w = w.into(); // outer-box is consistent -- 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') 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