summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_ast_pretty/src/pprust/state.rs
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_ast_pretty/src/pprust/state.rs')
-rw-r--r--compiler/rustc_ast_pretty/src/pprust/state.rs274
1 files changed, 138 insertions, 136 deletions
diff --git a/compiler/rustc_ast_pretty/src/pprust/state.rs b/compiler/rustc_ast_pretty/src/pprust/state.rs
index b87c6f78d..d3d8431c1 100644
--- a/compiler/rustc_ast_pretty/src/pprust/state.rs
+++ b/compiler/rustc_ast_pretty/src/pprust/state.rs
@@ -11,16 +11,15 @@ use rustc_ast::tokenstream::{TokenStream, TokenTree};
use rustc_ast::util::classify;
use rustc_ast::util::comments::{gather_comments, Comment, CommentStyle};
use rustc_ast::util::parser;
-use rustc_ast::{self as ast, BlockCheckMode, Mutability, PatKind, RangeEnd, RangeSyntax};
-use rustc_ast::{attr, BindingAnnotation, ByRef, Term};
-use rustc_ast::{GenericArg, MacArgs, MacArgsEq};
-use rustc_ast::{GenericBound, SelfKind, TraitBoundModifier};
+use rustc_ast::{self as ast, AttrArgs, AttrArgsEq, BlockCheckMode, PatKind};
+use rustc_ast::{attr, BindingAnnotation, ByRef, DelimArgs, RangeEnd, RangeSyntax, Term};
+use rustc_ast::{GenericArg, GenericBound, SelfKind, TraitBoundModifier};
use rustc_ast::{InlineAsmOperand, InlineAsmRegOrRegClass};
use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece};
use rustc_span::edition::Edition;
use rustc_span::source_map::{SourceMap, Spanned};
use rustc_span::symbol::{kw, sym, Ident, IdentPrinter, Symbol};
-use rustc_span::{BytePos, FileName, Span};
+use rustc_span::{BytePos, FileName, Span, DUMMY_SP};
use rustc_ast::attr::AttrIdGenerator;
use std::borrow::Cow;
@@ -65,6 +64,7 @@ impl<'a> Comments<'a> {
Comments { sm, comments, current: 0 }
}
+ // FIXME: This shouldn't probably clone lmao
pub fn next(&self) -> Option<Comment> {
self.comments.get(self.current).cloned()
}
@@ -120,17 +120,20 @@ pub fn print_crate<'a>(
// of the feature gate, so we fake them up here.
// `#![feature(prelude_import)]`
- let pi_nested = attr::mk_nested_word_item(Ident::with_dummy_span(sym::prelude_import));
- let list = attr::mk_list_item(Ident::with_dummy_span(sym::feature), vec![pi_nested]);
- let fake_attr = attr::mk_attr_inner(g, list);
+ let fake_attr = attr::mk_attr_nested_word(
+ g,
+ ast::AttrStyle::Inner,
+ sym::feature,
+ sym::prelude_import,
+ DUMMY_SP,
+ );
s.print_attribute(&fake_attr);
// 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 edition == Edition::Edition2015 {
// `#![no_std]`
- let no_std_meta = attr::mk_word_item(Ident::with_dummy_span(sym::no_std));
- let fake_attr = attr::mk_attr_inner(g, no_std_meta);
+ let fake_attr = attr::mk_attr_word(g, ast::AttrStyle::Inner, sym::no_std, DUMMY_SP);
s.print_attribute(&fake_attr);
}
}
@@ -269,10 +272,10 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
fn maybe_print_comment(&mut self, pos: BytePos) -> bool {
let mut has_comment = false;
- while let Some(ref cmnt) = self.next_comment() {
+ while let Some(cmnt) = self.next_comment() {
if cmnt.pos < pos {
has_comment = true;
- self.print_comment(cmnt);
+ self.print_comment(&cmnt);
} else {
break;
}
@@ -367,14 +370,18 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
if self.next_comment().is_none() {
self.hardbreak();
}
- while let Some(ref cmnt) = self.next_comment() {
- self.print_comment(cmnt)
+ while let Some(cmnt) = self.next_comment() {
+ self.print_comment(&cmnt)
}
}
- fn print_literal(&mut self, lit: &ast::Lit) {
- self.maybe_print_comment(lit.span.lo());
- self.word(lit.token_lit.to_string())
+ fn print_meta_item_lit(&mut self, lit: &ast::MetaItemLit) {
+ self.print_token_literal(lit.token_lit, lit.span)
+ }
+
+ fn print_token_literal(&mut self, token_lit: token::Lit, span: Span) {
+ self.maybe_print_comment(span.lo());
+ self.word(token_lit.to_string())
}
fn print_string(&mut self, st: &str, style: ast::StrStyle) {
@@ -443,8 +450,8 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
self.hardbreak_if_not_bol();
}
self.maybe_print_comment(attr.span.lo());
- match attr.kind {
- ast::AttrKind::Normal(ref normal) => {
+ match &attr.kind {
+ ast::AttrKind::Normal(normal) => {
match attr.style {
ast::AttrStyle::Inner => self.word("#!["),
ast::AttrStyle::Outer => self.word("#["),
@@ -453,7 +460,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
self.word("]");
}
ast::AttrKind::DocComment(comment_kind, data) => {
- self.word(doc_comment_to_string(comment_kind, attr.style, data));
+ self.word(doc_comment_to_string(*comment_kind, attr.style, *data));
self.hardbreak()
}
}
@@ -462,30 +469,30 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
fn print_attr_item(&mut self, item: &ast::AttrItem, span: Span) {
self.ibox(0);
match &item.args {
- MacArgs::Delimited(_, delim, tokens) => self.print_mac_common(
+ AttrArgs::Delimited(DelimArgs { dspan: _, delim, tokens }) => self.print_mac_common(
Some(MacHeader::Path(&item.path)),
false,
None,
- Some(delim.to_token()),
+ delim.to_token(),
tokens,
true,
span,
),
- MacArgs::Empty => {
+ AttrArgs::Empty => {
self.print_path(&item.path, false, 0);
}
- MacArgs::Eq(_, MacArgsEq::Ast(expr)) => {
+ AttrArgs::Eq(_, AttrArgsEq::Ast(expr)) => {
self.print_path(&item.path, false, 0);
self.space();
self.word_space("=");
let token_str = self.expr_to_string(expr);
self.word(token_str);
}
- MacArgs::Eq(_, MacArgsEq::Hir(lit)) => {
+ AttrArgs::Eq(_, AttrArgsEq::Hir(lit)) => {
self.print_path(&item.path, false, 0);
self.space();
self.word_space("=");
- let token_str = self.literal_to_string(lit);
+ let token_str = self.meta_item_lit_to_string(lit);
self.word(token_str);
}
}
@@ -494,25 +501,25 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
fn print_meta_list_item(&mut self, item: &ast::NestedMetaItem) {
match item {
- ast::NestedMetaItem::MetaItem(ref mi) => self.print_meta_item(mi),
- ast::NestedMetaItem::Literal(ref lit) => self.print_literal(lit),
+ ast::NestedMetaItem::MetaItem(mi) => self.print_meta_item(mi),
+ ast::NestedMetaItem::Lit(lit) => self.print_meta_item_lit(lit),
}
}
fn print_meta_item(&mut self, item: &ast::MetaItem) {
self.ibox(INDENT_UNIT);
- match item.kind {
+ match &item.kind {
ast::MetaItemKind::Word => self.print_path(&item.path, false, 0),
- ast::MetaItemKind::NameValue(ref value) => {
+ ast::MetaItemKind::NameValue(value) => {
self.print_path(&item.path, false, 0);
self.space();
self.word_space("=");
- self.print_literal(value);
+ self.print_meta_item_lit(value);
}
- ast::MetaItemKind::List(ref items) => {
+ ast::MetaItemKind::List(items) => {
self.print_path(&item.path, false, 0);
self.popen();
- self.commasep(Consistent, &items, |s, i| s.print_meta_list_item(i));
+ self.commasep(Consistent, items, |s, i| s.print_meta_list_item(i));
self.pclose();
}
}
@@ -529,7 +536,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
fn print_tt(&mut self, tt: &TokenTree, convert_dollar_crate: bool) {
match tt {
TokenTree::Token(token, _) => {
- let token_str = self.token_to_string_ext(&token, convert_dollar_crate);
+ let token_str = self.token_to_string_ext(token, convert_dollar_crate);
self.word(token_str);
if let token::DocComment(..) = token.kind {
self.hardbreak()
@@ -540,7 +547,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
None,
false,
None,
- Some(*delim),
+ *delim,
tts,
convert_dollar_crate,
dspan.entire(),
@@ -566,12 +573,12 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
header: Option<MacHeader<'_>>,
has_bang: bool,
ident: Option<Ident>,
- delim: Option<Delimiter>,
+ delim: Delimiter,
tts: &TokenStream,
convert_dollar_crate: bool,
span: Span,
) {
- if delim == Some(Delimiter::Brace) {
+ if delim == Delimiter::Brace {
self.cbox(INDENT_UNIT);
}
match header {
@@ -587,7 +594,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
self.print_ident(ident);
}
match delim {
- Some(Delimiter::Brace) => {
+ Delimiter::Brace => {
if header.is_some() || has_bang || ident.is_some() {
self.nbsp();
}
@@ -601,7 +608,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
let empty = tts.is_empty();
self.bclose(span, empty);
}
- Some(delim) => {
+ delim => {
let token_str = self.token_kind_to_string(&token::OpenDelim(delim));
self.word(token_str);
self.ibox(0);
@@ -610,11 +617,6 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
let token_str = self.token_kind_to_string(&token::CloseDelim(delim));
self.word(token_str);
}
- None => {
- self.ibox(0);
- self.print_tts(tts, convert_dollar_crate);
- self.end();
- }
}
}
@@ -635,8 +637,8 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
Some(MacHeader::Keyword(kw)),
has_bang,
Some(*ident),
- macro_def.body.delim(),
- &macro_def.body.inner_tokens(),
+ macro_def.body.delim.to_token(),
+ &macro_def.body.tokens.clone(),
true,
sp,
);
@@ -659,7 +661,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
fn print_path_segment(&mut self, segment: &ast::PathSegment, colons_before_params: bool) {
if segment.ident.name != kw::PathRoot {
self.print_ident(segment.ident);
- if let Some(ref args) = segment.args {
+ if let Some(args) = &segment.args {
self.print_generic_args(args, colons_before_params);
}
}
@@ -714,19 +716,19 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
}
fn nonterminal_to_string(&self, nt: &Nonterminal) -> String {
- match *nt {
- token::NtExpr(ref e) => self.expr_to_string(e),
- token::NtMeta(ref e) => self.attr_item_to_string(e),
- token::NtTy(ref e) => self.ty_to_string(e),
- token::NtPath(ref e) => self.path_to_string(e),
- token::NtItem(ref e) => self.item_to_string(e),
- token::NtBlock(ref e) => self.block_to_string(e),
- token::NtStmt(ref e) => self.stmt_to_string(e),
- token::NtPat(ref e) => self.pat_to_string(e),
- token::NtIdent(e, is_raw) => IdentPrinter::for_ast_ident(e, is_raw).to_string(),
+ match nt {
+ token::NtExpr(e) => self.expr_to_string(e),
+ token::NtMeta(e) => self.attr_item_to_string(e),
+ token::NtTy(e) => self.ty_to_string(e),
+ token::NtPath(e) => self.path_to_string(e),
+ token::NtItem(e) => self.item_to_string(e),
+ token::NtBlock(e) => self.block_to_string(e),
+ token::NtStmt(e) => self.stmt_to_string(e),
+ token::NtPat(e) => self.pat_to_string(e),
+ token::NtIdent(e, is_raw) => IdentPrinter::for_ast_ident(*e, *is_raw).to_string(),
token::NtLifetime(e) => e.to_string(),
- token::NtLiteral(ref e) => self.expr_to_string(e),
- token::NtVis(ref e) => self.vis_to_string(e),
+ token::NtLiteral(e) => self.expr_to_string(e),
+ token::NtVis(e) => self.vis_to_string(e),
}
}
@@ -827,8 +829,8 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
Self::to_string(|s| s.print_expr(e))
}
- fn literal_to_string(&self, lit: &ast::Lit) -> String {
- Self::to_string(|s| s.print_literal(lit))
+ fn meta_item_lit_to_string(&self, lit: &ast::MetaItemLit) -> String {
+ Self::to_string(|s| s.print_meta_item_lit(lit))
}
fn tt_to_string(&self, tt: &TokenTree) -> String {
@@ -919,8 +921,8 @@ impl<'a> PrintState<'a> for State<'a> {
self.word("::")
}
- match *args {
- ast::GenericArgs::AngleBracketed(ref data) => {
+ match args {
+ ast::GenericArgs::AngleBracketed(data) => {
self.word("<");
self.commasep(Inconsistent, &data.args, |s, arg| match arg {
ast::AngleBracketedArg::Arg(a) => s.print_generic_arg(a),
@@ -929,7 +931,7 @@ impl<'a> PrintState<'a> for State<'a> {
self.word(">")
}
- ast::GenericArgs::Parenthesized(ref data) => {
+ ast::GenericArgs::Parenthesized(data) => {
self.word("(");
self.commasep(Inconsistent, &data.inputs, |s, ty| s.print_type(ty));
self.word(")");
@@ -996,7 +998,7 @@ impl<'a> State<'a> {
ast::AssocConstraintKind::Bound { bounds } => {
if !bounds.is_empty() {
self.word_nbsp(":");
- self.print_type_bounds(&bounds);
+ self.print_type_bounds(bounds);
}
}
}
@@ -1013,17 +1015,17 @@ impl<'a> State<'a> {
pub fn print_type(&mut self, ty: &ast::Ty) {
self.maybe_print_comment(ty.span.lo());
self.ibox(0);
- match ty.kind {
- ast::TyKind::Slice(ref ty) => {
+ match &ty.kind {
+ ast::TyKind::Slice(ty) => {
self.word("[");
self.print_type(ty);
self.word("]");
}
- ast::TyKind::Ptr(ref mt) => {
+ ast::TyKind::Ptr(mt) => {
self.word("*");
self.print_mt(mt, true);
}
- ast::TyKind::Rptr(ref lifetime, ref mt) => {
+ ast::TyKind::Rptr(lifetime, mt) => {
self.word("&");
self.print_opt_lifetime(lifetime);
self.print_mt(mt, false);
@@ -1031,44 +1033,44 @@ impl<'a> State<'a> {
ast::TyKind::Never => {
self.word("!");
}
- ast::TyKind::Tup(ref elts) => {
+ ast::TyKind::Tup(elts) => {
self.popen();
- self.commasep(Inconsistent, &elts, |s, ty| s.print_type(ty));
+ self.commasep(Inconsistent, elts, |s, ty| s.print_type(ty));
if elts.len() == 1 {
self.word(",");
}
self.pclose();
}
- ast::TyKind::Paren(ref typ) => {
+ ast::TyKind::Paren(typ) => {
self.popen();
self.print_type(typ);
self.pclose();
}
- ast::TyKind::BareFn(ref f) => {
+ ast::TyKind::BareFn(f) => {
self.print_ty_fn(f.ext, f.unsafety, &f.decl, None, &f.generic_params);
}
- ast::TyKind::Path(None, ref path) => {
+ ast::TyKind::Path(None, path) => {
self.print_path(path, false, 0);
}
- ast::TyKind::Path(Some(ref qself), ref path) => self.print_qpath(path, qself, false),
- ast::TyKind::TraitObject(ref bounds, syntax) => {
- if syntax == ast::TraitObjectSyntax::Dyn {
+ ast::TyKind::Path(Some(qself), path) => self.print_qpath(path, qself, false),
+ ast::TyKind::TraitObject(bounds, syntax) => {
+ if *syntax == ast::TraitObjectSyntax::Dyn {
self.word_nbsp("dyn");
}
self.print_type_bounds(bounds);
}
- ast::TyKind::ImplTrait(_, ref bounds) => {
+ ast::TyKind::ImplTrait(_, bounds) => {
self.word_nbsp("impl");
self.print_type_bounds(bounds);
}
- ast::TyKind::Array(ref ty, ref length) => {
+ ast::TyKind::Array(ty, length) => {
self.word("[");
self.print_type(ty);
self.word("; ");
self.print_expr(&length.value);
self.word("]");
}
- ast::TyKind::Typeof(ref e) => {
+ ast::TyKind::Typeof(e) => {
self.word("typeof(");
self.print_expr(&e.value);
self.word(")");
@@ -1084,7 +1086,7 @@ impl<'a> State<'a> {
ast::TyKind::ImplicitSelf => {
self.word("Self");
}
- ast::TyKind::MacCall(ref m) => {
+ ast::TyKind::MacCall(m) => {
self.print_mac(m);
}
ast::TyKind::CVarArgs => {
@@ -1113,8 +1115,8 @@ impl<'a> State<'a> {
pub(crate) fn print_stmt(&mut self, st: &ast::Stmt) {
self.maybe_print_comment(st.span.lo());
- match st.kind {
- ast::StmtKind::Local(ref loc) => {
+ match &st.kind {
+ ast::StmtKind::Local(loc) => {
self.print_outer_attributes(&loc.attrs);
self.space_if_not_bol();
self.ibox(INDENT_UNIT);
@@ -1137,15 +1139,15 @@ impl<'a> State<'a> {
self.word(";");
self.end(); // `let` ibox
}
- ast::StmtKind::Item(ref item) => self.print_item(item),
- ast::StmtKind::Expr(ref expr) => {
+ ast::StmtKind::Item(item) => self.print_item(item),
+ ast::StmtKind::Expr(expr) => {
self.space_if_not_bol();
self.print_expr_outer_attr_style(expr, false);
if classify::expr_requires_semi_to_be_stmt(expr) {
self.word(";");
}
}
- ast::StmtKind::Semi(ref expr) => {
+ ast::StmtKind::Semi(expr) => {
self.space_if_not_bol();
self.print_expr_outer_attr_style(expr, false);
self.word(";");
@@ -1154,7 +1156,7 @@ impl<'a> State<'a> {
self.space_if_not_bol();
self.word(";");
}
- ast::StmtKind::MacCall(ref mac) => {
+ ast::StmtKind::MacCall(mac) => {
self.space_if_not_bol();
self.print_outer_attributes(&mac.attrs);
self.print_mac(&mac.mac);
@@ -1195,8 +1197,8 @@ impl<'a> State<'a> {
let has_attrs = self.print_inner_attributes(attrs);
for (i, st) in blk.stmts.iter().enumerate() {
- match st.kind {
- ast::StmtKind::Expr(ref expr) if i == blk.stmts.len() - 1 => {
+ match &st.kind {
+ ast::StmtKind::Expr(expr) if i == blk.stmts.len() - 1 => {
self.maybe_print_comment(st.span.lo());
self.space_if_not_bol();
self.print_expr_outer_attr_style(expr, false);
@@ -1226,8 +1228,8 @@ impl<'a> State<'a> {
Some(MacHeader::Path(&m.path)),
true,
None,
- m.args.delim(),
- &m.args.inner_tokens(),
+ m.args.delim.to_token(),
+ &m.args.tokens.clone(),
true,
m.span(),
);
@@ -1252,7 +1254,7 @@ impl<'a> State<'a> {
self.popen();
self.commasep(Consistent, &args, |s, arg| match arg {
- AsmArg::Template(template) => s.print_string(&template, ast::StrStyle::Cooked),
+ AsmArg::Template(template) => s.print_string(template, ast::StrStyle::Cooked),
AsmArg::Operand(op) => {
let print_reg_or_class = |s: &mut Self, r: &InlineAsmRegOrRegClass| match r {
InlineAsmRegOrRegClass::Reg(r) => s.print_symbol(*r, ast::StrStyle::Cooked),
@@ -1364,7 +1366,7 @@ impl<'a> State<'a> {
pub(crate) fn print_local_decl(&mut self, loc: &ast::Local) {
self.print_pat(&loc.pat);
- if let Some(ref ty) = loc.ty {
+ if let Some(ty) = &loc.ty {
self.word_space(":");
self.print_type(ty);
}
@@ -1388,7 +1390,7 @@ impl<'a> State<'a> {
for item_segment in &path.segments[qself.position..] {
self.word("::");
self.print_ident(item_segment.ident);
- if let Some(ref args) = item_segment.args {
+ if let Some(args) = &item_segment.args {
self.print_generic_args(args, colons_before_params)
}
}
@@ -1399,42 +1401,42 @@ impl<'a> State<'a> {
self.ann.pre(self, AnnNode::Pat(pat));
/* Pat isn't normalized, but the beauty of it
is that it doesn't matter */
- match pat.kind {
+ match &pat.kind {
PatKind::Wild => self.word("_"),
- PatKind::Ident(BindingAnnotation(by_ref, mutbl), ident, ref sub) => {
- if by_ref == ByRef::Yes {
+ PatKind::Ident(BindingAnnotation(by_ref, mutbl), ident, sub) => {
+ if *by_ref == ByRef::Yes {
self.word_nbsp("ref");
}
- if mutbl == Mutability::Mut {
+ if mutbl.is_mut() {
self.word_nbsp("mut");
}
- self.print_ident(ident);
- if let Some(ref p) = *sub {
+ self.print_ident(*ident);
+ if let Some(p) = sub {
self.space();
self.word_space("@");
self.print_pat(p);
}
}
- PatKind::TupleStruct(ref qself, ref path, ref elts) => {
+ PatKind::TupleStruct(qself, path, elts) => {
if let Some(qself) = qself {
self.print_qpath(path, qself, true);
} else {
self.print_path(path, true, 0);
}
self.popen();
- self.commasep(Inconsistent, &elts, |s, p| s.print_pat(p));
+ self.commasep(Inconsistent, elts, |s, p| s.print_pat(p));
self.pclose();
}
- PatKind::Or(ref pats) => {
- self.strsep("|", true, Inconsistent, &pats, |s, p| s.print_pat(p));
+ PatKind::Or(pats) => {
+ self.strsep("|", true, Inconsistent, pats, |s, p| s.print_pat(p));
}
- PatKind::Path(None, ref path) => {
+ PatKind::Path(None, path) => {
self.print_path(path, true, 0);
}
- PatKind::Path(Some(ref qself), ref path) => {
+ PatKind::Path(Some(qself), path) => {
self.print_qpath(path, qself, false);
}
- PatKind::Struct(ref qself, ref path, ref fields, etc) => {
+ PatKind::Struct(qself, path, fields, etc) => {
if let Some(qself) = qself {
self.print_qpath(path, qself, true);
} else {
@@ -1448,7 +1450,7 @@ impl<'a> State<'a> {
}
self.commasep_cmnt(
Consistent,
- &fields,
+ fields,
|s, f| {
s.cbox(INDENT_UNIT);
if !f.is_shorthand {
@@ -1460,7 +1462,7 @@ impl<'a> State<'a> {
},
|f| f.pat.span,
);
- if etc {
+ if *etc {
if !fields.is_empty() {
self.word_space(",");
}
@@ -1471,21 +1473,21 @@ impl<'a> State<'a> {
}
self.word("}");
}
- PatKind::Tuple(ref elts) => {
+ PatKind::Tuple(elts) => {
self.popen();
- self.commasep(Inconsistent, &elts, |s, p| s.print_pat(p));
+ self.commasep(Inconsistent, elts, |s, p| s.print_pat(p));
if elts.len() == 1 {
self.word(",");
}
self.pclose();
}
- PatKind::Box(ref inner) => {
+ PatKind::Box(inner) => {
self.word("box ");
self.print_pat(inner);
}
- PatKind::Ref(ref inner, mutbl) => {
+ PatKind::Ref(inner, mutbl) => {
self.word("&");
- if mutbl == Mutability::Mut {
+ if mutbl.is_mut() {
self.word("mut ");
}
if let PatKind::Ident(ast::BindingAnnotation::MUT, ..) = inner.kind {
@@ -1496,12 +1498,12 @@ impl<'a> State<'a> {
self.print_pat(inner);
}
}
- PatKind::Lit(ref e) => self.print_expr(&**e),
- PatKind::Range(ref begin, ref end, Spanned { node: ref end_kind, .. }) => {
+ PatKind::Lit(e) => self.print_expr(e),
+ PatKind::Range(begin, end, Spanned { node: end_kind, .. }) => {
if let Some(e) = begin {
self.print_expr(e);
}
- match *end_kind {
+ match end_kind {
RangeEnd::Included(RangeSyntax::DotDotDot) => self.word("..."),
RangeEnd::Included(RangeSyntax::DotDotEq) => self.word("..="),
RangeEnd::Excluded => self.word(".."),
@@ -1510,36 +1512,36 @@ impl<'a> State<'a> {
self.print_expr(e);
}
}
- PatKind::Slice(ref elts) => {
+ PatKind::Slice(elts) => {
self.word("[");
- self.commasep(Inconsistent, &elts, |s, p| s.print_pat(p));
+ self.commasep(Inconsistent, elts, |s, p| s.print_pat(p));
self.word("]");
}
PatKind::Rest => self.word(".."),
- PatKind::Paren(ref inner) => {
+ PatKind::Paren(inner) => {
self.popen();
self.print_pat(inner);
self.pclose();
}
- PatKind::MacCall(ref m) => self.print_mac(m),
+ PatKind::MacCall(m) => self.print_mac(m),
}
self.ann.post(self, AnnNode::Pat(pat))
}
fn print_explicit_self(&mut self, explicit_self: &ast::ExplicitSelf) {
- match explicit_self.node {
+ match &explicit_self.node {
SelfKind::Value(m) => {
- self.print_mutability(m, false);
+ self.print_mutability(*m, false);
self.word("self")
}
- SelfKind::Region(ref lt, m) => {
+ SelfKind::Region(lt, m) => {
self.word("&");
self.print_opt_lifetime(lt);
- self.print_mutability(m, false);
+ self.print_mutability(*m, false);
self.word("self")
}
- SelfKind::Explicit(ref typ, m) => {
- self.print_mutability(m, false);
+ SelfKind::Explicit(typ, m) => {
+ self.print_mutability(*m, false);
self.word("self");
self.word_space(":");
self.print_type(typ)
@@ -1598,10 +1600,10 @@ impl<'a> State<'a> {
self.word("<");
- self.commasep(Inconsistent, &generic_params, |s, param| {
+ self.commasep(Inconsistent, generic_params, |s, param| {
s.print_outer_attributes_inline(&param.attrs);
- match param.kind {
+ match &param.kind {
ast::GenericParamKind::Lifetime => {
let lt = ast::Lifetime { id: param.id, ident: param.ident };
s.print_lifetime(lt);
@@ -1610,19 +1612,19 @@ impl<'a> State<'a> {
s.print_lifetime_bounds(&param.bounds)
}
}
- ast::GenericParamKind::Type { ref default } => {
+ ast::GenericParamKind::Type { default } => {
s.print_ident(param.ident);
if !param.bounds.is_empty() {
s.word_nbsp(":");
s.print_type_bounds(&param.bounds);
}
- if let Some(ref default) = default {
+ if let Some(default) = default {
s.space();
s.word_space("=");
s.print_type(default)
}
}
- ast::GenericParamKind::Const { ref ty, kw_span: _, ref default } => {
+ ast::GenericParamKind::Const { ty, default, .. } => {
s.word_space("const");
s.print_ident(param.ident);
s.space();
@@ -1632,7 +1634,7 @@ impl<'a> State<'a> {
s.word_nbsp(":");
s.print_type_bounds(&param.bounds);
}
- if let Some(ref default) = default {
+ if let Some(default) = default {
s.space();
s.word_space("=");
s.print_expr(&default.value);
@@ -1714,9 +1716,9 @@ impl<'a> State<'a> {
where_clause: ast::WhereClause {
has_where_token: false,
predicates: Vec::new(),
- span: rustc_span::DUMMY_SP,
+ span: DUMMY_SP,
},
- span: rustc_span::DUMMY_SP,
+ span: DUMMY_SP,
};
let header = ast::FnHeader { unsafety, ext, ..ast::FnHeader::default() };
self.print_fn(decl, header, name, &generics);
@@ -1735,7 +1737,7 @@ impl<'a> State<'a> {
}
ast::Extern::Explicit(abi, _) => {
self.word_nbsp("extern");
- self.print_literal(&abi.as_lit());
+ self.print_token_literal(abi.as_token_lit(), abi.span);
self.nbsp();
}
}