]> git.lizzy.rs Git - rust.git/blob - src/test/ui/uniform-paths/basic-nested.rs
Auto merge of #86155 - alexcrichton:abort-on-unwind, r=nikomatsakis
[rust.git] / src / test / ui / uniform-paths / basic-nested.rs
1 // This test is similar to `basic.rs`, but nested in modules.
2
3 // run-pass
4 // edition:2018
5
6 #![feature(decl_macro)]
7
8 #![allow(unused_imports)]
9 #![allow(non_camel_case_types)]
10
11 mod foo {
12     // Test that ambiguity errors are not emitted between `self::test` and
13     // `::test`, assuming the latter (crate) is not in `extern_prelude`.
14     mod test {
15         pub struct Foo(pub ());
16     }
17     pub use test::Foo;
18
19     // Test that qualified paths can refer to both the external crate and local item.
20     mod std {
21         pub struct io(pub ());
22     }
23     pub use ::std::io as std_io;
24     pub use self::std::io as local_io;
25 }
26
27 // Test that we can refer to the external crate unqualified
28 // (when there isn't a local item with the same name).
29 use std::io;
30
31 mod bar {
32     // Also test the unqualified external crate import in a nested module,
33     // to show that the above import doesn't resolve through a local `std`
34     // item, e.g., the automatically injected `extern crate std;`, which in
35     // the Rust 2018 should no longer be visible through `crate::std`.
36     pub use std::io;
37
38     // Also test that items named `std` in other namespaces don't
39     // cause ambiguity errors for the import from `std` above.
40     pub fn std() {}
41     pub macro std() {}
42 }
43
44
45 fn main() {
46     foo::Foo(());
47     foo::std_io::stdout();
48     foo::local_io(());
49     io::stdout();
50     bar::io::stdout();
51     bar::std();
52     bar::std!();
53
54     {
55         // Test that having `io` in a module scope and a non-module
56         // scope is allowed, when both resolve to the same definition.
57         use std::io;
58         use io::stdout;
59         stdout();
60     }
61 }