Skip to content

Commit 1556320

Browse files
committed
Auto merge of #143458 - petrochenkov:bindnomod, r=<try>
resolve: Merge `NameBindingKind::Module` into `NameBindingKind::Res` This is a simplification, but also an optimization, because now we load modules from external crates in a more lazy fashion.
2 parents 6dec76f + e33d621 commit 1556320

File tree

13 files changed

+185
-231
lines changed

13 files changed

+185
-231
lines changed

compiler/rustc_hir/src/def.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,12 @@ impl DefKind {
295295
}
296296
}
297297

298+
/// This is a "module" in name resolution sense.
299+
#[inline]
300+
pub fn is_module_like(self) -> bool {
301+
matches!(self, DefKind::Mod | DefKind::Enum | DefKind::Trait)
302+
}
303+
298304
#[inline]
299305
pub fn is_fn_like(self) -> bool {
300306
matches!(
@@ -720,6 +726,15 @@ impl<Id> Res<Id> {
720726
}
721727
}
722728

729+
/// If this is a "module" in name resolution sense, return its `DefId`.
730+
#[inline]
731+
pub fn module_like_def_id(&self) -> Option<DefId> {
732+
match self {
733+
Res::Def(def_kind, def_id) if def_kind.is_module_like() => Some(*def_id),
734+
_ => None,
735+
}
736+
}
737+
723738
/// A human readable name for the res kind ("function", "module", etc.).
724739
pub fn descr(&self) -> &'static str {
725740
match *self {

compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::mem;
33
use std::sync::Arc;
44

55
use rustc_attr_data_structures::Deprecation;
6-
use rustc_hir::def::{CtorKind, DefKind, Res};
6+
use rustc_hir::def::{CtorKind, DefKind};
77
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LOCAL_CRATE};
88
use rustc_hir::definitions::{DefKey, DefPath, DefPathHash};
99
use rustc_middle::arena::ArenaAllocatable;
@@ -510,10 +510,7 @@ pub(in crate::rmeta) fn provide(providers: &mut Providers) {
510510
}
511511
Entry::Vacant(entry) => {
512512
entry.insert(parent);
513-
if matches!(
514-
child.res,
515-
Res::Def(DefKind::Mod | DefKind::Enum | DefKind::Trait, _)
516-
) {
513+
if child.res.module_like_def_id().is_some() {
517514
bfs_queue.push_back(def_id);
518515
}
519516
}

compiler/rustc_middle/src/ty/print/pretty.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3453,9 +3453,7 @@ fn for_each_def(tcx: TyCtxt<'_>, mut collect_fn: impl for<'b> FnMut(&'b Ident, N
34533453
collect_fn(&child.ident, ns, def_id);
34543454
}
34553455

3456-
if matches!(defkind, DefKind::Mod | DefKind::Enum | DefKind::Trait)
3457-
&& seen_defs.insert(def_id)
3458-
{
3456+
if defkind.is_module_like() && seen_defs.insert(def_id) {
34593457
queue.push(def_id);
34603458
}
34613459
}

0 commit comments

Comments
 (0)