summaryrefslogtreecommitdiffstats
path: root/tests/ui/imports/imports.rs
blob: acb2b32b59d5f4b18068213fda1d9c82cd277765 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// run-pass
#![allow(unused)]

// Like other items, private imports can be imported and used non-lexically in paths.
mod a {
    use a as foo;
    use self::foo::foo as bar;

    mod b {
        use super::bar;
    }
}

mod foo { pub fn f() {} }
mod bar { pub fn f() {} }

pub fn f() -> bool { true }

// Items and explicit imports shadow globs.
fn g() {
    use foo::*;
    use bar::*;
    fn f() -> bool { true }
    let _: bool = f();
}

fn h() {
    use foo::*;
    use bar::*;
    use f;
    let _: bool = f();
}

// Here, there appears to be shadowing but isn't because of namespaces.
mod b {
    use foo::*; // This imports `f` in the value namespace.
    use super::b as f; // This imports `f` only in the type namespace,
    fn test() { self::f(); } // so the glob isn't shadowed.
}

// Here, there is shadowing in one namespace, but not the other.
mod c {
    mod test {
        pub fn f() {}
        pub mod f {}
    }
    use self::test::*; // This glob-imports `f` in both namespaces.
    mod f { pub fn f() {} } // This shadows the glob only in the value namespace.

    fn test() {
        self::f(); // Check that the glob-imported value isn't shadowed.
        self::f::f(); // Check that the glob-imported module is shadowed.
    }
}

// Unused names can be ambiguous.
mod d {
    pub use foo::*; // This imports `f` in the value namespace.
    pub use bar::*; // This also imports `f` in the value namespace.
}

mod e {
    pub use d::*; // n.b. Since `e::f` is not used, this is not considered to be a use of `d::f`.
}

fn main() {}