]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/wildcard_imports.rs
Rollup merge of #78476 - RalfJung:btree-alias, r=Mark-Simulacrum
[rust.git] / src / tools / clippy / tests / ui / wildcard_imports.rs
1 // run-rustfix
2 // aux-build:wildcard_imports_helper.rs
3
4 #![warn(clippy::wildcard_imports)]
5 //#![allow(clippy::redundant_pub_crate)]
6 #![allow(unused)]
7 #![warn(unused_imports)]
8
9 extern crate wildcard_imports_helper;
10
11 use crate::fn_mod::*;
12 use crate::mod_mod::*;
13 use crate::multi_fn_mod::*;
14 #[macro_use]
15 use crate::struct_mod::*;
16
17 #[allow(unused_imports)]
18 use wildcard_imports_helper::inner::inner_for_self_import;
19 use wildcard_imports_helper::inner::inner_for_self_import::*;
20 use wildcard_imports_helper::*;
21
22 use std::io::prelude::*;
23 use wildcard_imports_helper::prelude::v1::*;
24
25 struct ReadFoo;
26
27 impl Read for ReadFoo {
28     fn read(&mut self, _buf: &mut [u8]) -> std::io::Result<usize> {
29         Ok(0)
30     }
31 }
32
33 mod fn_mod {
34     pub fn foo() {}
35 }
36
37 mod mod_mod {
38     pub mod inner_mod {
39         pub fn foo() {}
40     }
41 }
42
43 mod multi_fn_mod {
44     pub fn multi_foo() {}
45     pub fn multi_bar() {}
46     pub fn multi_baz() {}
47     pub mod multi_inner_mod {
48         pub fn foo() {}
49     }
50 }
51
52 mod struct_mod {
53     pub struct A;
54     pub struct B;
55     pub mod inner_struct_mod {
56         pub struct C;
57     }
58
59     #[macro_export]
60     macro_rules! double_struct_import_test {
61         () => {
62             let _ = A;
63         };
64     }
65 }
66
67 fn main() {
68     foo();
69     multi_foo();
70     multi_bar();
71     multi_inner_mod::foo();
72     inner_mod::foo();
73     extern_foo();
74     inner_extern_bar();
75
76     let _ = A;
77     let _ = inner_struct_mod::C;
78     let _ = ExternA;
79     let _ = PreludeModAnywhere;
80
81     double_struct_import_test!();
82     double_struct_import_test!();
83 }
84
85 mod in_fn_test {
86     pub use self::inner_exported::*;
87     #[allow(unused_imports)]
88     pub(crate) use self::inner_exported2::*;
89
90     fn test_intern() {
91         use crate::fn_mod::*;
92
93         foo();
94     }
95
96     fn test_extern() {
97         use wildcard_imports_helper::inner::inner_for_self_import::{self, *};
98         use wildcard_imports_helper::*;
99
100         inner_for_self_import::inner_extern_foo();
101         inner_extern_foo();
102
103         extern_foo();
104
105         let _ = ExternA;
106     }
107
108     fn test_inner_nested() {
109         use self::{inner::*, inner2::*};
110
111         inner_foo();
112         inner_bar();
113     }
114
115     fn test_extern_reexported() {
116         use wildcard_imports_helper::*;
117
118         extern_exported();
119         let _ = ExternExportedStruct;
120         let _ = ExternExportedEnum::A;
121     }
122
123     mod inner_exported {
124         pub fn exported() {}
125         pub struct ExportedStruct;
126         pub enum ExportedEnum {
127             A,
128         }
129     }
130
131     mod inner_exported2 {
132         pub(crate) fn exported2() {}
133     }
134
135     mod inner {
136         pub fn inner_foo() {}
137     }
138
139     mod inner2 {
140         pub fn inner_bar() {}
141     }
142 }
143
144 fn test_reexported() {
145     use crate::in_fn_test::*;
146
147     exported();
148     let _ = ExportedStruct;
149     let _ = ExportedEnum::A;
150 }
151
152 #[rustfmt::skip]
153 fn test_weird_formatting() {
154     use crate:: in_fn_test::  * ;
155     use crate:: fn_mod::
156         *;
157
158     exported();
159     foo();
160 }
161
162 mod super_imports {
163     fn foofoo() {}
164
165     mod should_be_replaced {
166         use super::*;
167
168         fn with_super() {
169             let _ = foofoo();
170         }
171     }
172
173     mod test_should_pass {
174         use super::*;
175
176         fn with_super() {
177             let _ = foofoo();
178         }
179     }
180
181     mod test_should_pass_inside_function {
182         fn with_super_inside_function() {
183             use super::*;
184             let _ = foofoo();
185         }
186     }
187
188     mod test_should_pass_further_inside {
189         fn insidefoo() {}
190         mod inner {
191             use super::*;
192             fn with_super() {
193                 let _ = insidefoo();
194             }
195         }
196     }
197
198     mod should_be_replaced_futher_inside {
199         fn insidefoo() {}
200         mod inner {
201             use super::*;
202             fn with_super() {
203                 let _ = insidefoo();
204             }
205         }
206     }
207
208     mod use_explicit_should_be_replaced {
209         use super_imports::*;
210
211         fn with_explicit() {
212             let _ = foofoo();
213         }
214     }
215
216     mod use_double_super_should_be_replaced {
217         mod inner {
218             use super::super::*;
219
220             fn with_double_super() {
221                 let _ = foofoo();
222             }
223         }
224     }
225
226     mod use_super_explicit_should_be_replaced {
227         use super::super::super_imports::*;
228
229         fn with_super_explicit() {
230             let _ = foofoo();
231         }
232     }
233 }