Skip to content

Commit 4942d3d

Browse files
committed
rustc_resolve: Test the order that preludes are resolved
1 parent d93f678 commit 4942d3d

File tree

3 files changed

+135
-0
lines changed

3 files changed

+135
-0
lines changed

Diff for: tests/ui/resolve/auxiliary/tracing.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#![feature(decl_macro)]
2+
3+
pub use std::clone::Clone as instrument; // macro_use/extern/tool
4+
pub use std::clone::Clone as global_allocator; // library
5+
pub use std::clone::Clone as deprecated; // lang
6+
7+
mod inner {
8+
pub macro some_macro {
9+
() => {}
10+
}
11+
}

Diff for: tests/ui/resolve/prelude-order.rs

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
//@ aux-build:tracing.rs
2+
//@ compile-flags: --crate-type=lib
3+
4+
#![feature(register_tool)]
5+
6+
/* tool prelude */
7+
#![register_tool(instrument)] // macro_use/extern prelude
8+
#![register_tool(must_use)] // lang prelude
9+
#![register_tool(test)] // library prelude
10+
11+
/* extern prelude */
12+
extern crate tracing as usize; // lang prelude
13+
extern crate tracing as Option; // libs prelude
14+
extern crate tracing as instrument; // macro_use/tool prelude
15+
16+
/* macro_use prelude */
17+
#[macro_use]
18+
extern crate tracing; // also extern prelude
19+
20+
/* lang and libs implicitly in scope */
21+
22+
// tool/extern -> extern
23+
// NOTE: macro_use/libs/lang not tested (not present)
24+
#[tracing::inner::some_macro] //~ ERROR `inner` is private
25+
fn foo() {}
26+
27+
// tool/lang -> tool (no possible conflict)
28+
// NOTE: macro_use/libs/extern not tested (not present)
29+
#[must_use::inner] // ok
30+
fn f() {}
31+
32+
// tool/libs -> tool
33+
// NOTE: extern/lang/macro not tested (not present)
34+
#[test::not_real] // ok
35+
fn b() {}
36+
37+
// tool/extern/macro_use -> extern
38+
// NOTE: lang/libs not tested (not present)
39+
#[instrument::inner] //~ ERROR could not find `inner`
40+
fn a() {}
41+
42+
// extern/lang -> lang
43+
// NOTE: macro_use/libs/tool not tested (different namespace/not present/wrong context)
44+
fn bar() -> usize { // ok
45+
0
46+
}
47+
48+
// extern/libs -> extern
49+
// NOTE: macro_use/lang/tool not tested (not present)
50+
fn baz() -> Option<i32> { //~ ERROR: expected type, found crate
51+
0
52+
}
53+
54+
// macro/lang -> ambiguous
55+
// NOTE: tool/libs/extern not tested (not present)
56+
#[deprecated] //~ ERROR ambiguous
57+
fn e() {}
58+
59+
// macro/libs -> macro
60+
// NOTE: tool/lang/extern not tested (not present)
61+
#[global_allocator] //~ ERROR derive macro
62+
fn d() {}
63+
64+
// lang/libs -> lang
65+
// NOTE: tool/extern/macro not tested (not present)
66+
// FIXME: this is not actually a good test. `cfg!` is a bang-style macro and so ignored here.
67+
// On the other hand, we control both lang and libs so it doesn't really matter.
68+
#[cfg(FALSE)] // ok
69+
fn g() {}

Diff for: tests/ui/resolve/prelude-order.stderr

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
error: expected attribute, found derive macro `global_allocator`
2+
--> $DIR/prelude-order.rs:61:3
3+
|
4+
LL | #[global_allocator]
5+
| ^^^^^^^^^^^^^^^^ not an attribute
6+
7+
error[E0433]: failed to resolve: could not find `inner` in `instrument`
8+
--> $DIR/prelude-order.rs:39:15
9+
|
10+
LL | #[instrument::inner]
11+
| ^^^^^ could not find `inner` in `instrument`
12+
13+
error[E0573]: expected type, found crate `Option`
14+
--> $DIR/prelude-order.rs:50:13
15+
|
16+
LL | fn baz() -> Option<i32> {
17+
| ^^^^^^^^^^^ not a type
18+
|
19+
help: consider importing this enum instead
20+
|
21+
LL + use std::option::Option;
22+
|
23+
24+
error[E0659]: `deprecated` is ambiguous
25+
--> $DIR/prelude-order.rs:56:3
26+
|
27+
LL | #[deprecated]
28+
| ^^^^^^^^^^ ambiguous name
29+
|
30+
= note: ambiguous because of a name conflict with a builtin attribute
31+
= note: `deprecated` could refer to a built-in attribute
32+
note: `deprecated` could also refer to the derive macro imported here
33+
--> $DIR/prelude-order.rs:17:1
34+
|
35+
LL | #[macro_use]
36+
| ^^^^^^^^^^^^
37+
38+
error[E0603]: module `inner` is private
39+
--> $DIR/prelude-order.rs:24:12
40+
|
41+
LL | #[tracing::inner::some_macro]
42+
| ^^^^^ ---------- macro `some_macro` is not publicly re-exported
43+
| |
44+
| private module
45+
|
46+
note: the module `inner` is defined here
47+
--> $DIR/auxiliary/tracing.rs:7:1
48+
|
49+
LL | mod inner {
50+
| ^^^^^^^^^
51+
52+
error: aborting due to 5 previous errors
53+
54+
Some errors have detailed explanations: E0433, E0573, E0603, E0659.
55+
For more information about an error, try `rustc --explain E0433`.

0 commit comments

Comments
 (0)