]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/imports.rs
Rollup merge of #53545 - FelixMcFelix:fix-50865-beta, r=petrochenkov
[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 #![allow(unused)]
12
13 // Like other items, private imports can be imported and used non-lexically in paths.
14 mod a {
15     use a as foo;
16     use self::foo::foo as bar;
17
18     mod b {
19         use super::bar;
20     }
21 }
22
23 mod foo { pub fn f() {} }
24 mod bar { pub fn f() {} }
25
26 pub fn f() -> bool { true }
27
28 // Items and explicit imports shadow globs.
29 fn g() {
30     use foo::*;
31     use bar::*;
32     fn f() -> bool { true }
33     let _: bool = f();
34 }
35
36 fn h() {
37     use foo::*;
38     use bar::*;
39     use f;
40     let _: bool = f();
41 }
42
43 // Here, there appears to be shadowing but isn't because of namespaces.
44 mod b {
45     use foo::*; // This imports `f` in the value namespace.
46     use super::b as f; // This imports `f` only in the type namespace,
47     fn test() { self::f(); } // so the glob isn't shadowed.
48 }
49
50 // Here, there is shadowing in one namespace, but not the other.
51 mod c {
52     mod test {
53         pub fn f() {}
54         pub mod f {}
55     }
56     use self::test::*; // This glob-imports `f` in both namespaces.
57     mod f { pub fn f() {} } // This shadows the glob only in the value namespace.
58
59     fn test() {
60         self::f(); // Check that the glob-imported value isn't shadowed.
61         self::f::f(); // Check that the glob-imported module is shadowed.
62     }
63 }
64
65 // Unused names can be ambiguous.
66 mod d {
67     pub use foo::*; // This imports `f` in the value namespace.
68     pub use bar::*; // This also imports `f` in the value namespace.
69 }
70
71 mod e {
72     pub use d::*; // n.b. Since `e::f` is not used, this is not considered to be a use of `d::f`.
73 }
74
75 fn main() {}