diff options
Diffstat (limited to 'compiler/rustc_hir')
| -rw-r--r-- | compiler/rustc_hir/src/arena.rs | 1 | ||||
| -rw-r--r-- | compiler/rustc_hir/src/def.rs | 12 | ||||
| -rw-r--r-- | compiler/rustc_hir/src/hir.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_hir/src/intravisit.rs | 2 |
4 files changed, 14 insertions, 5 deletions
diff --git a/compiler/rustc_hir/src/arena.rs b/compiler/rustc_hir/src/arena.rs index 88c0d223fd3..b0dff635a9b 100644 --- a/compiler/rustc_hir/src/arena.rs +++ b/compiler/rustc_hir/src/arena.rs @@ -8,7 +8,6 @@ macro_rules! arena_types { [] asm_template: rustc_ast::InlineAsmTemplatePiece, [] attribute: rustc_hir::Attribute, [] owner_info: rustc_hir::OwnerInfo<'tcx>, - [] use_path: rustc_hir::UsePath<'tcx>, [] lit: rustc_hir::Lit, [] macro_def: rustc_ast::MacroDef, ]); diff --git a/compiler/rustc_hir/src/def.rs b/compiler/rustc_hir/src/def.rs index 507c94aca8b..98ec1ccd6ba 100644 --- a/compiler/rustc_hir/src/def.rs +++ b/compiler/rustc_hir/src/def.rs @@ -584,7 +584,7 @@ impl<CTX: crate::HashStableContext> ToStableHashKey<CTX> for Namespace { } /// Just a helper ‒ separate structure for each namespace. -#[derive(Copy, Clone, Default, Debug)] +#[derive(Copy, Clone, Default, Debug, HashStable_Generic)] pub struct PerNS<T> { pub value_ns: T, pub type_ns: T, @@ -596,10 +596,16 @@ impl<T> PerNS<T> { PerNS { value_ns: f(self.value_ns), type_ns: f(self.type_ns), macro_ns: f(self.macro_ns) } } + /// Note: Do you really want to use this? Often you know which namespace a + /// name will belong in, and you can consider just that namespace directly, + /// rather than iterating through all of them. pub fn into_iter(self) -> IntoIter<T, 3> { [self.value_ns, self.type_ns, self.macro_ns].into_iter() } + /// Note: Do you really want to use this? Often you know which namespace a + /// name will belong in, and you can consider just that namespace directly, + /// rather than iterating through all of them. pub fn iter(&self) -> IntoIter<&T, 3> { [&self.value_ns, &self.type_ns, &self.macro_ns].into_iter() } @@ -634,6 +640,10 @@ impl<T> PerNS<Option<T>> { } /// Returns an iterator over the items which are `Some`. + /// + /// Note: Do you really want to use this? Often you know which namespace a + /// name will belong in, and you can consider just that namespace directly, + /// rather than iterating through all of them. pub fn present_items(self) -> impl Iterator<Item = T> { [self.type_ns, self.value_ns, self.macro_ns].into_iter().flatten() } diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index b4fcc16c09c..e440324d7d0 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -30,7 +30,7 @@ use thin_vec::ThinVec; use tracing::debug; use crate::LangItem; -use crate::def::{CtorKind, DefKind, Res}; +use crate::def::{CtorKind, DefKind, PerNS, Res}; use crate::def_id::{DefId, LocalDefIdMap}; pub(crate) use crate::hir_id::{HirId, ItemLocalId, ItemLocalMap, OwnerId}; use crate::intravisit::{FnKind, VisitorExt}; @@ -347,7 +347,7 @@ pub struct Path<'hir, R = Res> { } /// Up to three resolutions for type, value and macro namespaces. -pub type UsePath<'hir> = Path<'hir, SmallVec<[Res; 3]>>; +pub type UsePath<'hir> = Path<'hir, PerNS<Option<Res>>>; impl Path<'_> { pub fn is_global(&self) -> bool { diff --git a/compiler/rustc_hir/src/intravisit.rs b/compiler/rustc_hir/src/intravisit.rs index 1fd44e44b9c..b6ebd61301c 100644 --- a/compiler/rustc_hir/src/intravisit.rs +++ b/compiler/rustc_hir/src/intravisit.rs @@ -1148,7 +1148,7 @@ pub fn walk_use<'v, V: Visitor<'v>>( hir_id: HirId, ) -> V::Result { let UsePath { segments, ref res, span } = *path; - for &res in res { + for res in res.present_items() { try_visit!(visitor.visit_path(&Path { segments, res, span }, hir_id)); } V::Result::output() |
