Skip to content

Commit c5ecb0c

Browse files
committed
address review
1 parent 5d10d90 commit c5ecb0c

File tree

7 files changed

+15
-21
lines changed

7 files changed

+15
-21
lines changed

compiler/rustc_hir/src/def.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ pub enum Res<Id = hir::HirId> {
590590
/// **Belongs to the type namespace.**
591591
ToolMod,
592592

593-
/// The resolution for a virtual module in a namespaced crate. E.g. `my_api`
593+
/// The resolution for an open module in a namespaced crate. E.g. `my_api`
594594
/// in the namespaced crate `my_api::utils` when `my_api` isn't part of the
595595
/// extern prelude.
596596
///

compiler/rustc_resolve/src/diagnostics.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1737,7 +1737,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
17371737
format!("{} {}", kinds.article(), kinds.descr())
17381738
}
17391739
Res::ToolMod | Res::OpenMod(..) => {
1740-
// Don't confuse the user with tool modules or virtual modules.
1740+
// Don't confuse the user with tool modules or open modules.
17411741
continue;
17421742
}
17431743
Res::Def(DefKind::Trait, _) if macro_kind == MacroKind::Derive => {
@@ -1968,7 +1968,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
19681968
true
19691969
}
19701970

1971-
#[instrument(skip(self), level = "debug")]
19721971
fn decl_description(&self, b: Decl<'_>, ident: Ident, scope: Scope<'_>) -> String {
19731972
let res = b.res();
19741973
if b.span.is_dummy() || !self.tcx.sess.source_map().is_span_accessible(b.span) {

compiler/rustc_resolve/src/ident.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
479479
}
480480
Err(determinacy) => Err(determinacy.into_value()),
481481
};
482-
483482
match res {
484483
Ok(decl) if sub_namespace_match(decl.macro_kinds(), macro_kind) => {
485484
// Below we report various ambiguity errors.

compiler/rustc_resolve/src/lib.rs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ use rustc_session::lint::builtin::PRIVATE_MACRO_USE;
7777
use rustc_span::hygiene::{ExpnId, LocalExpnId, MacroKind, SyntaxContext, Transparency};
7878
use rustc_span::{DUMMY_SP, Ident, Span, Symbol, kw, sym};
7979
use smallvec::{SmallVec, smallvec};
80-
use tracing::{debug, instrument};
80+
use tracing::debug;
8181

8282
type Res = def::Res<NodeId>;
8383

@@ -1125,7 +1125,7 @@ struct ExternPreludeEntry<'ra> {
11251125
CacheCell<(
11261126
PendingDecl<'ra>,
11271127
/* finalized */ bool,
1128-
/* virtual flag (namespaced crate) */ bool,
1128+
/* open flag (namespaced crate) */ bool,
11291129
)>,
11301130
>,
11311131
}
@@ -1142,7 +1142,7 @@ impl ExternPreludeEntry<'_> {
11421142
}
11431143
}
11441144

1145-
fn virtual_flag() -> Self {
1145+
fn open_flag() -> Self {
11461146
ExternPreludeEntry {
11471147
item_decl: None,
11481148
flag_decl: Some(CacheCell::new((PendingDecl::Pending, false, true))),
@@ -2304,7 +2304,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
23042304
})
23052305
}
23062306

2307-
#[instrument(skip(self), level = "debug")]
23082307
fn extern_prelude_get_flag(
23092308
&self,
23102309
ident: IdentKey,
@@ -2313,11 +2312,10 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
23132312
) -> Option<Decl<'ra>> {
23142313
let entry = self.extern_prelude.get(&ident);
23152314
entry.and_then(|entry| entry.flag_decl.as_ref()).and_then(|flag_decl| {
2316-
let (pending_decl, finalized, is_virtual) = flag_decl.get();
2317-
debug!(?pending_decl, ?is_virtual);
2315+
let (pending_decl, finalized, is_open) = flag_decl.get();
23182316
let decl = match pending_decl {
23192317
PendingDecl::Ready(decl) => {
2320-
if finalize && !finalized && !is_virtual {
2318+
if finalize && !finalized && !is_open {
23212319
self.cstore_mut().process_path_extern(
23222320
self.tcx,
23232321
ident.name,
@@ -2328,7 +2326,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
23282326
}
23292327
PendingDecl::Pending => {
23302328
debug_assert!(!finalized);
2331-
if is_virtual {
2329+
if is_open {
23322330
let res = Res::OpenMod(ident.name);
23332331
Some(self.arenas.new_pub_def_decl(res, DUMMY_SP, LocalExpnId::ROOT))
23342332
} else {
@@ -2349,7 +2347,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
23492347
}
23502348
}
23512349
};
2352-
flag_decl.set((PendingDecl::Ready(decl), finalize || finalized, is_virtual));
2350+
flag_decl.set((PendingDecl::Ready(decl), finalize || finalized, is_open));
23532351
decl.or_else(|| finalize.then_some(self.dummy_decl))
23542352
})
23552353
}
@@ -2535,12 +2533,12 @@ fn build_extern_prelude<'tcx, 'ra>(
25352533
})
25362534
.collect();
25372535

2538-
// Add virtual base entries for namespaced crates whose base segment
2536+
// Add open base entries for namespaced crates whose base segment
25392537
// is missing from the prelude (e.g. `foo::bar` without `foo`).
25402538
// These are necessary in order to resolve the open modules, whereas
25412539
// the namespaced names are necessary in `extern_prelude` for actually
25422540
// resolving the namespaced crates.
2543-
let missing_virtual_bases: Vec<IdentKey> = extern_prelude
2541+
let missing_open_bases: Vec<IdentKey> = extern_prelude
25442542
.keys()
25452543
.filter_map(|ident| {
25462544
let (base, _) = ident.name.as_str().split_once("::")?;
@@ -2551,11 +2549,9 @@ fn build_extern_prelude<'tcx, 'ra>(
25512549
.collect();
25522550

25532551
extern_prelude.extend(
2554-
missing_virtual_bases.into_iter().map(|ident| (ident, ExternPreludeEntry::virtual_flag())),
2552+
missing_open_bases.into_iter().map(|ident| (ident, ExternPreludeEntry::open_flag())),
25552553
);
25562554

2557-
debug!(?extern_prelude);
2558-
25592555
// Inject `core` / `std` unless suppressed by attributes.
25602556
if !attr::contains_name(attrs, sym::no_core) {
25612557
extern_prelude.insert(IdentKey::with_root_ctxt(sym::core), ExternPreludeEntry::flag());

tests/ui/resolve/open-ns-1.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use my_api::root_function;
88
use my_api::utils::util;
9-
//~^ ERROR E0432
9+
//~^ ERROR unresolved import `my_api::utils`
1010

1111
fn main() {
1212
let _ = root_function();

tests/ui/resolve/open-ns-11.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Tests that namespaced crate names are limited to two segments
1+
// Tests that std has higher precedence than an open module with the same name.
22

33
//@ aux-crate: std::utils=open-ns-my_api_utils.rs
44
//@ compile-flags: -Z namespaced-crates

tests/ui/resolve/open-ns-6.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Tests that virtual modules are resolvable.
1+
// Tests that open modules are resolvable.
22

33
//@ aux-crate: my_api::utils=open-ns-my_api_utils.rs
44
//@ compile-flags: -Z namespaced-crates

0 commit comments

Comments
 (0)