Skip to content

Commit

Permalink
Add Res::ns() instead of matches_ns()
Browse files Browse the repository at this point in the history
  • Loading branch information
jyn514 committed Aug 25, 2020
1 parent c35007d commit 18e7a1b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/librustc_ast_lowering/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 7 additions & 6 deletions src/librustc_hir/def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
}

0 comments on commit 18e7a1b

Please sign in to comment.