Skip to content

Add test cases for namespaced crates #142437

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

eholk
Copy link
Contributor

@eholk eholk commented Jun 12, 2025

This is just to add a few test cases of agreed upon desired behavior for this feature so that future PRs can enable them as they start passing.

I pulled these tests out of #140271.

r? @petrochenkov

cc @b-naber

@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 Jun 12, 2025

//@ ignore-test FIXME(packages_as_namespaces): feature not implemented yet

use my_api; // FIXME can be resolved even though it (maybe?) shouldn't be
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
use my_api; // FIXME can be resolved even though it (maybe?) shouldn't be
use my_api;

We should decide the desired behavior before merging this. In this test case, my_api is an open namespace module. I think it makes sense to resolve it, as it's fine to have a module that only contains another module.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, this should generally work, unless there are specific reasons for not supporting it (like issues with reexporting things like this to other crates due to them lacking identity).

//@ ignore-test FIXME(packages_as_namespaces): feature not implemented yet

use my_api::root_function;
use my_api::utils::util;
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be an ambiguity error.
my_api::utils refers both to my_api(crate)::utils(mod) and my_api(open_ns)::utils(crate), and they have different definitions.

Alternatively my_api(crate)::utils(mod) will shadow my_api(open_ns)::utils(crate) in the 3-scope model, if we do not report ambiguities even for explicit uses.

Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure what you mean, there is no utils(mod) in my_api. The my_api crate only has a public function named root_function.

Copy link
Contributor

@petrochenkov petrochenkov Jun 22, 2025

Choose a reason for hiding this comment

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

Ah, okay, I mixed up tests/ui/resolve/auxiliary/open-ns-my_api.rs and tests/ui/resolve/auxiliary/open-ns-mod-my_api.rs, the files are named too similarly.
I'll need to re-review all the cases.

//@ ignore-test FIXME(packages_as_namespaces): feature not implemented yet

use my_api::core::{core_fn, core_fn2};
use my_api::utils::*;
Copy link
Contributor

Choose a reason for hiding this comment

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

Also an ambiguity, like in tests/ui/resolve/open-ns-1.rs.


use my_api::core::{core_fn, core_fn2};
use my_api::utils::*;
use 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.

In the 3-scope model this would import from both my_api(crate) and my_api(open_ns).
Therefore it will introduce names utils(mod), root_function and core into this module, but not utils(crate) because it would be shadowed by utils(mod).
Need to test this behavior.

@@ -0,0 +1,18 @@
// This test should fail with `utils` being defined multiple times, since open-ns-mod-my_api.rs
Copy link
Contributor

Choose a reason for hiding this comment

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

Hm? There's no open-ns-mod-my_api.rs in this test.


fn main() {
let _ = my_api::root_function();
let _ = my_api::utils::utils_helper();
Copy link
Contributor

Choose a reason for hiding this comment

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

Also an ambiguity, like in tests/ui/resolve/open-ns-1.rs.


//@ ignore-test FIXME(packages_as_namespaces): feature not implemented yet

use my_api; // FIXME can be resolved even though it (maybe?) shouldn't be
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, this should generally work, unless there are specific reasons for not supporting it (like issues with reexporting things like this to other crates due to them lacking identity).

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