]> git.lizzy.rs Git - rust.git/blob - src/test/ui/rfc-2166-underscore-imports/basic.rs
Auto merge of #54720 - davidtwco:issue-51191, r=nikomatsakis
[rust.git] / src / test / ui / rfc-2166-underscore-imports / basic.rs
1 // Copyright 2018 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 // compile-pass
12
13 #![feature(underscore_imports)]
14 #![warn(unused_imports, unused_extern_crates)]
15
16 struct S;
17
18 mod m {
19     pub trait Tr1 {
20         fn tr1_is_in_scope(&self) {}
21     }
22     pub trait Tr2 {
23         fn tr2_is_in_scope(&self) {}
24     }
25
26     impl Tr1 for ::S {}
27     impl Tr2 for ::S {}
28 }
29
30 mod unused {
31     use m::Tr1 as _; //~ WARN unused import
32     use S as _; //~ WARN unused import
33     extern crate core as _; // OK
34 }
35
36 mod outer {
37     mod middle {
38         pub use m::Tr1 as _;
39         pub use m::Tr2 as _; // OK, no name conflict
40         struct Tr1; // OK, no name conflict
41         fn check() {
42             // Both traits are in scope
43             ::S.tr1_is_in_scope();
44             ::S.tr2_is_in_scope();
45         }
46
47         mod inner {
48             // `_` imports are fetched by glob imports
49             use super::*;
50             fn check() {
51                 // Both traits are in scope
52                 ::S.tr1_is_in_scope();
53                 ::S.tr2_is_in_scope();
54             }
55         }
56     }
57
58     // `_` imports are fetched by glob imports
59     use self::middle::*;
60     fn check() {
61         // Both traits are in scope
62         ::S.tr1_is_in_scope();
63         ::S.tr2_is_in_scope();
64     }
65 }
66
67 fn main() {}