Avoid prematurely choosing a glob import#153912
Avoid prematurely choosing a glob import#153912rust-bors[bot] merged 1 commit intorust-lang:mainfrom
Conversation
… with current import
|
This code is a minefield, it is known to not be correct, it makes assumptions that do not hold, and the whole thing needs to be rewritten together with some correctness proof. |
|
Best I can do is to run crater on this and see what happens. |
Avoid prematurely choosing a glob import
This comment has been minimized.
This comment has been minimized.
|
Glob imports that get selected first and then overwritten by single imports is something that is indeed done in the current system, even if it may be incorrect in corner cases, see e.g. the comments in |
|
Okay, the crater queue doesn't seem to be large at the moment. |
|
👌 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
|
🚧 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
|
🎉 Experiment
Footnotes
|
|
No non-spurious regressions. |
IIUC, single imports will be selected finally. This change is in But I have to say that I still don't have a complete mental model of resolver yet. |
|
Okay, @bors r+ |
…rochenkov Avoid prematurely choosing a glob import Fixes rust-lang#153842 Use the following without introducing trait to explain: ```rust mod a { pub use crate::x::y as x; // single import rust-lang#1 } mod b { pub mod x { pub mod y {} } } use a::x; // single import rust-lang#2 use b::*; // glob import rust-lang#3 fn main() {} ``` In current implementation, when `rust-lang#1` is first resolved, `crate::x` is temporarily taken from glob import `rust-lang#3` as `crate::b::x`. This happens because `single_import_can_define_name` will see that `rust-lang#2` cannot define `x` (because it depends on `rust-lang#1` and `rust-lang#1` is ignored) and then return `false`. Later, during finalization, `crate::x` in `rust-lang#1` resolves through single import `rust-lang#2` instead, which no longer matches the initially cached module `crate::b::x` and triggers the ICE. I think the resolver should keep this unresolved because `rust-lang#2` may still define `x` to avoid prematurely choosing a glob import. r? petrochenkov
…uwer Rollup of 8 pull requests Successful merges: - #122668 (Add APIs for dealing with titlecase) - #153041 (Remove `ATTRIBUTE_ORDER`) - #153912 (Avoid prematurely choosing a glob import) - #154093 (const validity checking: do not recurse to references inside MaybeDangling) - #154257 (Revert eagerly normalize in generalize) - #154179 (tests/ui/async-await/gat-is-send-across-await.rs: New regression test) - #154224 (Remove more `BuiltinLintDiag` variants) - #154245 (Allow applying autodiff macros to trait functions.)
Fixes #153842
Use the following without introducing trait to explain:
In current implementation, when
#1is first resolved,crate::xis temporarily taken from glob import#3ascrate::b::x. This happens becausesingle_import_can_define_namewill see that#2cannot definex(because it depends on#1and#1is ignored) and then returnfalse. Later, during finalization,crate::xin#1resolves through single import#2instead, which no longer matches the initially cached modulecrate::b::xand triggers the ICE.I think the resolver should keep this unresolved because
#2may still definexto avoid prematurely choosing a glob import.r? petrochenkov