Skip to content

Commit 79e7d5e

Browse files
committed
add tests
1 parent 374cd80 commit 79e7d5e

20 files changed

Lines changed: 332 additions & 0 deletions
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
pub mod utils {
2+
pub fn root_helper() {
3+
println!("root_helper");
4+
}
5+
}
6+
7+
pub fn root_function() -> String {
8+
"my_api root!".to_string()
9+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pub fn root_function() -> String {
2+
"my_api root!".to_string()
3+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// #![crate_name = "my_api::core"]
2+
3+
pub mod util {
4+
pub fn core_mod_fn() -> String {
5+
format!("core_fn from my_api::core::util",)
6+
}
7+
}
8+
9+
pub fn core_fn() -> String {
10+
format!("core_fn from my_api::core!",)
11+
}
12+
13+
pub fn core_fn2() -> String {
14+
format!("core_fn2 from my_api::core!",)
15+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
pub mod util {
2+
pub fn util_mod_helper() -> String {
3+
format!("Helper from my_api::utils::util",)
4+
}
5+
}
6+
7+
pub fn utils_helper() -> String {
8+
format!("Helper from my_api::utils!",)
9+
}
10+
11+
pub fn get_u32() -> u32 {
12+
1
13+
}

tests/ui/resolve/open-ns-1.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//@ aux-crate:my_api=open-ns-my_api.rs
2+
//@ aux-crate:my_api::utils=open-ns-my_api_utils.rs
3+
//@ aux-crate:my_api::core=open-ns-my_api_core.rs
4+
//@ compile-flags: -Z namespaced-crates
5+
//@ edition: 2024
6+
7+
use my_api::root_function;
8+
use my_api::utils::util;
9+
//~^ ERROR E0432
10+
11+
fn main() {
12+
let _ = root_function();
13+
let _ = my_api::root_function();
14+
let _ = my_api::utils::utils_helper();
15+
//~^ ERROR E0433
16+
let _ = util::util_mod_helper();
17+
let _ = my_api::core::core_fn();
18+
//~^ ERROR E0433
19+
}

tests/ui/resolve/open-ns-1.stderr

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
error[E0432]: unresolved import `my_api::utils`
2+
--> $DIR/open-ns-1.rs:8:13
3+
|
4+
LL | use my_api::utils::util;
5+
| ^^^^^ could not find `utils` in `my_api`
6+
7+
error[E0433]: failed to resolve: could not find `utils` in `my_api`
8+
--> $DIR/open-ns-1.rs:14:21
9+
|
10+
LL | let _ = my_api::utils::utils_helper();
11+
| ^^^^^ could not find `utils` in `my_api`
12+
13+
error[E0433]: failed to resolve: could not find `core` in `my_api`
14+
--> $DIR/open-ns-1.rs:17:21
15+
|
16+
LL | let _ = my_api::core::core_fn();
17+
| ^^^^ could not find `core` in `my_api`
18+
19+
error: aborting due to 3 previous errors
20+
21+
Some errors have detailed explanations: E0432, E0433.
22+
For more information about an error, try `rustc --explain E0432`.

tests/ui/resolve/open-ns-10.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//@ aux-crate: my_api::utils=open-ns-my_api_utils.rs
2+
//@ compile-flags: -Z namespaced-crates
3+
//@ edition: 2024
4+
5+
use my_api::utils::get_u32;
6+
//~^ ERROR E0659
7+
8+
macro_rules! define {
9+
() => {
10+
pub mod my_api {
11+
pub mod utils {
12+
pub fn get_u32() -> u32 {
13+
2
14+
}
15+
}
16+
}
17+
};
18+
}
19+
20+
define!();
21+
22+
fn main() {
23+
let val = get_u32();
24+
assert_eq!(val, 2);
25+
}

tests/ui/resolve/open-ns-10.stderr

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
error[E0659]: `my_api` is ambiguous
2+
--> $DIR/open-ns-10.rs:5:5
3+
|
4+
LL | use my_api::utils::get_u32;
5+
| ^^^^^^ ambiguous name
6+
|
7+
= note: ambiguous because of a conflict between a macro-expanded name and a less macro-expanded name from outer scope during import or macro resolution
8+
= note: `my_api` could refer to a namespaced crate passed with `--extern`
9+
note: `my_api` could also refer to the module defined here
10+
--> $DIR/open-ns-10.rs:10:9
11+
|
12+
LL | / pub mod my_api {
13+
LL | | pub mod utils {
14+
LL | | pub fn get_u32() -> u32 {
15+
LL | | 2
16+
... |
17+
LL | | }
18+
| |_________^
19+
...
20+
LL | define!();
21+
| --------- in this macro invocation
22+
= help: use `crate::my_api` to refer to this module unambiguously
23+
= note: this error originates in the macro `define` (in Nightly builds, run with -Z macro-backtrace for more info)
24+
25+
error: aborting due to 1 previous error
26+
27+
For more information about this error, try `rustc --explain E0659`.

tests/ui/resolve/open-ns-2.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//@ aux-crate: my_api=open-ns-my_api.rs
2+
//@ aux-crate: my_api::utils=open-ns-my_api_utils.rs
3+
//@ aux-crate: my_api::core=open-ns-my_api_core.rs
4+
//@ compile-flags: -Z namespaced-crates
5+
//@ edition: 2024
6+
7+
use my_api::core::{core_fn, core_fn2};
8+
//~^ ERROR E0432
9+
use my_api::utils::*;
10+
//~^ ERROR E0432
11+
use my_api::*;
12+
13+
fn main() {
14+
let _ = root_function();
15+
let _ = utils_helper();
16+
let _ = core_fn();
17+
let _ = core_fn2();
18+
}

tests/ui/resolve/open-ns-2.stderr

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0432]: unresolved import `my_api::core`
2+
--> $DIR/open-ns-2.rs:7:13
3+
|
4+
LL | use my_api::core::{core_fn, core_fn2};
5+
| ^^^^ could not find `core` in `my_api`
6+
7+
error[E0432]: unresolved import `my_api::utils`
8+
--> $DIR/open-ns-2.rs:9:13
9+
|
10+
LL | use my_api::utils::*;
11+
| ^^^^^ could not find `utils` in `my_api`
12+
13+
error: aborting due to 2 previous errors
14+
15+
For more information about this error, try `rustc --explain E0432`.

0 commit comments

Comments
 (0)