Skip to content

Commit 1782736

Browse files
authored
Unrolled build for #149681
Rollup merge of #149681 - petrochenkov:openapi1, r=davidtwco resolve: Split `Scope::Module` into two scopes for non-glob and glob bindings This is a re-implementation of #144131 with all the issues mentioned there fixed. As it turned out, the non-trivial part of the split was already done in c91b6ca, so the remaining part implemented in this PR is *mostly* mechanical. After addressing the issue of already found bindings being lost due to indeterminacies in outer scopes (7e890bf) and adding one missing `Stage::Late` in `Finalize` the scope splitting refactoring just worked. (One more ICE was revealed by the refactoring, but not caused by it, fixed up in the last commit.) This is a part of implementation for the [Open API](https://rust-lang.github.io/rust-project-goals/2025h1/open-namespaces.html) proposal.
2 parents e29fcf4 + 3f3db93 commit 1782736

15 files changed

Lines changed: 253 additions & 263 deletions

compiler/rustc_middle/src/metadata.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,9 @@ pub struct ModChild {
4545
pub reexport_chain: SmallVec<[Reexport; 2]>,
4646
}
4747

48-
#[derive(Debug, TyEncodable, TyDecodable, HashStable)]
49-
pub enum AmbigModChildKind {
50-
GlobVsGlob,
51-
GlobVsExpanded,
52-
}
53-
5448
/// Same as `ModChild`, however, it includes ambiguity error.
5549
#[derive(Debug, TyEncodable, TyDecodable, HashStable)]
5650
pub struct AmbigModChild {
5751
pub main: ModChild,
5852
pub second: ModChild,
59-
pub kind: AmbigModChildKind,
6053
}

compiler/rustc_resolve/src/build_reduced_graph.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use rustc_hir::def::{self, *};
2222
use rustc_hir::def_id::{CRATE_DEF_ID, DefId, LocalDefId};
2323
use rustc_index::bit_set::DenseBitSet;
2424
use rustc_metadata::creader::LoadedMacro;
25-
use rustc_middle::metadata::{AmbigModChildKind, ModChild, Reexport};
25+
use rustc_middle::metadata::{ModChild, Reexport};
2626
use rustc_middle::ty::{Feed, Visibility};
2727
use rustc_middle::{bug, span_bug};
2828
use rustc_span::hygiene::{ExpnId, LocalExpnId, MacroKind};
@@ -36,9 +36,9 @@ use crate::imports::{ImportData, ImportKind};
3636
use crate::macros::{MacroRulesBinding, MacroRulesScope, MacroRulesScopeRef};
3737
use crate::ref_mut::CmCell;
3838
use crate::{
39-
AmbiguityKind, BindingKey, ExternPreludeEntry, Finalize, MacroData, Module, ModuleKind,
40-
ModuleOrUniformRoot, NameBinding, NameBindingData, NameBindingKind, ParentScope, PathResult,
41-
ResolutionError, Resolver, Segment, Used, VisResolutionError, errors,
39+
BindingKey, ExternPreludeEntry, Finalize, MacroData, Module, ModuleKind, ModuleOrUniformRoot,
40+
NameBinding, NameBindingData, NameBindingKind, ParentScope, PathResult, ResolutionError,
41+
Resolver, Segment, Used, VisResolutionError, errors,
4242
};
4343

4444
type Res = def::Res<NodeId>;
@@ -82,7 +82,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
8282
vis: Visibility<DefId>,
8383
span: Span,
8484
expansion: LocalExpnId,
85-
ambiguity: Option<(NameBinding<'ra>, AmbiguityKind)>,
85+
ambiguity: Option<NameBinding<'ra>>,
8686
) {
8787
let binding = self.arenas.alloc_name_binding(NameBindingData {
8888
kind: NameBindingKind::Res(res),
@@ -254,7 +254,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
254254
&child.main,
255255
parent_scope,
256256
children.len() + i,
257-
Some((&child.second, child.kind)),
257+
Some(&child.second),
258258
)
259259
}
260260
}
@@ -265,7 +265,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
265265
child: &ModChild,
266266
parent_scope: ParentScope<'ra>,
267267
child_index: usize,
268-
ambig_child: Option<(&ModChild, AmbigModChildKind)>,
268+
ambig_child: Option<&ModChild>,
269269
) {
270270
let parent = parent_scope.module;
271271
let child_span = |this: &Self, reexport_chain: &[Reexport], res: def::Res<_>| {
@@ -280,15 +280,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
280280
let span = child_span(self, reexport_chain, res);
281281
let res = res.expect_non_local();
282282
let expansion = parent_scope.expansion;
283-
let ambig = ambig_child.map(|(ambig_child, ambig_kind)| {
283+
let ambig = ambig_child.map(|ambig_child| {
284284
let ModChild { ident: _, res, vis, ref reexport_chain } = *ambig_child;
285285
let span = child_span(self, reexport_chain, res);
286286
let res = res.expect_non_local();
287-
let ambig_kind = match ambig_kind {
288-
AmbigModChildKind::GlobVsGlob => AmbiguityKind::GlobVsGlob,
289-
AmbigModChildKind::GlobVsExpanded => AmbiguityKind::GlobVsExpanded,
290-
};
291-
(self.arenas.new_res_binding(res, vis, span, expansion), ambig_kind)
287+
self.arenas.new_res_binding(res, vis, span, expansion)
292288
});
293289

294290
// Record primary definitions.

compiler/rustc_resolve/src/diagnostics.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,9 +1206,12 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
12061206
}
12071207
}
12081208
}
1209-
Scope::Module(module, _) => {
1209+
Scope::ModuleNonGlobs(module, _) => {
12101210
this.add_module_candidates(module, suggestions, filter_fn, None);
12111211
}
1212+
Scope::ModuleGlobs(..) => {
1213+
// Already handled in `ModuleNonGlobs`.
1214+
}
12121215
Scope::MacroUsePrelude => {
12131216
suggestions.extend(this.macro_use_prelude.iter().filter_map(
12141217
|(name, binding)| {
@@ -2033,7 +2036,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
20332036
help_msgs.push(format!("use `::{ident}` to refer to this {thing} unambiguously"))
20342037
}
20352038

2036-
if let Scope::Module(module, _) = scope {
2039+
if let Scope::ModuleNonGlobs(module, _) | Scope::ModuleGlobs(module, _) = scope {
20372040
if module == self.graph_root {
20382041
help_msgs.push(format!(
20392042
"use `crate::{ident}` to refer to this {thing} unambiguously"

0 commit comments

Comments
 (0)