Skip to content

resolve: Merge NameBindingKind::Module into NameBindingKind::Res #143458

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions compiler/rustc_hir/src/def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,12 @@ impl DefKind {
}
}

/// This is a "module" in name resolution sense.
#[inline]
pub fn is_module_like(self) -> bool {
matches!(self, DefKind::Mod | DefKind::Enum | DefKind::Trait)
}

#[inline]
pub fn is_fn_like(self) -> bool {
matches!(
Expand Down Expand Up @@ -720,6 +726,15 @@ impl<Id> Res<Id> {
}
}

/// If this is a "module" in name resolution sense, return its `DefId`.
#[inline]
pub fn module_like_def_id(&self) -> Option<DefId> {
match self {
Res::Def(def_kind, def_id) if def_kind.is_module_like() => Some(*def_id),
_ => None,
}
}

/// A human readable name for the res kind ("function", "module", etc.).
pub fn descr(&self) -> &'static str {
match *self {
Expand Down
7 changes: 2 additions & 5 deletions compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::mem;
use std::sync::Arc;

use rustc_attr_data_structures::Deprecation;
use rustc_hir::def::{CtorKind, DefKind, Res};
use rustc_hir::def::{CtorKind, DefKind};
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LOCAL_CRATE};
use rustc_hir::definitions::{DefKey, DefPath, DefPathHash};
use rustc_middle::arena::ArenaAllocatable;
Expand Down Expand Up @@ -510,10 +510,7 @@ pub(in crate::rmeta) fn provide(providers: &mut Providers) {
}
Entry::Vacant(entry) => {
entry.insert(parent);
if matches!(
child.res,
Res::Def(DefKind::Mod | DefKind::Enum | DefKind::Trait, _)
) {
if child.res.module_like_def_id().is_some() {
bfs_queue.push_back(def_id);
}
}
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_middle/src/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3453,9 +3453,7 @@ fn for_each_def(tcx: TyCtxt<'_>, mut collect_fn: impl for<'b> FnMut(&'b Ident, N
collect_fn(&child.ident, ns, def_id);
}

if matches!(defkind, DefKind::Mod | DefKind::Enum | DefKind::Trait)
&& seen_defs.insert(def_id)
{
if defkind.is_module_like() && seen_defs.insert(def_id) {
queue.push(def_id);
}
}
Expand Down
Loading
Loading