diff --git a/src/librustc_ast_lowering/lib.rs b/src/librustc_ast_lowering/lib.rs index 586355fe6136..d61db171aa22 100644 --- a/src/librustc_ast_lowering/lib.rs +++ b/src/librustc_ast_lowering/lib.rs @@ -1145,7 +1145,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { if let TyKind::Path(ref qself, ref path) = ty.kind { if let Some(partial_res) = self.resolver.get_partial_res(ty.id) { let res = partial_res.base_res(); - if !res.matches_ns(Namespace::TypeNS) { + if res.ns().map(|ns| ns != Namespace::TypeNS).unwrap_or(false) { debug!( "lower_generic_arg: Lowering type argument as const argument: {:?}", ty, diff --git a/src/librustc_hir/def.rs b/src/librustc_hir/def.rs index fb7fced27c28..67f20aa848f1 100644 --- a/src/librustc_hir/def.rs +++ b/src/librustc_hir/def.rs @@ -451,13 +451,14 @@ impl Res { } } - pub fn matches_ns(&self, ns: Namespace) -> bool { + /// Returns `None` if this is `Res::Err` + pub fn ns(&self) -> Option { match self { - Res::Def(kind, ..) => kind.ns() == Some(ns), - Res::PrimTy(..) | Res::SelfTy(..) | Res::ToolMod => ns == Namespace::TypeNS, - Res::SelfCtor(..) | Res::Local(..) => ns == Namespace::ValueNS, - Res::NonMacroAttr(..) => ns == Namespace::MacroNS, - Res::Err => true, + Res::Def(kind, ..) => kind.ns(), + Res::PrimTy(..) | Res::SelfTy(..) | Res::ToolMod => Some(Namespace::TypeNS), + Res::SelfCtor(..) | Res::Local(..) => Some(Namespace::ValueNS), + Res::NonMacroAttr(..) => Some(Namespace::MacroNS), + Res::Err => None, } } }