Skip to content

Commit 14238b6

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

File tree

3 files changed

+149
-0
lines changed

3 files changed

+149
-0
lines changed

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+
}

tests/ui/resolve/prelude-order.rs

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

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)