]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/wildcard_imports.fixed
Rollup merge of #84221 - ABouttefeux:generic-arg-elision, r=estebank
[rust.git] / src / tools / clippy / tests / ui / wildcard_imports.fixed
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 #![allow(clippy::unnecessary_wraps)]
8 #![warn(unused_imports)]
9
10 extern crate wildcard_imports_helper;
11
12 use crate::fn_mod::foo;
13 use crate::mod_mod::inner_mod;
14 use crate::multi_fn_mod::{multi_bar, multi_foo, multi_inner_mod};
15 #[macro_use]
16 use crate::struct_mod::{A, inner_struct_mod};
17
18 #[allow(unused_imports)]
19 use wildcard_imports_helper::inner::inner_for_self_import;
20 use wildcard_imports_helper::inner::inner_for_self_import::inner_extern_bar;
21 use wildcard_imports_helper::{ExternA, extern_foo};
22
23 use std::io::prelude::*;
24 use wildcard_imports_helper::prelude::v1::*;
25
26 struct ReadFoo;
27
28 impl Read for ReadFoo {
29     fn read(&mut self, _buf: &mut [u8]) -> std::io::Result<usize> {
30         Ok(0)
31     }
32 }
33
34 mod fn_mod {
35     pub fn foo() {}
36 }
37
38 mod mod_mod {
39     pub mod inner_mod {
40         pub fn foo() {}
41     }
42 }
43
44 mod multi_fn_mod {
45     pub fn multi_foo() {}
46     pub fn multi_bar() {}
47     pub fn multi_baz() {}
48     pub mod multi_inner_mod {
49         pub fn foo() {}
50     }
51 }
52
53 mod struct_mod {
54     pub struct A;
55     pub struct B;
56     pub mod inner_struct_mod {
57         pub struct C;
58     }
59
60     #[macro_export]
61     macro_rules! double_struct_import_test {
62         () => {
63             let _ = A;
64         };
65     }
66 }
67
68 fn main() {
69     foo();
70     multi_foo();
71     multi_bar();
72     multi_inner_mod::foo();
73     inner_mod::foo();
74     extern_foo();
75     inner_extern_bar();
76
77     let _ = A;
78     let _ = inner_struct_mod::C;
79     let _ = ExternA;
80     let _ = PreludeModAnywhere;
81
82     double_struct_import_test!();
83     double_struct_import_test!();
84 }
85
86 mod in_fn_test {
87     pub use self::inner_exported::*;
88     #[allow(unused_imports)]
89     pub(crate) use self::inner_exported2::*;
90
91     fn test_intern() {
92         use crate::fn_mod::foo;
93
94         foo();
95     }
96
97     fn test_extern() {
98         use wildcard_imports_helper::inner::inner_for_self_import::{self, inner_extern_foo};
99         use wildcard_imports_helper::{ExternA, extern_foo};
100
101         inner_for_self_import::inner_extern_foo();
102         inner_extern_foo();
103
104         extern_foo();
105
106         let _ = ExternA;
107     }
108
109     fn test_inner_nested() {
110         use self::{inner::inner_foo, inner2::inner_bar};
111
112         inner_foo();
113         inner_bar();
114     }
115
116     fn test_extern_reexported() {
117         use wildcard_imports_helper::{ExternExportedEnum, ExternExportedStruct, extern_exported};
118
119         extern_exported();
120         let _ = ExternExportedStruct;
121         let _ = ExternExportedEnum::A;
122     }
123
124     mod inner_exported {
125         pub fn exported() {}
126         pub struct ExportedStruct;
127         pub enum ExportedEnum {
128             A,
129         }
130     }
131
132     mod inner_exported2 {
133         pub(crate) fn exported2() {}
134     }
135
136     mod inner {
137         pub fn inner_foo() {}
138     }
139
140     mod inner2 {
141         pub fn inner_bar() {}
142     }
143 }
144
145 fn test_reexported() {
146     use crate::in_fn_test::{ExportedEnum, ExportedStruct, exported};
147
148     exported();
149     let _ = ExportedStruct;
150     let _ = ExportedEnum::A;
151 }
152
153 #[rustfmt::skip]
154 fn test_weird_formatting() {
155     use crate:: in_fn_test::exported;
156     use crate:: fn_mod::foo;
157
158     exported();
159     foo();
160 }
161
162 mod super_imports {
163     fn foofoo() {}
164
165     mod should_be_replaced {
166         use super::foofoo;
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::insidefoo;
202             fn with_super() {
203                 let _ = insidefoo();
204             }
205         }
206     }
207
208     mod use_explicit_should_be_replaced {
209         use super_imports::foofoo;
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::foofoo;
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::foofoo;
228
229         fn with_super_explicit() {
230             let _ = foofoo();
231         }
232     }
233 }