-
Notifications
You must be signed in to change notification settings - Fork 13.5k
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
pub mod utils { | ||
pub fn root_helper() { | ||
println!("root_helper"); | ||
} | ||
} | ||
|
||
pub fn root_function() -> String { | ||
"my_api root!".to_string() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pub fn root_function() -> String { | ||
"my_api root!".to_string() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// #![crate_name = "my_api::core"] | ||
|
||
pub mod util { | ||
pub fn core_mod_fn() -> String { | ||
format!("core_fn from my_api::core::util",) | ||
} | ||
} | ||
|
||
pub fn core_fn() -> String { | ||
format!("core_fn from my_api::core!",) | ||
} | ||
|
||
pub fn core_fn2() -> String { | ||
format!("core_fn2 from my_api::core!",) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
pub mod util { | ||
pub fn util_mod_helper() -> String { | ||
format!("Helper from my_api::utils::util",) | ||
} | ||
} | ||
|
||
pub fn utils_helper() -> String { | ||
format!("Helper from my_api::utils!",) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
//@ build-pass | ||
//@ aux-crate:my_api=open-ns-my_api.rs | ||
//@ aux-crate:my_api::utils=open-ns-my_api_utils.rs | ||
//@ aux-crate:my_api::core=open-ns-my_api_core.rs | ||
//@ compile-flags: -Z namespaced-crates | ||
//@ edition: 2024 | ||
|
||
//@ ignore-test FIXME(packages_as_namespaces): feature not implemented yet | ||
|
||
use my_api::root_function; | ||
use my_api::utils::util; | ||
|
||
fn main() { | ||
let _ = root_function(); | ||
let _ = my_api::root_function(); | ||
let _ = my_api::utils::utils_helper(); | ||
let _ = util::util_mod_helper(); | ||
let _ = my_api::core::core_fn(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
//@ build-pass | ||
//@ aux-crate: my_api=open-ns-my_api.rs | ||
//@ aux-crate: my_api::utils=open-ns-my_api_utils.rs | ||
//@ aux-crate: my_api::core=open-ns-my_api_core.rs | ||
//@ compile-flags: -Z namespaced-crates | ||
//@ edition: 2024 | ||
|
||
//@ ignore-test FIXME(packages_as_namespaces): feature not implemented yet | ||
|
||
use my_api::core::{core_fn, core_fn2}; | ||
use my_api::utils::*; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also an ambiguity, like in |
||
use my_api::*; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the 3-scope model this would import from both |
||
|
||
fn main() { | ||
let _ = root_function(); | ||
let _ = utils_helper(); | ||
let _ = core_fn(); | ||
let _ = core_fn2(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// This test should fail with `utils` being defined multiple times, since open-ns-mod-my_api.rs | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm? There's no |
||
// includes a `mod utils` and we also include open-ns-my_api_utils.rs as a namespaced crate at | ||
// my_api::utils. | ||
|
||
//@ aux-crate: my_api::utils=open-ns-my_api_utils.rs | ||
//@ compile-flags: -Z namespaced-crates | ||
//@ edition: 2024 | ||
//@ build-pass | ||
|
||
//@ ignore-test FIXME(packages_as_namespaces): feature not implemented yet | ||
|
||
fn main() { | ||
// FIXME test should fail with conflict here, but unsure how to do error annotation | ||
// in auxiliary crate. | ||
// let _ = my_api::root_function(); | ||
// let _ = my_api::utils::root_helper(); | ||
let _ = my_api::utils::utils_helper(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// This test makes sure namespaced crates work if we don't use any use statements but instead fully | ||
// qualify all references. | ||
|
||
//@ aux-crate: my_api=open-ns-my_api.rs | ||
//@ aux-crate: my_api::utils=open-ns-my_api_utils.rs | ||
//@ compile-flags: -Z namespaced-crates | ||
//@ edition: 2024 | ||
//@ build-pass | ||
|
||
//@ ignore-test FIXME(packages_as_namespaces): feature not implemented yet | ||
|
||
fn main() { | ||
let _ = my_api::root_function(); | ||
let _ = my_api::utils::utils_helper(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also an ambiguity, like in |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// This test makes sure namespaced crates work if we don't use any use statements but instead fully | ||
// qualify all references and we only have a single namespaced crate with no parent crate. | ||
|
||
//@ aux-crate: my_api::utils=open-ns-my_api_utils.rs | ||
//@ compile-flags: -Z namespaced-crates | ||
//@ edition: 2024 | ||
//@ build-pass | ||
|
||
//@ ignore-test FIXME(packages_as_namespaces): feature not implemented yet | ||
|
||
fn main() { | ||
let _ = my_api::utils::utils_helper(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Tests that namespaced crate names work inside macros. | ||
|
||
//@ aux-crate: my_api::utils=open-ns-my_api_utils.rs | ||
//@ compile-flags: -Z namespaced-crates | ||
//@ edition: 2024 | ||
//@ build-pass | ||
|
||
//@ ignore-test FIXME(packages_as_namespaces): feature not implemented yet | ||
|
||
macro_rules! import_and_call { | ||
($import_path:path, $fn_name:ident) => {{ | ||
use $import_path; | ||
$fn_name(); | ||
}}; | ||
} | ||
|
||
fn main() { | ||
import_and_call!(my_api::utils::utils_helper, utils_helper) | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,13 @@ | ||||||
//@ aux-crate: my_api::utils=open-ns-my_api_utils.rs | ||||||
//@ compile-flags: -Z namespaced-crates | ||||||
//@ edition: 2024 | ||||||
//@ build-pass | ||||||
|
||||||
//@ ignore-test FIXME(packages_as_namespaces): feature not implemented yet | ||||||
|
||||||
use my_api; // FIXME can be resolved even though it (maybe?) shouldn't be | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
We should decide the desired behavior before merging this. In this test case, There was a problem hiding this comment. Choose a reason for hiding this commentThe 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). |
||||||
use my_api::utils::utils_helper; | ||||||
|
||||||
fn main() { | ||||||
let _ = utils_helper(); | ||||||
} |
There was a problem hiding this comment.
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 tomy_api(crate)::utils(mod)
andmy_api(open_ns)::utils(crate)
, and they have different definitions.Alternatively
my_api(crate)::utils(mod)
will shadowmy_api(open_ns)::utils(crate)
in the 3-scope model, if we do not report ambiguities even for explicit uses.There was a problem hiding this comment.
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)
inmy_api
. Themy_api
crate only has a public function namedroot_function
.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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
andtests/ui/resolve/auxiliary/open-ns-mod-my_api.rs
, the files are named too similarly.I'll need to re-review all the cases.