]> git.lizzy.rs Git - rust.git/commitdiff
Allow `hir().find` to return `None`
authorJohn Kåre Alsaker <john.kare.alsaker@gmail.com>
Mon, 16 Mar 2020 18:17:40 +0000 (19:17 +0100)
committerMarkus Westerlind <markus.westerlind@distilnetworks.com>
Tue, 5 May 2020 08:03:13 +0000 (10:03 +0200)
src/librustc_middle/hir/map/mod.rs
src/librustc_middle/hir/mod.rs
src/librustc_middle/query/mod.rs
src/test/ui/issues/issue-70041.rs

index 1c71fc57bea5a23effe7bd60521ebb80572456c0..971bfd0281eb5210bdeabe764ca062f2af78d3b4 100644 (file)
@@ -311,19 +311,16 @@ pub fn def_kind(&self, local_def_id: LocalDefId) -> DefKind {
     }
 
     fn find_entry(&self, id: HirId) -> Option<Entry<'hir>> {
-        if id.local_id == ItemLocalId::from_u32(0) {
-            let owner = self.tcx.hir_owner(id.owner);
+        if id.local_id == ItemLocalId::from_u32_const(0) {
+            let owner = self.tcx.hir_owner(id.owner_def_id());
             owner.map(|owner| Entry { parent: owner.parent, node: owner.node })
         } else {
-            let owner = self.tcx.hir_owner_nodes(id.owner);
+            let owner = self.tcx.hir_owner_items(id.owner_def_id());
             owner.and_then(|owner| {
-                let node = owner.nodes[id.local_id].as_ref();
-                // FIXME(eddyb) use a single generic type insted of having both
-                // `Entry` and `ParentedNode`, which are effectively the same.
-                // Alternatively, rewrite code using `Entry` to use `ParentedNode`.
-                node.map(|node| Entry {
-                    parent: HirId { owner: id.owner, local_id: node.parent },
-                    node: node.node,
+                let item = owner.items[id.local_id].as_ref();
+                item.map(|item| Entry {
+                    parent: HirId { owner: id.owner, local_id: item.parent },
+                    node: item.node,
                 })
             })
         }
@@ -355,7 +352,12 @@ pub fn impl_item(&self, id: ImplItemId) -> &'hir ImplItem<'hir> {
     }
 
     pub fn body(&self, id: BodyId) -> &'hir Body<'hir> {
-        self.tcx.hir_owner_nodes(id.hir_id.owner).unwrap().bodies.get(&id.hir_id.local_id).unwrap()
+        self.tcx
+            .hir_owner_items(DefId::local(id.hir_id.owner))
+            .unwrap()
+            .bodies
+            .get(&id.hir_id.local_id)
+            .unwrap()
     }
 
     pub fn fn_decl_by_hir_id(&self, hir_id: HirId) -> Option<&'hir FnDecl<'hir>> {
index 7ab66411b21093ab18d14deb91c7456407709e9c..3d84bbd7062f0a34baf62c1198f326ebaac7ab0e 100644 (file)
@@ -77,8 +77,8 @@ pub fn provide(providers: &mut Providers<'_>) {
         let module = hir.as_local_hir_id(id);
         &tcx.untracked_crate.modules[&module]
     };
-    providers.hir_owner = |tcx, id| tcx.index_hir(LOCAL_CRATE).map[id].signature;
-    providers.hir_owner_nodes =
-        |tcx, id| tcx.index_hir(LOCAL_CRATE).map[id].with_bodies.as_ref().map(|nodes| &**nodes);
+    providers.hir_owner = |tcx, id| tcx.index_hir(id.krate).map[id.index].signature;
+    providers.hir_owner_items =
+        |tcx, id| tcx.index_hir(id.krate).map[id.index].with_bodies.as_ref().map(|items| &**items);
     map::provide(providers);
 }
index b0c442381484c11f244206e628856ecd234bad7b..8c437ca6907702167c466df53168ea9f93ad670a 100644 (file)
@@ -75,7 +75,7 @@ fn describe_as_module(def_id: DefId, tcx: TyCtxt<'_>) -> String {
         //
         // This can be conveniently accessed by methods on `tcx.hir()`.
         // Avoid calling this query directly.
-        query hir_owner(key: LocalDefId) -> Option<&'tcx crate::hir::Owner<'tcx>> {
+        query hir_owner(key: DefId) -> Option<&'tcx HirOwner<'tcx>> {
             eval_always
             desc { |tcx| "HIR owner of `{}`", tcx.def_path_str(key.to_def_id()) }
         }
@@ -84,7 +84,7 @@ fn describe_as_module(def_id: DefId, tcx: TyCtxt<'_>) -> String {
         //
         // This can be conveniently accessed by methods on `tcx.hir()`.
         // Avoid calling this query directly.
-        query hir_owner_nodes(key: LocalDefId) -> Option<&'tcx crate::hir::OwnerNodes<'tcx>> {
+        query hir_owner_items(key: DefId) -> Option<&'tcx HirOwnerItems<'tcx>> {
             eval_always
             desc { |tcx| "HIR owner items in `{}`", tcx.def_path_str(key.to_def_id()) }
         }
index 22e42295eedf302a992441e24eb303f17c838c92..e45e16418e144162875d279bb5aa6e58bbb7ca6e 100644 (file)
@@ -2,12 +2,10 @@
 // run-pass
 
 macro_rules! regex {
-    //~^ WARN unused macro definition
     () => {};
 }
 
 #[allow(dead_code)]
 use regex;
-//~^ WARN unused import
 
 fn main() {}