]> git.lizzy.rs Git - rust.git/blob - tests/ui/wildcard_imports.rs
Add tests for wildcard_imports lint
[rust.git] / tests / ui / wildcard_imports.rs
1 // run-rustfix
2 // aux-build:wildcard_imports_helper.rs
3
4 #![warn(clippy::wildcard_imports)]
5 #![allow(unused)]
6 #![warn(unused_imports)]
7
8 extern crate wildcard_imports_helper;
9
10 use crate::fn_mod::*;
11 use crate::mod_mod::*;
12 use crate::multi_fn_mod::*;
13 #[macro_use]
14 use crate::struct_mod::*;
15
16 #[allow(unused_imports)]
17 use wildcard_imports_helper::inner::inner_for_self_import;
18 use wildcard_imports_helper::inner::inner_for_self_import::*;
19 use wildcard_imports_helper::*;
20
21 mod fn_mod {
22     pub fn foo() {}
23 }
24
25 mod mod_mod {
26     pub mod inner_mod {
27         pub fn foo() {}
28     }
29 }
30
31 mod multi_fn_mod {
32     pub fn multi_foo() {}
33     pub fn multi_bar() {}
34     pub fn multi_baz() {}
35     pub mod multi_inner_mod {
36         pub fn foo() {}
37     }
38 }
39
40 mod struct_mod {
41     pub struct A;
42     pub struct B;
43     pub mod inner_struct_mod {
44         pub struct C;
45     }
46
47     #[macro_export]
48     macro_rules! double_struct_import_test {
49         () => {
50             let _ = A;
51         };
52     }
53 }
54
55 fn main() {
56     foo();
57     multi_foo();
58     multi_bar();
59     multi_inner_mod::foo();
60     inner_mod::foo();
61     extern_foo();
62     inner_extern_bar();
63
64     let _ = A;
65     let _ = inner_struct_mod::C;
66     let _ = ExternA;
67
68     double_struct_import_test!();
69     double_struct_import_test!();
70 }
71
72 mod in_fn_test {
73     pub use self::inner_exported::*;
74     #[allow(unused_imports)]
75     pub(crate) use self::inner_exported2::*;
76
77     fn test_intern() {
78         use crate::fn_mod::*;
79
80         foo();
81     }
82
83     fn test_extern() {
84         use wildcard_imports_helper::inner::inner_for_self_import::{self, *};
85         use wildcard_imports_helper::*;
86
87         inner_for_self_import::inner_extern_foo();
88         inner_extern_foo();
89
90         extern_foo();
91
92         let _ = ExternA;
93     }
94
95     fn test_inner_nested() {
96         use self::{inner::*, inner2::*};
97
98         inner_foo();
99         inner_bar();
100     }
101
102     fn test_extern_reexported() {
103         use wildcard_imports_helper::*;
104
105         extern_exported();
106         let _ = ExternExportedStruct;
107         let _ = ExternExportedEnum::A;
108     }
109
110     mod inner_exported {
111         pub fn exported() {}
112         pub struct ExportedStruct;
113         pub enum ExportedEnum {
114             A,
115         }
116     }
117
118     mod inner_exported2 {
119         pub(crate) fn exported2() {}
120     }
121
122     mod inner {
123         pub fn inner_foo() {}
124     }
125
126     mod inner2 {
127         pub fn inner_bar() {}
128     }
129 }
130
131 fn test_reexported() {
132     use crate::in_fn_test::*;
133
134     exported();
135     let _ = ExportedStruct;
136     let _ = ExportedEnum::A;
137 }