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