Skip to content

Commit 18e7a1b

Browse files
committed
Add Res::ns() instead of matches_ns()
1 parent c35007d commit 18e7a1b

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/librustc_ast_lowering/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1145,7 +1145,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
11451145
if let TyKind::Path(ref qself, ref path) = ty.kind {
11461146
if let Some(partial_res) = self.resolver.get_partial_res(ty.id) {
11471147
let res = partial_res.base_res();
1148-
if !res.matches_ns(Namespace::TypeNS) {
1148+
if res.ns().map(|ns| ns != Namespace::TypeNS).unwrap_or(false) {
11491149
debug!(
11501150
"lower_generic_arg: Lowering type argument as const argument: {:?}",
11511151
ty,

src/librustc_hir/def.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -451,13 +451,14 @@ impl<Id> Res<Id> {
451451
}
452452
}
453453

454-
pub fn matches_ns(&self, ns: Namespace) -> bool {
454+
/// Returns `None` if this is `Res::Err`
455+
pub fn ns(&self) -> Option<Namespace> {
455456
match self {
456-
Res::Def(kind, ..) => kind.ns() == Some(ns),
457-
Res::PrimTy(..) | Res::SelfTy(..) | Res::ToolMod => ns == Namespace::TypeNS,
458-
Res::SelfCtor(..) | Res::Local(..) => ns == Namespace::ValueNS,
459-
Res::NonMacroAttr(..) => ns == Namespace::MacroNS,
460-
Res::Err => true,
457+
Res::Def(kind, ..) => kind.ns(),
458+
Res::PrimTy(..) | Res::SelfTy(..) | Res::ToolMod => Some(Namespace::TypeNS),
459+
Res::SelfCtor(..) | Res::Local(..) => Some(Namespace::ValueNS),
460+
Res::NonMacroAttr(..) => Some(Namespace::MacroNS),
461+
Res::Err => None,
461462
}
462463
}
463464
}

0 commit comments

Comments
 (0)