summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_ast_pretty/src/pprust/state/item.rs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--compiler/rustc_ast_pretty/src/pprust/state/item.rs128
1 files changed, 61 insertions, 67 deletions
diff --git a/compiler/rustc_ast_pretty/src/pprust/state/item.rs b/compiler/rustc_ast_pretty/src/pprust/state/item.rs
index 159853c9e..5b6a07721 100644
--- a/compiler/rustc_ast_pretty/src/pprust/state/item.rs
+++ b/compiler/rustc_ast_pretty/src/pprust/state/item.rs
@@ -136,10 +136,10 @@ impl<'a> State<'a> {
self.maybe_print_comment(item.span.lo());
self.print_outer_attributes(&item.attrs);
self.ann.pre(self, AnnNode::Item(item));
- match item.kind {
+ match &item.kind {
ast::ItemKind::ExternCrate(orig_name) => {
self.head(visibility_qualified(&item.vis, "extern crate"));
- if let Some(orig_name) = orig_name {
+ if let &Some(orig_name) = orig_name {
self.print_name(orig_name);
self.space();
self.word("as");
@@ -150,35 +150,41 @@ impl<'a> State<'a> {
self.end(); // end inner head-block
self.end(); // end outer head-block
}
- ast::ItemKind::Use(ref tree) => {
+ ast::ItemKind::Use(tree) => {
self.print_visibility(&item.vis);
self.word_nbsp("use");
self.print_use_tree(tree);
self.word(";");
}
- ast::ItemKind::Static(ref ty, mutbl, ref body) => {
+ ast::ItemKind::Static(ty, mutbl, body) => {
let def = ast::Defaultness::Final;
- self.print_item_const(item.ident, Some(mutbl), ty, body.as_deref(), &item.vis, def);
+ self.print_item_const(
+ item.ident,
+ Some(*mutbl),
+ ty,
+ body.as_deref(),
+ &item.vis,
+ def,
+ );
}
- ast::ItemKind::Const(def, ref ty, ref body) => {
- self.print_item_const(item.ident, None, ty, body.as_deref(), &item.vis, def);
+ ast::ItemKind::Const(def, ty, body) => {
+ self.print_item_const(item.ident, None, ty, body.as_deref(), &item.vis, *def);
}
- ast::ItemKind::Fn(box ast::Fn { defaultness, ref sig, ref generics, ref body }) => {
- let body = body.as_deref();
+ ast::ItemKind::Fn(box ast::Fn { defaultness, sig, generics, body }) => {
self.print_fn_full(
sig,
item.ident,
generics,
&item.vis,
- defaultness,
- body,
+ *defaultness,
+ body.as_deref(),
&item.attrs,
);
}
- ast::ItemKind::Mod(unsafety, ref mod_kind) => {
+ ast::ItemKind::Mod(unsafety, mod_kind) => {
self.head(Self::to_string(|s| {
s.print_visibility(&item.vis);
- s.print_unsafety(unsafety);
+ s.print_unsafety(*unsafety);
s.word("mod");
}));
self.print_ident(item.ident);
@@ -201,13 +207,13 @@ impl<'a> State<'a> {
}
}
}
- ast::ItemKind::ForeignMod(ref nmod) => {
+ ast::ItemKind::ForeignMod(nmod) => {
self.head(Self::to_string(|s| {
s.print_unsafety(nmod.unsafety);
s.word("extern");
}));
if let Some(abi) = nmod.abi {
- self.print_literal(&abi.as_lit());
+ self.print_token_literal(abi.as_token_lit(), abi.span);
self.nbsp();
}
self.bopen();
@@ -215,7 +221,7 @@ impl<'a> State<'a> {
let empty = item.attrs.is_empty() && nmod.items.is_empty();
self.bclose(item.span, empty);
}
- ast::ItemKind::GlobalAsm(ref asm) => {
+ ast::ItemKind::GlobalAsm(asm) => {
self.head(visibility_qualified(&item.vis, "global_asm!"));
self.print_inline_asm(asm);
self.word(";");
@@ -224,32 +230,31 @@ impl<'a> State<'a> {
}
ast::ItemKind::TyAlias(box ast::TyAlias {
defaultness,
- ref generics,
+ generics,
where_clauses,
where_predicates_split,
- ref bounds,
- ref ty,
+ bounds,
+ ty,
}) => {
- let ty = ty.as_deref();
self.print_associated_type(
item.ident,
generics,
- where_clauses,
- where_predicates_split,
+ *where_clauses,
+ *where_predicates_split,
bounds,
- ty,
+ ty.as_deref(),
&item.vis,
- defaultness,
+ *defaultness,
);
}
- ast::ItemKind::Enum(ref enum_definition, ref params) => {
+ ast::ItemKind::Enum(enum_definition, params) => {
self.print_enum_def(enum_definition, params, item.ident, item.span, &item.vis);
}
- ast::ItemKind::Struct(ref struct_def, ref generics) => {
+ ast::ItemKind::Struct(struct_def, generics) => {
self.head(visibility_qualified(&item.vis, "struct"));
self.print_struct(struct_def, generics, item.ident, item.span, true);
}
- ast::ItemKind::Union(ref struct_def, ref generics) => {
+ ast::ItemKind::Union(struct_def, generics) => {
self.head(visibility_qualified(&item.vis, "union"));
self.print_struct(struct_def, generics, item.ident, item.span, true);
}
@@ -258,15 +263,15 @@ impl<'a> State<'a> {
polarity,
defaultness,
constness,
- ref generics,
- ref of_trait,
- ref self_ty,
- ref items,
+ generics,
+ of_trait,
+ self_ty,
+ items,
}) => {
self.head("");
self.print_visibility(&item.vis);
- self.print_defaultness(defaultness);
- self.print_unsafety(unsafety);
+ self.print_defaultness(*defaultness);
+ self.print_unsafety(*unsafety);
self.word("impl");
if generics.params.is_empty() {
@@ -276,13 +281,13 @@ impl<'a> State<'a> {
self.space();
}
- self.print_constness(constness);
+ self.print_constness(*constness);
if let ast::ImplPolarity::Negative(_) = polarity {
self.word("!");
}
- if let Some(ref t) = *of_trait {
+ if let Some(t) = of_trait {
self.print_trait_ref(t);
self.space();
self.word_space("for");
@@ -303,21 +308,21 @@ impl<'a> State<'a> {
ast::ItemKind::Trait(box ast::Trait {
is_auto,
unsafety,
- ref generics,
- ref bounds,
- ref items,
+ generics,
+ bounds,
+ items,
..
}) => {
self.head("");
self.print_visibility(&item.vis);
- self.print_unsafety(unsafety);
- self.print_is_auto(is_auto);
+ self.print_unsafety(*unsafety);
+ self.print_is_auto(*is_auto);
self.word_nbsp("trait");
self.print_ident(item.ident);
self.print_generic_params(&generics.params);
let mut real_bounds = Vec::with_capacity(bounds.len());
for b in bounds.iter() {
- if let GenericBound::Trait(ref ptr, ast::TraitBoundModifier::Maybe) = *b {
+ if let GenericBound::Trait(ptr, ast::TraitBoundModifier::Maybe) = b {
self.space();
self.word_space("for ?");
self.print_trait_ref(&ptr.trait_ref);
@@ -339,38 +344,27 @@ impl<'a> State<'a> {
let empty = item.attrs.is_empty() && items.is_empty();
self.bclose(item.span, empty);
}
- ast::ItemKind::TraitAlias(ref generics, ref bounds) => {
+ ast::ItemKind::TraitAlias(generics, bounds) => {
self.head(visibility_qualified(&item.vis, "trait"));
self.print_ident(item.ident);
self.print_generic_params(&generics.params);
- let mut real_bounds = Vec::with_capacity(bounds.len());
- // FIXME(durka) this seems to be some quite outdated syntax
- for b in bounds.iter() {
- if let GenericBound::Trait(ref ptr, ast::TraitBoundModifier::Maybe) = *b {
- self.space();
- self.word_space("for ?");
- self.print_trait_ref(&ptr.trait_ref);
- } else {
- real_bounds.push(b.clone());
- }
- }
self.nbsp();
- if !real_bounds.is_empty() {
+ if !bounds.is_empty() {
self.word_nbsp("=");
- self.print_type_bounds(&real_bounds);
+ self.print_type_bounds(&bounds);
}
self.print_where_clause(&generics.where_clause);
self.word(";");
self.end(); // end inner head-block
self.end(); // end outer head-block
}
- ast::ItemKind::MacCall(ref mac) => {
+ ast::ItemKind::MacCall(mac) => {
self.print_mac(mac);
if mac.args.need_semicolon() {
self.word(";");
}
}
- ast::ItemKind::MacroDef(ref macro_def) => {
+ ast::ItemKind::MacroDef(macro_def) => {
self.print_mac_def(macro_def, &item.ident, item.span, |state| {
state.print_visibility(&item.vis)
});
@@ -412,11 +406,11 @@ impl<'a> State<'a> {
}
pub(crate) fn print_visibility(&mut self, vis: &ast::Visibility) {
- match vis.kind {
+ match &vis.kind {
ast::VisibilityKind::Public => self.word_nbsp("pub"),
- ast::VisibilityKind::Restricted { ref path, id: _, shorthand } => {
+ ast::VisibilityKind::Restricted { path, shorthand, .. } => {
let path = Self::to_string(|s| s.print_path(path, false, 0));
- if shorthand && (path == "crate" || path == "self" || path == "super") {
+ if *shorthand && (path == "crate" || path == "self" || path == "super") {
self.word_nbsp(format!("pub({})", path))
} else {
self.word_nbsp(format!("pub(in {})", path))
@@ -465,7 +459,7 @@ impl<'a> State<'a> {
) {
self.print_ident(ident);
self.print_generic_params(&generics.params);
- match struct_def {
+ match &struct_def {
ast::VariantData::Tuple(..) | ast::VariantData::Unit(..) => {
if let ast::VariantData::Tuple(..) = struct_def {
self.popen();
@@ -484,7 +478,7 @@ impl<'a> State<'a> {
self.end();
self.end(); // Close the outer-box.
}
- ast::VariantData::Struct(ref fields, ..) => {
+ ast::VariantData::Struct(fields, ..) => {
self.print_where_clause(&generics.where_clause);
self.print_record_struct_body(fields, span);
}
@@ -496,7 +490,7 @@ impl<'a> State<'a> {
self.print_visibility(&v.vis);
let generics = ast::Generics::default();
self.print_struct(&v.data, &generics, v.ident, v.span, false);
- if let Some(ref d) = v.disr_expr {
+ if let Some(d) = &v.disr_expr {
self.space();
self.word_space("=");
self.print_expr(&d.value)
@@ -657,10 +651,10 @@ impl<'a> State<'a> {
}
fn print_use_tree(&mut self, tree: &ast::UseTree) {
- match tree.kind {
- ast::UseTreeKind::Simple(rename, ..) => {
+ match &tree.kind {
+ ast::UseTreeKind::Simple(rename) => {
self.print_path(&tree.prefix, false, 0);
- if let Some(rename) = rename {
+ if let &Some(rename) = rename {
self.nbsp();
self.word_nbsp("as");
self.print_ident(rename);
@@ -673,7 +667,7 @@ impl<'a> State<'a> {
}
self.word("*");
}
- ast::UseTreeKind::Nested(ref items) => {
+ ast::UseTreeKind::Nested(items) => {
if !tree.prefix.segments.is_empty() {
self.print_path(&tree.prefix, false, 0);
self.word("::");