Skip to content

Packages as namespaces part 1#153312

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

Packages as namespaces part 1#153312
b-naber wants to merge 7 commits intorust-lang:mainfrom
b-naber:namespaced-crate-names-pt1

Conversation

@b-naber
Copy link
Contributor

@b-naber b-naber commented Mar 2, 2026

Part 1 of #152299

r? @petrochenkov

@rustbot
Copy link
Collaborator

rustbot commented Mar 2, 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 Mar 2, 2026
@rust-log-analyzer

This comment has been minimized.

@rust-cloud-vms rust-cloud-vms bot force-pushed the namespaced-crate-names-pt1 branch from a2f2abf to 3031b7d Compare March 3, 2026 18:45
@rust-log-analyzer

This comment has been minimized.

@rust-cloud-vms rust-cloud-vms bot force-pushed the namespaced-crate-names-pt1 branch from 3031b7d to a4f7d4d Compare March 3, 2026 20:29
&& let sym = Symbol::intern(name)
&& sym.can_be_raw()
{
Some((IdentKey::with_root_ctxt(sym), ExternPreludeEntry::flag()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Names with :: shouldn't be added to the map here, even if they are added they will never be used anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think ScopeSet::NamespacedCrate is necessary.
If only one scope is visited, then none of the ambiguity tracking infra in resolve_ident_in_scope_set is needed, you can just do the extern prelude lookup here directly.

This relates to one of your previous comments. I chose to keep these in the extern prelude, because we use them in resolve_ident_in_module. An alternative would be to keep a map like the namespaced_crate_names field. Keeping them in extern_prelude seems ok to me, given that they are passed via --extern.

extern_prelude.insert(IdentKey::with_root_ctxt(sym::core), ExternPreludeEntry::flag());

if !attr::contains_name(attrs, sym::no_std) {
extern_prelude.insert(IdentKey::with_root_ctxt(sym::std), ExternPreludeEntry::flag());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably need a test with an open namespace called std.
I guess now explicit --extern std::something should shadow the implicit real std, but eventually in the part 2 the latter should "link" to the former as a fallback.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a test, but since the real std seems to also be in the extern-prelude no OpenMod is ever created and the real std isn't shadowed.

@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 6, 2026
@b-naber
Copy link
Contributor Author

b-naber commented Mar 9, 2026

Thanks for the review.

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 9, 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.

4 participants