]> git.lizzy.rs Git - rust.git/commitdiff
Add back `Res::matches_ns`, implemented in terms of `ns`
authorJoshua Nelson <jyn514@gmail.com>
Tue, 25 Aug 2020 20:45:12 +0000 (16:45 -0400)
committerJoshua Nelson <jyn514@gmail.com>
Tue, 25 Aug 2020 20:45:12 +0000 (16:45 -0400)
src/librustc_ast_lowering/lib.rs
src/librustc_hir/def.rs

index d61db171aa225474a97dbf17e971447a497bc3de..586355fe6136e9a62fb1000e5de12d2c70549941 100644 (file)
@@ -1145,7 +1145,7 @@ fn lower_generic_arg(
                 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.ns().map(|ns| ns != Namespace::TypeNS).unwrap_or(false) {
+                        if !res.matches_ns(Namespace::TypeNS) {
                             debug!(
                                 "lower_generic_arg: Lowering type argument as const argument: {:?}",
                                 ty,
index 67f20aa848f13b328636f76da4e7fa07fcbd7954..72310061d5cb5de1efb52b1971e149fe38ed1825 100644 (file)
@@ -461,4 +461,9 @@ pub fn ns(&self) -> Option<Namespace> {
             Res::Err => None,
         }
     }
+
+    /// Always returns `true` if `self` is `Res::Err`
+    pub fn matches_ns(&self, ns: Namespace) -> bool {
+        self.ns().map(|actual_ns| actual_ns == ns).unwrap_or(true)
+    }
 }