resolve: Split `Scope::Module` into two scopes for non-glob and glob bindings
This is a re-implementation of https://github.com/rust-lang/rust/pull/144131 with all the issues mentioned there fixed.
As it turned out, the non-trivial part of the split was already done in https://github.com/rust-lang/rust/pull/149454/commits/c91b6ca58d4d870d3099db1defbd8c1f26a7d851, 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 (https://github.com/rust-lang/rust/commit/7e890bfa879ec8a3e1beabee7e42f5491a3cc9b1) 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 proposal.
r? @davidtwco
rustbot has assigned @davidtwco. They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.
Use r? to explicitly pick a reviewer
There may be minor breakage in corner cases due to ambiguity checking being unified between in-scope resolution and in-module resolution, so this needs a crater run. @bors try
:hourglass: Trying commit fdaf0226fe2b52db72ddf20c7acb0b09a64a1540 with merge 588eab2606249d5c408b91089fa4eb676635d378…
To cancel the try build, run the command @bors try cancel.
Workflow: https://github.com/rust-lang/rust/actions/runs/19967170454
The job pr-check-1 failed! Check out the build log: (web) (plain enhanced) (plain)
Click to see the possible cause of the failure (guessed by this bot)
error[E0659]: `Path` is ambiguous
--> compiler/rustc_builtin_macros/src/deriving/generic/mod.rs:195:18
|
195 | use ty::{Bounds, Path, Ref, Self_, Ty};
| ^^^^ ambiguous name
|
= note: ambiguous because of a conflict between a macro-expanded name and a less macro-expanded name from outer scope during import or macro resolution
note: `Path` could refer to the struct defined here
--> compiler/rustc_builtin_macros/src/deriving/generic/ty.rs:14:1
|
The job dist-x86_64-linux failed! Check out the build log: (web) (plain enhanced) (plain)
Click to see the possible cause of the failure (guessed by this bot)
Finished `dev` profile [unoptimized + debuginfo] target(s) in 32.00s
##[endgroup]
[2025-12-05T15:22:28.177Z INFO opt_dist::timer] Section `Stage 1 (Rustc PGO)` starts
[2025-12-05T15:22:28.177Z INFO opt_dist::timer] Section `Stage 1 (Rustc PGO) > Build PGO instrumented rustc and LLVM` starts
[2025-12-05T15:22:28.177Z INFO opt_dist::exec] Executing `RUST_BACKTRACE=full python3 /checkout/x.py build --target x86_64-unknown-linux-gnu --host x86_64-unknown-linux-gnu --stage 2 library/std --set rust.llvm-bitcode-linker=false --set build.extended=false --set rust.codegen-backends=['llvm'] --set rust.deny-warnings=false --rust-profile-generate /tmp/tmp-multistage/opt-artifacts/rustc-pgo --set llvm.thin-lto=false --set llvm.link-shared=true [at /checkout/obj]`
##[group]Building bootstrap
Finished `dev` profile [unoptimized] target(s) in 0.06s
##[endgroup]
[TIMING:start] compile::Assemble { target_compiler: Compiler { stage: 2, host: x86_64-unknown-linux-gnu, forced_compiler: false } }
[TIMING:start] builder::Libdir { compiler: Compiler { stage: 2, host: x86_64-unknown-linux-gnu, forced_compiler: false }, target: x86_64-unknown-linux-gnu }
---
error[E0659]: `Path` is ambiguous
--> compiler/rustc_builtin_macros/src/deriving/generic/mod.rs:195:18
|
195 | use ty::{Bounds, Path, Ref, Self_, Ty};
| ^^^^ ambiguous name
|
= note: ambiguous because of a conflict between a macro-expanded name and a less macro-expanded name from outer scope during import or macro resolution
note: `Path` could refer to the struct defined here
--> compiler/rustc_builtin_macros/src/deriving/generic/ty.rs:14:1
|
---
[RUSTC-TIMING] rustc_attr_parsing test:false 18.610
[RUSTC-TIMING] rustc_expand test:false 24.635
[RUSTC-TIMING] rustc_parse test:false 42.354
[RUSTC-TIMING] rustc_middle test:false 70.778
Bootstrap failed while executing `build --target x86_64-unknown-linux-gnu --host x86_64-unknown-linux-gnu --stage 2 library/std --set rust.llvm-bitcode-linker=false --set build.extended=false --set rust.codegen-backends=['llvm'] --set rust.deny-warnings=false --rust-profile-generate /tmp/tmp-multistage/opt-artifacts/rustc-pgo --set llvm.thin-lto=false --set llvm.link-shared=true`
Build completed unsuccessfully in 0:12:07
[2025-12-05T15:34:35.668Z INFO opt_dist::timer] Section `Stage 1 (Rustc PGO) > Build PGO instrumented rustc and LLVM` ended: FAIL (727.49s)`
[2025-12-05T15:34:35.668Z INFO opt_dist::timer] Section `Stage 1 (Rustc PGO)` ended: FAIL (727.49s)`
[2025-12-05T15:34:35.668Z INFO opt_dist] Timer results
-----------------------------------------------------------------
---
[2025-12-05T15:34:35.668Z INFO opt_dist::utils] Free disk space: 1.24 TiB out of total 2.18 TiB (43.00% used)
Error: Optimized build pipeline has failed
Caused by:
Command RUST_BACKTRACE=full python3 /checkout/x.py build --target x86_64-unknown-linux-gnu --host x86_64-unknown-linux-gnu --stage 2 library/std --set rust.llvm-bitcode-linker=false --set build.extended=false --set rust.codegen-backends=['llvm'] --set rust.deny-warnings=false --rust-profile-generate /tmp/tmp-multistage/opt-artifacts/rustc-pgo --set llvm.thin-lto=false --set llvm.link-shared=true [at /checkout/obj] has failed with exit code Some(1)
Stack backtrace:
0: <anyhow::Error>::msg::<alloc::string::String>
at /rust/deps/anyhow-1.0.100/src/backtrace.rs:27:14
1: <opt_dist::exec::CmdBuilder>::run
at /rustc/588eab2606249d5c408b91089fa4eb676635d378/src/tools/opt-dist/src/exec.rs:80:17
2: <opt_dist::exec::Bootstrap>::run
at /rustc/588eab2606249d5c408b91089fa4eb676635d378/src/tools/opt-dist/src/exec.rs:199:18
3: opt_dist::execute_pipeline::{closure#1}::{closure#0}
at /rustc/588eab2606249d5c408b91089fa4eb676635d378/src/tools/opt-dist/src/main.rs:256:21
4: <opt_dist::timer::TimerSection>::section::<opt_dist::execute_pipeline::{closure#1}::{closure#0}, ()>
at /rustc/588eab2606249d5c408b91089fa4eb676635d378/src/tools/opt-dist/src/timer.rs:111:22
5: opt_dist::execute_pipeline::{closure#1}
at /rustc/588eab2606249d5c408b91089fa4eb676635d378/src/tools/opt-dist/src/main.rs:245:15
6: <opt_dist::timer::TimerSection>::section::<opt_dist::execute_pipeline::{closure#1}, opt_dist::training::RustcPGOProfile>
at /rustc/588eab2606249d5c408b91089fa4eb676635d378/src/tools/opt-dist/src/timer.rs:111:22
7: opt_dist::execute_pipeline
at /rustc/588eab2606249d5c408b91089fa4eb676635d378/src/tools/opt-dist/src/main.rs:242:35
8: opt_dist::main
at /rustc/588eab2606249d5c408b91089fa4eb676635d378/src/tools/opt-dist/src/main.rs:467:18
9: <fn() -> core::result::Result<(), anyhow::Error> as core::ops::function::FnOnce<()>>::call_once
at /rustc/3b4dd9bf1410f8da6329baa36ce5e37673cbbd1f/library/core/src/ops/function.rs:250:5
10: std::sys::backtrace::__rust_begin_short_backtrace::<fn() -> core::result::Result<(), anyhow::Error>, core::result::Result<(), anyhow::Error>>
at /rustc/3b4dd9bf1410f8da6329baa36ce5e37673cbbd1f/library/std/src/sys/backtrace.rs:158:18
11: std::rt::lang_start::<core::result::Result<(), anyhow::Error>>::{closure#0}
at /rustc/3b4dd9bf1410f8da6329baa36ce5e37673cbbd1f/library/std/src/rt.rs:206:18
12: core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once
at /rustc/3b4dd9bf1410f8da6329baa36ce5e37673cbbd1f/library/core/src/ops/function.rs:287:21
13: std::panicking::catch_unwind::do_call
at /rustc/3b4dd9bf1410f8da6329baa36ce5e37673cbbd1f/library/std/src/panicking.rs:590:40
14: std::panicking::catch_unwind
at /rustc/3b4dd9bf1410f8da6329baa36ce5e37673cbbd1f/library/std/src/panicking.rs:553:19
:broken_heart: Test for 588eab2606249d5c408b91089fa4eb676635d378 failed: CI. Failed jobs:
try - dist-x86_64-linux(web logs, extended logs)
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.
Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.
@bors try
:hourglass: Trying commit 1b2b0daf97d52a0f23fd4d4e8195011dcd9dfd19 with merge 0c70cfbec949d241375e31c5a42066be70c720fc…
To cancel the try build, run the command @bors try cancel.
Workflow: https://github.com/rust-lang/rust/actions/runs/19990295829
:sunny: Try build successful (CI)
Build commit: 0c70cfbec949d241375e31c5a42066be70c720fc (0c70cfbec949d241375e31c5a42066be70c720fc, parent: da2544bfbe84df7b24d83c029c74299ebf6112c6)
@craterbot check
:ok_hand: Experiment pr-149681 created and queued.
:robot: Automatically detected try build 0c70cfbec949d241375e31c5a42066be70c720fc
:mag: You can check out the queue and this experiment's details.
:information_source: Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more
:umbrella: The latest upstream changes (presumably #149941) made this pull request unmergeable. Please resolve the merge conflicts.