]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc/hir/print.rs
Use Arena inside hir::ImplItem.
[rust.git] / src / librustc / hir / print.rs
index 4cbe0e8099126a74d2bbbba25bf94248df61d05b..dc270fc40c989e83d6dd9874ba51d61e8adf4566 100644 (file)
@@ -21,7 +21,7 @@
 pub enum AnnNode<'a> {
     Name(&'a ast::Name),
     Block(&'a hir::Block),
-    Item(&'a hir::Item),
+    Item(&'a hir::Item<'a>),
     SubItem(hir::HirId),
     Expr(&'a hir::Expr),
     Pat(&'a hir::Pat),
@@ -43,7 +43,7 @@ fn pre(&self, _state: &mut State<'_>, _node: AnnNode<'_>) {
     }
     fn post(&self, _state: &mut State<'_>, _node: AnnNode<'_>) {
     }
-    fn try_fetch_item(&self, _: hir::HirId) -> Option<&hir::Item> {
+    fn try_fetch_item(&self, _: hir::HirId) -> Option<&hir::Item<'_>> {
         None
     }
 }
@@ -52,8 +52,8 @@ fn try_fetch_item(&self, _: hir::HirId) -> Option<&hir::Item> {
 impl PpAnn for NoAnn {}
 pub const NO_ANN: &dyn PpAnn = &NoAnn;
 
-impl PpAnn for hir::Crate {
-    fn try_fetch_item(&self, item: hir::HirId) -> Option<&hir::Item> {
+impl PpAnn for hir::Crate<'a> {
+    fn try_fetch_item(&self, item: hir::HirId) -> Option<&hir::Item<'_>> {
         Some(self.item(item))
     }
     fn nested(&self, state: &mut State<'_>, nested: Nested) {
@@ -107,7 +107,7 @@ fn print_generic_args(&mut self, args: &ast::GenericArgs, _colons_before_params:
 /// it can scan the input text for comments to copy forward.
 pub fn print_crate<'a>(cm: &'a SourceMap,
                        sess: &ParseSess,
-                       krate: &hir::Crate,
+                       krate: &hir::Crate<'a>,
                        filename: FileName,
                        input: String,
                        ann: &'a dyn PpAnn) -> String {
@@ -267,11 +267,11 @@ pub fn print_mod(&mut self, _mod: &hir::Mod, attrs: &[ast::Attribute]) {
     }
 
     pub fn print_foreign_mod(&mut self,
-                             nmod: &hir::ForeignMod,
+                             nmod: &hir::ForeignMod<'_>,
                              attrs: &[ast::Attribute])
                              {
         self.print_inner_attributes(attrs);
-        for item in &nmod.items {
+        for item in nmod.items {
             self.print_foreign_item(item);
         }
     }
@@ -294,16 +294,12 @@ pub fn print_type(&mut self, ty: &hir::Ty) {
             }
             hir::TyKind::Ptr(ref mt) => {
                 self.s.word("*");
-                match mt.mutbl {
-                    hir::Mutability::Mutable => self.word_nbsp("mut"),
-                    hir::Mutability::Immutable => self.word_nbsp("const"),
-                }
-                self.print_type(&mt.ty);
+                self.print_mt(mt, true);
             }
             hir::TyKind::Rptr(ref lifetime, ref mt) => {
                 self.s.word("&");
                 self.print_opt_lifetime(lifetime);
-                self.print_mt(mt);
+                self.print_mt(mt, false);
             }
             hir::TyKind::Never => {
                 self.s.word("!");
@@ -365,7 +361,7 @@ pub fn print_type(&mut self, ty: &hir::Ty) {
         self.end()
     }
 
-    pub fn print_foreign_item(&mut self, item: &hir::ForeignItem) {
+    pub fn print_foreign_item(&mut self, item: &hir::ForeignItem<'_>) {
         self.hardbreak_if_not_bol();
         self.maybe_print_comment(item.span.lo());
         self.print_outer_attributes(&item.attrs);
@@ -390,7 +386,7 @@ pub fn print_foreign_item(&mut self, item: &hir::ForeignItem) {
             }
             hir::ForeignItemKind::Static(ref t, m) => {
                 self.head(visibility_qualified(&item.vis, "static"));
-                if m == hir::Mutability::Mutable {
+                if m == hir::Mutability::Mut {
                     self.word_space("mut");
                 }
                 self.print_ident(item.ident);
@@ -449,7 +445,7 @@ fn print_associated_type(&mut self,
 
     fn print_item_type(
         &mut self,
-        item: &hir::Item,
+        item: &hir::Item<'_>,
         generics: &hir::Generics,
         inner: impl Fn(&mut Self),
     ) {
@@ -466,7 +462,7 @@ fn print_item_type(
     }
 
     /// Pretty-print an item
-    pub fn print_item(&mut self, item: &hir::Item) {
+    pub fn print_item(&mut self, item: &hir::Item<'_>) {
         self.hardbreak_if_not_bol();
         self.maybe_print_comment(item.span.lo());
         self.print_outer_attributes(&item.attrs);
@@ -506,7 +502,7 @@ pub fn print_item(&mut self, item: &hir::Item) {
             }
             hir::ItemKind::Static(ref ty, m, expr) => {
                 self.head(visibility_qualified(&item.vis, "static"));
-                if m == hir::Mutability::Mutable {
+                if m == hir::Mutability::Mut {
                     self.word_space("mut");
                 }
                 self.print_ident(item.ident);
@@ -605,7 +601,7 @@ pub fn print_item(&mut self, item: &hir::Item) {
                           ref generics,
                           ref opt_trait,
                           ref ty,
-                          ref impl_items) => {
+                          impl_items) => {
                 self.head("");
                 self.print_visibility(&item.vis);
                 self.print_defaultness(defaultness);
@@ -638,7 +634,7 @@ pub fn print_item(&mut self, item: &hir::Item) {
                 }
                 self.bclose(item.span);
             }
-            hir::ItemKind::Trait(is_auto, unsafety, ref generics, ref bounds, ref trait_items) => {
+            hir::ItemKind::Trait(is_auto, unsafety, ref generics, ref bounds, trait_items) => {
                 self.head("");
                 self.print_visibility(&item.vis);
                 self.print_is_auto(is_auto);
@@ -850,7 +846,7 @@ pub fn print_method_sig(&mut self,
                       body_id)
     }
 
-    pub fn print_trait_item(&mut self, ti: &hir::TraitItem) {
+    pub fn print_trait_item(&mut self, ti: &hir::TraitItem<'_>) {
         self.ann.pre(self, AnnNode::SubItem(ti.hir_id));
         self.hardbreak_if_not_bol();
         self.maybe_print_comment(ti.span.lo());
@@ -886,7 +882,7 @@ pub fn print_trait_item(&mut self, ti: &hir::TraitItem) {
         self.ann.post(self, AnnNode::SubItem(ti.hir_id))
     }
 
-    pub fn print_impl_item(&mut self, ii: &hir::ImplItem) {
+    pub fn print_impl_item(&mut self, ii: &hir::ImplItem<'_>) {
         self.ann.pre(self, AnnNode::SubItem(ii.hir_id));
         self.hardbreak_if_not_bol();
         self.maybe_print_comment(ii.span.lo());
@@ -1178,11 +1174,18 @@ fn print_expr_unary(&mut self, op: hir::UnOp, expr: &hir::Expr) {
     }
 
     fn print_expr_addr_of(&mut self,
+                          kind: hir::BorrowKind,
                           mutability: hir::Mutability,
                           expr: &hir::Expr)
-                          {
+    {
         self.s.word("&");
-        self.print_mutability(mutability);
+        match kind {
+            hir::BorrowKind::Ref => self.print_mutability(mutability, false),
+            hir::BorrowKind::Raw => {
+                self.word_nbsp("raw");
+                self.print_mutability(mutability, true);
+            }
+        }
         self.print_expr_maybe_paren(expr, parser::PREC_PREFIX)
     }
 
@@ -1225,8 +1228,8 @@ pub fn print_expr(&mut self, expr: &hir::Expr) {
             hir::ExprKind::Unary(op, ref expr) => {
                 self.print_expr_unary(op, &expr);
             }
-            hir::ExprKind::AddrOf(m, ref expr) => {
-                self.print_expr_addr_of(m, &expr);
+            hir::ExprKind::AddrOf(k, m, ref expr) => {
+                self.print_expr_addr_of(k, m, &expr);
             }
             hir::ExprKind::Lit(ref lit) => {
                 self.print_literal(&lit);
@@ -1629,11 +1632,11 @@ pub fn print_pat(&mut self, pat: &hir::Pat) {
                 match binding_mode {
                     hir::BindingAnnotation::Ref => {
                         self.word_nbsp("ref");
-                        self.print_mutability(hir::Mutability::Immutable);
+                        self.print_mutability(hir::Mutability::Not, false);
                     }
                     hir::BindingAnnotation::RefMut => {
                         self.word_nbsp("ref");
-                        self.print_mutability(hir::Mutability::Mutable);
+                        self.print_mutability(hir::Mutability::Mut, false);
                     }
                     hir::BindingAnnotation::Unannotated => {}
                     hir::BindingAnnotation::Mutable => {
@@ -2060,15 +2063,15 @@ pub fn print_where_clause(&mut self, where_clause: &hir::WhereClause) {
         }
     }
 
-    pub fn print_mutability(&mut self, mutbl: hir::Mutability) {
+    pub fn print_mutability(&mut self, mutbl: hir::Mutability, print_const: bool) {
         match mutbl {
-            hir::Mutability::Mutable => self.word_nbsp("mut"),
-            hir::Mutability::Immutable => {},
+            hir::Mutability::Mut => self.word_nbsp("mut"),
+            hir::Mutability::Not => if print_const { self.word_nbsp("const") },
         }
     }
 
-    pub fn print_mt(&mut self, mt: &hir::MutTy) {
-        self.print_mutability(mt.mutbl);
+    pub fn print_mt(&mut self, mt: &hir::MutTy, print_const: bool) {
+        self.print_mutability(mt.mutbl, print_const);
         self.print_type(&mt.ty)
     }