|
| 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() {} |
0 commit comments