]> git.lizzy.rs Git - rust.git/commitdiff
Add HirId to VisibilityKind::Restricted
authorMark Rousskov <mark.simulacrum@gmail.com>
Tue, 31 Jul 2018 16:43:51 +0000 (10:43 -0600)
committerMark Rousskov <mark.simulacrum@gmail.com>
Tue, 7 Aug 2018 16:13:17 +0000 (10:13 -0600)
14 files changed:
src/librustc/hir/intravisit.rs
src/librustc/hir/lowering.rs
src/librustc/hir/mod.rs
src/librustc/ich/impls_hir.rs
src/librustc/lint/context.rs
src/librustc/lint/mod.rs
src/librustc/middle/dead.rs
src/librustc/middle/resolve_lifetime.rs
src/librustc/middle/stability.rs
src/librustc_lint/builtin.rs
src/librustc_passes/hir_stats.rs
src/librustc_privacy/lib.rs
src/librustdoc/clean/auto_trait.rs
src/librustdoc/clean/blanket_impl.rs

index 4274cd3a0a6559e6759a13b5734714503f22588c..d853d3d9a7fb4975601bc311b1c538455d131c4d 100644 (file)
@@ -353,10 +353,10 @@ fn visit_generic_arg(&mut self, generic_arg: &'v GenericArg) {
     fn visit_lifetime(&mut self, lifetime: &'v Lifetime) {
         walk_lifetime(self, lifetime)
     }
-    fn visit_qpath(&mut self, qpath: &'v QPath, id: NodeId, span: Span) {
+    fn visit_qpath(&mut self, qpath: &'v QPath, id: HirId, span: Span) {
         walk_qpath(self, qpath, id, span)
     }
-    fn visit_path(&mut self, path: &'v Path, _id: NodeId) {
+    fn visit_path(&mut self, path: &'v Path, _id: HirId) {
         walk_path(self, path)
     }
     fn visit_path_segment(&mut self, path_span: Span, path_segment: &'v PathSegment) {
@@ -456,7 +456,7 @@ pub fn walk_trait_ref<'v, V>(visitor: &mut V, trait_ref: &'v TraitRef)
     where V: Visitor<'v>
 {
     visitor.visit_id(trait_ref.ref_id);
-    visitor.visit_path(&trait_ref.path, trait_ref.ref_id)
+    visitor.visit_path(&trait_ref.path, trait_ref.hir_ref_id)
 }
 
 pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) {
@@ -471,7 +471,7 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) {
         }
         ItemKind::Use(ref path, _) => {
             visitor.visit_id(item.id);
-            visitor.visit_path(path, item.id);
+            visitor.visit_path(path, item.hir_id);
         }
         ItemKind::Static(ref typ, _, body) |
         ItemKind::Const(ref typ, body) => {
@@ -602,7 +602,7 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty) {
             visitor.visit_fn_decl(&function_declaration.decl);
         }
         TyKind::Path(ref qpath) => {
-            visitor.visit_qpath(qpath, typ.id, typ.span);
+            visitor.visit_qpath(qpath, typ.hir_id, typ.span);
         }
         TyKind::Array(ref ty, ref length) => {
             visitor.visit_ty(ty);
@@ -621,7 +621,7 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty) {
     }
 }
 
-pub fn walk_qpath<'v, V: Visitor<'v>>(visitor: &mut V, qpath: &'v QPath, id: NodeId, span: Span) {
+pub fn walk_qpath<'v, V: Visitor<'v>>(visitor: &mut V, qpath: &'v QPath, id: HirId, span: Span) {
     match *qpath {
         QPath::Resolved(ref maybe_qself, ref path) => {
             if let Some(ref qself) = *maybe_qself {
@@ -670,14 +670,14 @@ pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat) {
     visitor.visit_id(pattern.id);
     match pattern.node {
         PatKind::TupleStruct(ref qpath, ref children, _) => {
-            visitor.visit_qpath(qpath, pattern.id, pattern.span);
+            visitor.visit_qpath(qpath, pattern.hir_id, pattern.span);
             walk_list!(visitor, visit_pat, children);
         }
         PatKind::Path(ref qpath) => {
-            visitor.visit_qpath(qpath, pattern.id, pattern.span);
+            visitor.visit_qpath(qpath, pattern.hir_id, pattern.span);
         }
         PatKind::Struct(ref qpath, ref fields, _) => {
-            visitor.visit_qpath(qpath, pattern.id, pattern.span);
+            visitor.visit_qpath(qpath, pattern.hir_id, pattern.span);
             for field in fields {
                 visitor.visit_id(field.node.id);
                 visitor.visit_ident(field.node.ident);
@@ -985,7 +985,7 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) {
             visitor.visit_anon_const(count)
         }
         ExprKind::Struct(ref qpath, ref fields, ref optional_base) => {
-            visitor.visit_qpath(qpath, expression.id, expression.span);
+            visitor.visit_qpath(qpath, expression.hir_id, expression.span);
             for field in fields {
                 visitor.visit_id(field.id);
                 visitor.visit_ident(field.ident);
@@ -1062,7 +1062,7 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) {
             visitor.visit_expr(index_expression)
         }
         ExprKind::Path(ref qpath) => {
-            visitor.visit_qpath(qpath, expression.id, expression.span);
+            visitor.visit_qpath(qpath, expression.hir_id, expression.span);
         }
         ExprKind::Break(ref destination, ref opt_expr) => {
             if let Some(ref label) = destination.label {
@@ -1108,9 +1108,9 @@ pub fn walk_arm<'v, V: Visitor<'v>>(visitor: &mut V, arm: &'v Arm) {
 }
 
 pub fn walk_vis<'v, V: Visitor<'v>>(visitor: &mut V, vis: &'v Visibility) {
-    if let VisibilityKind::Restricted { ref path, id } = vis.node {
+    if let VisibilityKind::Restricted { ref path, id, hir_id } = vis.node {
         visitor.visit_id(id);
-        visitor.visit_path(path, id)
+        visitor.visit_path(path, hir_id)
     }
 }
 
index 0cc5d3034e0a6c7e8e6fc957c840f87dcafcd4a5..6b66fd8a2b2ff0af74171613dd0f8503624296a3 100644 (file)
@@ -2155,12 +2155,14 @@ fn visit_lifetime(&mut self, lifetime: &'v hir::Lifetime) {
             let future_path =
                 this.std_path(span, &["future", "Future"], Some(future_params), false);
 
+            let LoweredNodeId { node_id, hir_id } = this.next_id();
             let mut bounds = vec![
                 hir::GenericBound::Trait(
                     hir::PolyTraitRef {
                         trait_ref: hir::TraitRef {
                             path: future_path,
-                            ref_id: this.next_id().node_id,
+                            ref_id: node_id,
+                            hir_ref_id: hir_id,
                         },
                         bound_generic_params: hir_vec![],
                         span,
@@ -2482,9 +2484,11 @@ fn lower_trait_ref(&mut self, p: &TraitRef, itctx: ImplTraitContext) -> hir::Tra
             hir::QPath::Resolved(None, path) => path.and_then(|path| path),
             qpath => bug!("lower_trait_ref: unexpected QPath `{:?}`", qpath),
         };
+        let LoweredNodeId { node_id, hir_id } = self.lower_node_id(p.ref_id);
         hir::TraitRef {
             path,
-            ref_id: self.lower_node_id(p.ref_id).node_id,
+            ref_id: node_id,
+            hir_ref_id: hir_id,
         }
     }
 
@@ -2843,11 +2847,13 @@ fn lower_use_tree(
                             hir::VisibilityKind::Public => hir::VisibilityKind::Public,
                             hir::VisibilityKind::Crate(sugar) => hir::VisibilityKind::Crate(sugar),
                             hir::VisibilityKind::Inherited => hir::VisibilityKind::Inherited,
-                            hir::VisibilityKind::Restricted { ref path, id: _ } => {
+                            hir::VisibilityKind::Restricted { ref path, id: _, hir_id: _ } => {
+                                let id = this.next_id();
                                 hir::VisibilityKind::Restricted {
                                     path: path.clone(),
                                     // We are allocating a new NodeId here
-                                    id: this.next_id().node_id,
+                                    id: id.node_id,
+                                    hir_id: id.hir_id,
                                 }
                             }
                         };
@@ -2916,11 +2922,13 @@ fn lower_use_tree(
                             hir::VisibilityKind::Public => hir::VisibilityKind::Public,
                             hir::VisibilityKind::Crate(sugar) => hir::VisibilityKind::Crate(sugar),
                             hir::VisibilityKind::Inherited => hir::VisibilityKind::Inherited,
-                            hir::VisibilityKind::Restricted { ref path, id: _ } => {
+                            hir::VisibilityKind::Restricted { ref path, id: _, hir_id: _ } => {
+                                let id = this.next_id();
                                 hir::VisibilityKind::Restricted {
                                     path: path.clone(),
                                     // We are allocating a new NodeId here
-                                    id: this.next_id().node_id,
+                                    id: id.node_id,
+                                    hir_id: id.hir_id,
                                 }
                             }
                         };
@@ -4350,13 +4358,17 @@ fn lower_visibility(
         let node = match v.node {
             VisibilityKind::Public => hir::VisibilityKind::Public,
             VisibilityKind::Crate(sugar) => hir::VisibilityKind::Crate(sugar),
-            VisibilityKind::Restricted { ref path, id } => hir::VisibilityKind::Restricted {
-                path: P(self.lower_path(id, path, ParamMode::Explicit)),
-                id: if let Some(owner) = explicit_owner {
-                    self.lower_node_id_with_owner(id, owner).node_id
+            VisibilityKind::Restricted { ref path, id } => {
+                let lowered_id = if let Some(owner) = explicit_owner {
+                    self.lower_node_id_with_owner(id, owner)
                 } else {
-                    self.lower_node_id(id).node_id
-                },
+                    self.lower_node_id(id)
+                };
+                hir::VisibilityKind::Restricted {
+                    path: P(self.lower_path(id, path, ParamMode::Explicit)),
+                    id: lowered_id.node_id,
+                    hir_id: lowered_id.hir_id,
+                }
             },
             VisibilityKind::Inherited => hir::VisibilityKind::Inherited,
         };
@@ -4675,6 +4687,7 @@ fn ty_path(&mut self, id: LoweredNodeId, span: Span, qpath: hir::QPath) -> hir::
                         trait_ref: hir::TraitRef {
                             path: path.and_then(|path| path),
                             ref_id: id.node_id,
+                            hir_ref_id: id.hir_id,
                         },
                         span,
                     };
index 610add90b8577253eaee6501e7d8b535a9425cfb..0003790e6d552cfc066ed946c8789206b4f1f8c5 100644 (file)
@@ -1912,6 +1912,7 @@ pub enum UseKind {
 pub struct TraitRef {
     pub path: Path,
     pub ref_id: NodeId,
+    pub hir_ref_id: HirId,
 }
 
 #[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
@@ -1931,7 +1932,7 @@ pub struct PolyTraitRef {
 pub enum VisibilityKind {
     Public,
     Crate(CrateSugar),
-    Restricted { path: P<Path>, id: NodeId },
+    Restricted { path: P<Path>, id: NodeId, hir_id: HirId },
     Inherited,
 }
 
index 69872cffdc1b1ea54891628ce55e3583690f1d7c..53bd7106e9680f4f0dae141f5e2df2ca63ae62e3 100644 (file)
@@ -360,6 +360,7 @@ fn hash_stable<W: StableHasherResult>(&self,
 impl_stable_hash_for!(struct hir::TraitRef {
     // Don't hash the ref_id. It is tracked via the thing it is used to access
     ref_id -> _,
+    hir_ref_id -> _,
     path,
 });
 
@@ -723,9 +724,10 @@ fn hash_stable<W: StableHasherResult>(&self,
             hir::VisibilityKind::Crate(sugar) => {
                 sugar.hash_stable(hcx, hasher);
             }
-            hir::VisibilityKind::Restricted { ref path, id } => {
+            hir::VisibilityKind::Restricted { ref path, id, hir_id } => {
                 hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
                     id.hash_stable(hcx, hasher);
+                    hir_id.hash_stable(hcx, hasher);
                 });
                 path.hash_stable(hcx, hasher);
             }
index 15630157722fa502ea3c715648c4ad01f7508914..315ed38ad07703fc14566a3efe808490d6253826 100644 (file)
@@ -869,7 +869,7 @@ fn visit_lifetime(&mut self, lt: &'tcx hir::Lifetime) {
         hir_visit::walk_lifetime(self, lt);
     }
 
-    fn visit_path(&mut self, p: &'tcx hir::Path, id: ast::NodeId) {
+    fn visit_path(&mut self, p: &'tcx hir::Path, id: hir::HirId) {
         run_lints!(self, check_path, p, id);
         hir_visit::walk_path(self, p);
     }
index d267c1812773b07ab6116b4bd3851af2326a6c7e..231a70f873fdc833bb9f2a1163063f28db59e7de 100644 (file)
@@ -242,7 +242,7 @@ fn check_struct_def_post(
             fn check_variant(a: &$hir hir::Variant, b: &$hir hir::Generics);
             fn check_variant_post(a: &$hir hir::Variant, b: &$hir hir::Generics);
             fn check_lifetime(a: &$hir hir::Lifetime);
-            fn check_path(a: &$hir hir::Path, b: ast::NodeId);
+            fn check_path(a: &$hir hir::Path, b: hir::HirId);
             fn check_attribute(a: &$hir ast::Attribute);
 
             /// Called when entering a syntax node that can have lint attributes such
index 0f889549b58e39ddd058b0db12e96262a02adce5..d0e3ae2b9fc465254b731ae70cbe57c5d6a4457b 100644 (file)
@@ -279,7 +279,7 @@ fn visit_pat(&mut self, pat: &'tcx hir::Pat) {
         self.in_pat = false;
     }
 
-    fn visit_path(&mut self, path: &'tcx hir::Path, _: ast::NodeId) {
+    fn visit_path(&mut self, path: &'tcx hir::Path, _: hir::HirId) {
         self.handle_definition(path.def);
         intravisit::walk_path(self, path);
     }
index ca8fe463119c1b9c60ea651acc8a762cb025c6e4..f2d39a905ee5f496d4a33e1a4d2e1413015d6632 100644 (file)
@@ -903,7 +903,7 @@ fn visit_lifetime(&mut self, lifetime_ref: &'tcx hir::Lifetime) {
         self.resolve_lifetime_ref(lifetime_ref);
     }
 
-    fn visit_path(&mut self, path: &'tcx hir::Path, _: ast::NodeId) {
+    fn visit_path(&mut self, path: &'tcx hir::Path, _: hir::HirId) {
         for (i, segment) in path.segments.iter().enumerate() {
             let depth = path.segments.len() - i - 1;
             if let Some(ref args) = segment.args {
index 0aa532fd9a46e9e5e6fd625af800902f0ead7154..8af8d463b112bbfeb9e978a8cc71f5efea7f30d0 100644 (file)
@@ -780,7 +780,8 @@ fn visit_item(&mut self, item: &'tcx hir::Item) {
         intravisit::walk_item(self, item);
     }
 
-    fn visit_path(&mut self, path: &'tcx hir::Path, id: ast::NodeId) {
+    fn visit_path(&mut self, path: &'tcx hir::Path, id: hir::HirId) {
+        let id = self.tcx.hir.hir_to_node_id(id);
         match path.def {
             Def::Local(..) | Def::Upvar(..) |
             Def::PrimTy(..) | Def::SelfTy(..) | Def::Err => {}
index 4ef4397d974c420254d2b3b465690a56a298d285..3a449b6a68e4c260f8c7dc3d13b16e174d2573a1 100644 (file)
@@ -1526,7 +1526,6 @@ fn suggest_changing_assoc_types(ty: &hir::Ty, err: &mut DiagnosticBuilder) {
 
         // We use a HIR visitor to walk the type.
         use rustc::hir::intravisit::{self, Visitor};
-        use syntax::ast::NodeId;
         struct WalkAssocTypes<'a, 'db> where 'db: 'a {
             err: &'a mut DiagnosticBuilder<'db>
         }
@@ -1536,7 +1535,7 @@ fn nested_visit_map<'this>(&'this mut self) -> intravisit::NestedVisitorMap<'thi
                 intravisit::NestedVisitorMap::None
             }
 
-            fn visit_qpath(&mut self, qpath: &'v hir::QPath, id: NodeId, span: Span) {
+            fn visit_qpath(&mut self, qpath: &'v hir::QPath, id: hir::HirId, span: Span) {
                 if TypeAliasBounds::is_type_variable_assoc(qpath) {
                     self.err.span_help(span,
                         "use fully disambiguated paths (i.e., `<T as Trait>::Assoc`) to refer to \
index e7b2869dfe61eaaea68c0f03df8350a07f7c9c5e..3c5a0590c20235ef59de29b070c03a2d8e597a8e 100644 (file)
@@ -224,11 +224,11 @@ fn visit_lifetime(&mut self, lifetime: &'v hir::Lifetime) {
         self.record("Lifetime", Id::Node(lifetime.id), lifetime);
         hir_visit::walk_lifetime(self, lifetime)
     }
-    fn visit_qpath(&mut self, qpath: &'v hir::QPath, id: NodeId, span: Span) {
+    fn visit_qpath(&mut self, qpath: &'v hir::QPath, id: hir::HirId, span: Span) {
         self.record("QPath", Id::None, qpath);
         hir_visit::walk_qpath(self, qpath, id, span)
     }
-    fn visit_path(&mut self, path: &'v hir::Path, _id: NodeId) {
+    fn visit_path(&mut self, path: &'v hir::Path, _id: hir::HirId) {
         self.record("Path", Id::None, path);
         hir_visit::walk_path(self, path)
     }
index 5c3a016a82b4c599955f62c1204333966b530bc3..b6dd0e8b9b21db9d2d440199675bb736ad46c216 100644 (file)
@@ -815,7 +815,7 @@ fn visit_expr(&mut self, expr: &'tcx hir::Expr) {
     // we prohibit access to private statics from other crates, this allows to give
     // more code internal visibility at link time. (Access to private functions
     // is already prohibited by type privacy for function types.)
-    fn visit_qpath(&mut self, qpath: &'tcx hir::QPath, id: ast::NodeId, span: Span) {
+    fn visit_qpath(&mut self, qpath: &'tcx hir::QPath, id: hir::HirId, span: Span) {
         let def = match *qpath {
             hir::QPath::Resolved(_, ref path) => match path.def {
                 Def::Method(..) | Def::AssociatedConst(..) |
@@ -823,8 +823,7 @@ fn visit_qpath(&mut self, qpath: &'tcx hir::QPath, id: ast::NodeId, span: Span)
                 _ => None,
             }
             hir::QPath::TypeRelative(..) => {
-                let hir_id = self.tcx.hir.node_to_hir_id(id);
-                self.tables.type_dependent_defs().get(hir_id).cloned()
+                self.tables.type_dependent_defs().get(id).cloned()
             }
         };
         if let Some(def) = def {
index 4390a31d3e33f84111b207ee3ab6e1e6741e0c15..5fd0b88870736c0d82d0a265458d1a0d7deec4ad 100644 (file)
@@ -126,6 +126,7 @@ fn get_auto_trait_impl_for<F>(
             let trait_ = hir::TraitRef {
                 path: get_path_for_type(self.cx.tcx, trait_def_id, hir::def::Def::Trait),
                 ref_id: ast::DUMMY_NODE_ID,
+                hir_ref_id: hir::DUMMY_HIR_ID,
             };
 
             let polarity;
index 5b352ffb725d0cc03eb3ae1dc731bc2f8cc82861..83e0827340dafbb3e4fa9fe5a1af05d1c65be175 100644 (file)
@@ -119,6 +119,7 @@ pub fn get_blanket_impls<F>(
                                                         trait_def_id,
                                                         hir::def::Def::Trait),
                                 ref_id: ast::DUMMY_NODE_ID,
+                                hir_ref_id: hir::DUMMY_HIR_ID,
                             };
                             let provided_trait_methods =
                                 infcx.tcx.provided_trait_methods(trait_def_id)