about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJoshua Nelson <jyn514@gmail.com>2020-08-25 14:16:05 -0400
committerJoshua Nelson <jyn514@gmail.com>2020-08-25 14:16:05 -0400
commit18e7a1b799517790b8702aae11fecb1743918352 (patch)
tree02a9876ca85b0d9caeccd30dbb93536ac36059b1
parentc35007dbbe4846c641b5edad9fddf3f72a5a035a (diff)
downloadrust-18e7a1b799517790b8702aae11fecb1743918352.tar.gz
rust-18e7a1b799517790b8702aae11fecb1743918352.zip
Add `Res::ns()` instead of `matches_ns()`
-rw-r--r--src/librustc_ast_lowering/lib.rs2
-rw-r--r--src/librustc_hir/def.rs13
2 files changed, 8 insertions, 7 deletions
diff --git a/src/librustc_ast_lowering/lib.rs b/src/librustc_ast_lowering/lib.rs
index 586355fe613..d61db171aa2 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 fb7fced27c2..67f20aa848f 100644
--- a/src/librustc_hir/def.rs
+++ b/src/librustc_hir/def.rs
@@ -451,13 +451,14 @@ impl<Id> Res<Id> {
         }
     }
 
-    pub fn matches_ns(&self, ns: Namespace) -> bool {
+    /// Returns `None` if this is `Res::Err`
+    pub fn ns(&self) -> Option<Namespace> {
         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,
         }
     }
 }