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.

Copy link
Contributor

Choose a reason for hiding this comment

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

@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

use my_api::root_function;
use my_api::utils::util;
//~^ ERROR E0432
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
//~^ ERROR E0432
//~^ ERROR unresolved import `my_api::utils`

@@ -0,0 +1,12 @@
// Tests that namespaced crate names are limited to two segments
Copy link
Contributor

Choose a reason for hiding this comment

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

Non-relevant copypasted comment.

/// **Belongs to the type namespace.**
ToolMod,

/// The resolution for a virtual module in a namespaced crate. E.g. `my_api`
Copy link
Contributor

Choose a reason for hiding this comment

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

"Virtual" is still used in a number of comments and variables.

let open_ns_name = format!("{}::{}", sym.as_str(), ident.name);
let ns_ident = IdentKey::with_root_ctxt(Symbol::intern(&open_ns_name));
match self.extern_prelude_get_flag(ns_ident, ident.span, finalize.is_some()) {
Some(decl) => Ok(decl),
Copy link
Contributor

Choose a reason for hiding this comment

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

No need for the concatenation above, we can lookup the ident directly and return Ok only if the returned Decl is Res::OpenMod.

}
Err(determinacy) => Err(determinacy.into_value()),
};

Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: unnecessary change.

missing_virtual_bases.into_iter().map(|ident| (ident, ExternPreludeEntry::virtual_flag())),
);

debug!(?extern_prelude);
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: could you remove the added debugging logic before merging?

@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 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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