]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/imports.rs
Auto merge of #35856 - phimuemue:master, r=brson
[rust.git] / src / test / run-pass / imports.rs
1 // Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // ignore-pretty : (#23623) problems when ending with // comments
12
13 #![feature(item_like_imports)]
14 #![allow(unused)]
15
16 // Like other items, private imports can be imported and used non-lexically in paths.
17 mod a {
18     use a as foo;
19     use self::foo::foo as bar;
20
21     mod b {
22         use super::bar;
23     }
24 }
25
26 mod foo { pub fn f() {} }
27 mod bar { pub fn f() {} }
28
29 pub fn f() -> bool { true }
30
31 // Items and explicit imports shadow globs.
32 fn g() {
33     use foo::*;
34     use bar::*;
35     fn f() -> bool { true }
36     let _: bool = f();
37 }
38
39 fn h() {
40     use foo::*;
41     use bar::*;
42     use f;
43     let _: bool = f();
44 }
45
46 // Here, there appears to be shadowing but isn't because of namespaces.
47 mod b {
48     use foo::*; // This imports `f` in the value namespace.
49     use super::b as f; // This imports `f` only in the type namespace,
50     fn test() { self::f(); } // so the glob isn't shadowed.
51 }
52
53 // Here, there is shadowing in one namespace, but not the other.
54 mod c {
55     mod test {
56         pub fn f() {}
57         pub mod f {}
58     }
59     use self::test::*; // This glob-imports `f` in both namespaces.
60     mod f { pub fn f() {} } // This shadows the glob only in the value namespace.
61
62     fn test() {
63         self::f(); // Check that the glob-imported value isn't shadowed.
64         self::f::f(); // Check that the glob-imported module is shadowed.
65     }
66 }
67
68 // Unused names can be ambiguous.
69 mod d {
70     pub use foo::*; // This imports `f` in the value namespace.
71     pub use bar::*; // This also imports `f` in the value namespace.
72 }
73
74 mod e {
75     pub use d::*; // n.b. Since `e::f` is not used, this is not considered to be a use of `d::f`.
76 }
77
78 fn main() {}