Skip to content

Introduce changes for packages as namespaces#152299

Open
b-naber wants to merge 7 commits intorust-lang:mainfrom
b-naber:namespaced-crate-names
Open

Introduce changes for packages as namespaces#152299
b-naber wants to merge 7 commits intorust-lang:mainfrom
b-naber:namespaced-crate-names

Conversation

@b-naber
Copy link
Contributor

@b-naber b-naber commented Feb 7, 2026

Implements the compiler changes for RFC 3243.

After the refactorings introduced in #143734 and #149681, we can now introduce a new scope to handle namespaced crate names. Scope::NamespacedCrates has lower precedence than Scope::ModuleNonGlobs and Scope::ModuleGlobs, and is used to as a fallback whenever an Ident isn't resolvable in a Module. In cases where the root of a namespaced crate (foo in foo::bar) isn't in the extern prelude, we have to introduce a virtual module. This PR introduces a new variant VirtualMod to Res and ScopeSet::NamespacedCrates. An alternative to this approach would be to create synthetic metadata for these crates, which seemed like the less attractive option to me.

One potential downside to this approach that uses a new Scope is that in cases where a crate contains a public module whose name overlaps with the name of a namespaced crate (i.e. foo and foo::bar are dependencies and bar is a public module in foo), only the module in the base crate is used for resolution. This seems like less of a problem in practice though, as crate owners would probably only re-export the crate through that module in the first place?! Throwing an ambiguity error in this situation would be preferable, but is not possible with this implementation approach.

Namespaces are also limited to two levels, though that is by design currently, and not a limitation of the implementation approach.

r? @petrochenkov

@rustbot
Copy link
Collaborator

rustbot commented Feb 7, 2026

HIR ty lowering was modified

cc @fmease

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants