diff options
| author | Alexander Regueiro <alexreg@me.com> | 2019-09-06 03:56:45 +0100 |
|---|---|---|
| committer | Alexander Regueiro <alexreg@me.com> | 2019-09-07 16:29:04 +0100 |
| commit | 49d2fd1725510fd3bf6f2937e178b1aa055ddb02 (patch) | |
| tree | a04455dea49b29d2c981573bd920116f0418024b /src/libsyntax/print | |
| parent | ef54f57c5b9d894a38179d09b00610c1b337b086 (diff) | |
Aggregation of cosmetic changes made during work on REPL PRs: libsyntax
Diffstat (limited to 'src/libsyntax/print')
| -rw-r--r-- | src/libsyntax/print/pprust.rs | 52 | ||||
| -rw-r--r-- | src/libsyntax/print/pprust/tests.rs | 5 |
2 files changed, 27 insertions, 30 deletions
diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 8c1632dc780..5d8498f8b5d 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -119,19 +119,19 @@ pub fn print_crate<'a>(cm: &'a SourceMap, if is_expanded && sess.injected_crate_name.try_get().is_some() { // We need to print `#![no_std]` (and its feature gate) so that // compiling pretty-printed source won't inject libstd again. - // However we don't want these attributes in the AST because + // However, we don't want these attributes in the AST because // of the feature gate, so we fake them up here. - // #![feature(prelude_import)] + // `#![feature(prelude_import)]` let pi_nested = attr::mk_nested_word_item(ast::Ident::with_dummy_span(sym::prelude_import)); let list = attr::mk_list_item(ast::Ident::with_dummy_span(sym::feature), vec![pi_nested]); let fake_attr = attr::mk_attr_inner(list); s.print_attribute(&fake_attr); - // Currently on Rust 2018 we don't have `extern crate std;` at the crate + // Currently, in Rust 2018 we don't have `extern crate std;` at the crate // root, so this is not needed, and actually breaks things. if sess.edition == syntax_pos::edition::Edition::Edition2015 { - // #![no_std] + // `#![no_std]` let no_std_meta = attr::mk_word_item(ast::Ident::with_dummy_span(sym::no_std)); let fake_attr = attr::mk_attr_inner(no_std_meta); s.print_attribute(&fake_attr); @@ -398,9 +398,9 @@ pub fn vis_to_string(v: &ast::Visibility) -> String { fn block_to_string(blk: &ast::Block) -> String { to_string(|s| { - // containing cbox, will be closed by print-block at } + // Containing cbox, will be closed by `print_block` at `}`. s.cbox(INDENT_UNIT); - // head-ibox, will be closed by print-block after { + // Head-ibox, will be closed by `print_block` after `{`. s.ibox(0); s.print_block(blk) }) @@ -443,7 +443,7 @@ impl std::ops::DerefMut for State<'_> { } } -pub trait PrintState<'a>: std::ops::Deref<Target=pp::Printer> + std::ops::DerefMut { +pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::DerefMut { fn comments(&mut self) -> &mut Option<Comments<'a>>; fn print_ident(&mut self, ident: ast::Ident); fn print_generic_args(&mut self, args: &ast::GenericArgs, colons_before_params: bool); @@ -495,7 +495,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target=pp::Printer> + std::ops::DerefM self.hardbreak_if_not_bol(); for line in &cmnt.lines { // Don't print empty lines because they will end up as trailing - // whitespace + // whitespace. if !line.is_empty() { self.word(line.clone()); } @@ -783,11 +783,11 @@ pub trait PrintState<'a>: std::ops::Deref<Target=pp::Printer> + std::ops::DerefM fn head<S: Into<Cow<'static, str>>>(&mut self, w: S) { let w = w.into(); - // outer-box is consistent + // Outer-box is consistent. self.cbox(INDENT_UNIT); - // head-box is inconsistent + // Head-box is inconsistent. self.ibox(w.len() + 1); - // keyword that starts the head + // Keyword that starts the head. if !w.is_empty() { self.word_nbsp(w); } @@ -795,7 +795,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target=pp::Printer> + std::ops::DerefM fn bopen(&mut self) { self.word("{"); - self.end(); // close the head-box + self.end(); // Close the head-box. } fn bclose_maybe_open(&mut self, span: syntax_pos::Span, close_box: bool) { @@ -803,7 +803,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target=pp::Printer> + std::ops::DerefM self.break_offset_if_not_bol(1, -(INDENT_UNIT as isize)); self.word("}"); if close_box { - self.end(); // close the outer-box + self.end(); // Close the outer-box. } } @@ -900,8 +900,6 @@ impl<'a> State<'a> { self.s.word("*/") } - - crate fn commasep_cmnt<T, F, G>(&mut self, b: Breaks, elts: &[T], @@ -928,12 +926,12 @@ impl<'a> State<'a> { } crate fn commasep_exprs(&mut self, b: Breaks, - exprs: &[P<ast::Expr>]) { + exprs: &[P<ast::Expr>]) { self.commasep_cmnt(b, exprs, |s, e| s.print_expr(e), |e| e.span) } crate fn print_mod(&mut self, _mod: &ast::Mod, - attrs: &[ast::Attribute]) { + attrs: &[ast::Attribute]) { self.print_inner_attributes(attrs); for item in &_mod.items { self.print_item(item); @@ -941,7 +939,7 @@ impl<'a> State<'a> { } crate fn print_foreign_mod(&mut self, nmod: &ast::ForeignMod, - attrs: &[ast::Attribute]) { + attrs: &[ast::Attribute]) { self.print_inner_attributes(attrs); for item in &nmod.items { self.print_foreign_item(item); @@ -1136,7 +1134,7 @@ impl<'a> State<'a> { self.s.word(";") } - /// Pretty-print an item + /// Pretty-prints an item. crate fn print_item(&mut self, item: &ast::Item) { self.hardbreak_if_not_bol(); self.maybe_print_comment(item.span.lo()); @@ -1489,7 +1487,7 @@ impl<'a> State<'a> { self.s.word(";"); } self.end(); - self.end(); // close the outer-box + self.end(); // Close the outer-box. } ast::VariantData::Struct(..) => { self.print_where_clause(&generics.where_clause); @@ -1793,7 +1791,7 @@ impl<'a> State<'a> { self.print_expr_cond_paren(expr, expr.precedence().order() < prec) } - /// Print an expr using syntax that's acceptable in a condition position, such as the `cond` in + /// Prints an expr using syntax that's acceptable in a condition position, such as the `cond` in /// `if cond { ... }`. crate fn print_expr_as_cond(&mut self, expr: &ast::Expr) { self.print_expr_cond_paren(expr, Self::cond_needs_par(expr)) @@ -1812,7 +1810,7 @@ impl<'a> State<'a> { } } - /// Print `expr` or `(expr)` when `needs_par` holds. + /// Prints `expr` or `(expr)` when `needs_par` holds. fn print_expr_cond_paren(&mut self, expr: &ast::Expr, needs_par: bool) { if needs_par { self.popen(); @@ -2456,7 +2454,7 @@ impl<'a> State<'a> { } fn print_arm(&mut self, arm: &ast::Arm) { - // I have no idea why this check is necessary, but here it is :( + // Note, I have no idea why this check is necessary, but here it is. if arm.attrs.is_empty() { self.s.space(); } @@ -2480,21 +2478,21 @@ impl<'a> State<'a> { self.word_space(":"); } - // the block will close the pattern's ibox + // The block will close the pattern's ibox. self.print_block_unclosed_indent(blk); - // If it is a user-provided unsafe block, print a comma after it + // If it is a user-provided unsafe block, print a comma after it. if let BlockCheckMode::Unsafe(ast::UserProvided) = blk.rules { self.s.word(","); } } _ => { - self.end(); // close the ibox for the pattern + self.end(); // Close the ibox for the pattern. self.print_expr(&arm.body); self.s.word(","); } } - self.end(); // close enclosing cbox + self.end(); // Close enclosing cbox. } fn print_explicit_self(&mut self, explicit_self: &ast::ExplicitSelf) { diff --git a/src/libsyntax/print/pprust/tests.rs b/src/libsyntax/print/pprust/tests.rs index 25214673e69..afd1726adf3 100644 --- a/src/libsyntax/print/pprust/tests.rs +++ b/src/libsyntax/print/pprust/tests.rs @@ -12,8 +12,8 @@ fn fun_to_string( s.head(""); s.print_fn(decl, header, Some(name), generics, &source_map::dummy_spanned(ast::VisibilityKind::Inherited)); - s.end(); // Close the head box - s.end(); // Close the outer box + s.end(); // Close the head box. + s.end(); // Close the outer box. }) } @@ -58,7 +58,6 @@ fn test_variant_to_string() { ident, attrs: Vec::new(), id: ast::DUMMY_NODE_ID, - // making this up as I go.... ? data: ast::VariantData::Unit(ast::DUMMY_NODE_ID), disr_expr: None, span: syntax_pos::DUMMY_SP, |
