Skip to content

Commit 61621e2

Browse files
ZoxcMarkus Westerlind
authored andcommitted
Allow hir().find to return None
1 parent 04689e2 commit 61621e2

File tree

4 files changed

+18
-18
lines changed

4 files changed

+18
-18
lines changed

src/librustc_middle/hir/map/mod.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -311,19 +311,16 @@ impl<'hir> Map<'hir> {
311311
}
312312

313313
fn find_entry(&self, id: HirId) -> Option<Entry<'hir>> {
314-
if id.local_id == ItemLocalId::from_u32(0) {
315-
let owner = self.tcx.hir_owner(id.owner);
314+
if id.local_id == ItemLocalId::from_u32_const(0) {
315+
let owner = self.tcx.hir_owner(id.owner_def_id());
316316
owner.map(|owner| Entry { parent: owner.parent, node: owner.node })
317317
} else {
318-
let owner = self.tcx.hir_owner_nodes(id.owner);
318+
let owner = self.tcx.hir_owner_items(id.owner_def_id());
319319
owner.and_then(|owner| {
320-
let node = owner.nodes[id.local_id].as_ref();
321-
// FIXME(eddyb) use a single generic type insted of having both
322-
// `Entry` and `ParentedNode`, which are effectively the same.
323-
// Alternatively, rewrite code using `Entry` to use `ParentedNode`.
324-
node.map(|node| Entry {
325-
parent: HirId { owner: id.owner, local_id: node.parent },
326-
node: node.node,
320+
let item = owner.items[id.local_id].as_ref();
321+
item.map(|item| Entry {
322+
parent: HirId { owner: id.owner, local_id: item.parent },
323+
node: item.node,
327324
})
328325
})
329326
}
@@ -355,7 +352,12 @@ impl<'hir> Map<'hir> {
355352
}
356353

357354
pub fn body(&self, id: BodyId) -> &'hir Body<'hir> {
358-
self.tcx.hir_owner_nodes(id.hir_id.owner).unwrap().bodies.get(&id.hir_id.local_id).unwrap()
355+
self.tcx
356+
.hir_owner_items(DefId::local(id.hir_id.owner))
357+
.unwrap()
358+
.bodies
359+
.get(&id.hir_id.local_id)
360+
.unwrap()
359361
}
360362

361363
pub fn fn_decl_by_hir_id(&self, hir_id: HirId) -> Option<&'hir FnDecl<'hir>> {

src/librustc_middle/hir/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ pub fn provide(providers: &mut Providers<'_>) {
7777
let module = hir.as_local_hir_id(id);
7878
&tcx.untracked_crate.modules[&module]
7979
};
80-
providers.hir_owner = |tcx, id| tcx.index_hir(LOCAL_CRATE).map[id].signature;
81-
providers.hir_owner_nodes =
82-
|tcx, id| tcx.index_hir(LOCAL_CRATE).map[id].with_bodies.as_ref().map(|nodes| &**nodes);
80+
providers.hir_owner = |tcx, id| tcx.index_hir(id.krate).map[id.index].signature;
81+
providers.hir_owner_items =
82+
|tcx, id| tcx.index_hir(id.krate).map[id.index].with_bodies.as_ref().map(|items| &**items);
8383
map::provide(providers);
8484
}

src/librustc_middle/query/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ rustc_queries! {
7575
//
7676
// This can be conveniently accessed by methods on `tcx.hir()`.
7777
// Avoid calling this query directly.
78-
query hir_owner(key: LocalDefId) -> Option<&'tcx crate::hir::Owner<'tcx>> {
78+
query hir_owner(key: DefId) -> Option<&'tcx HirOwner<'tcx>> {
7979
eval_always
8080
desc { |tcx| "HIR owner of `{}`", tcx.def_path_str(key.to_def_id()) }
8181
}
@@ -84,7 +84,7 @@ rustc_queries! {
8484
//
8585
// This can be conveniently accessed by methods on `tcx.hir()`.
8686
// Avoid calling this query directly.
87-
query hir_owner_nodes(key: LocalDefId) -> Option<&'tcx crate::hir::OwnerNodes<'tcx>> {
87+
query hir_owner_items(key: DefId) -> Option<&'tcx HirOwnerItems<'tcx>> {
8888
eval_always
8989
desc { |tcx| "HIR owner items in `{}`", tcx.def_path_str(key.to_def_id()) }
9090
}

src/test/ui/issues/issue-70041.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22
// run-pass
33

44
macro_rules! regex {
5-
//~^ WARN unused macro definition
65
() => {};
76
}
87

98
#[allow(dead_code)]
109
use regex;
11-
//~^ WARN unused import
1210

1311
fn main() {}

0 commit comments

Comments
 (0)