]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/wildcard_imports.fixed
Auto merge of #78448 - rylev:cache-foreign_modules, r=wesleywiser
[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 #![warn(unused_imports)]
8
9 extern crate wildcard_imports_helper;
10
11 use crate::fn_mod::foo;
12 use crate::mod_mod::inner_mod;
13 use crate::multi_fn_mod::{multi_bar, multi_foo, multi_inner_mod};
14 #[macro_use]
15 use crate::struct_mod::{A, inner_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::inner_extern_bar;
20 use wildcard_imports_helper::{ExternA, extern_foo};
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::foo;
92
93         foo();
94     }
95
96     fn test_extern() {
97         use wildcard_imports_helper::inner::inner_for_self_import::{self, inner_extern_foo};
98         use wildcard_imports_helper::{ExternA, extern_foo};
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::inner_foo, inner2::inner_bar};
110
111         inner_foo();
112         inner_bar();
113     }
114
115     fn test_extern_reexported() {
116         use wildcard_imports_helper::{ExternExportedEnum, ExternExportedStruct, extern_exported};
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::{ExportedEnum, ExportedStruct, exported};
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::exported;
155     use crate:: fn_mod::foo;
156
157     exported();
158     foo();
159 }
160
161 mod super_imports {
162     fn foofoo() {}
163
164     mod should_be_replaced {
165         use super::foofoo;
166
167         fn with_super() {
168             let _ = foofoo();
169         }
170     }
171
172     mod test_should_pass {
173         use super::*;
174
175         fn with_super() {
176             let _ = foofoo();
177         }
178     }
179
180     mod test_should_pass_inside_function {
181         fn with_super_inside_function() {
182             use super::*;
183             let _ = foofoo();
184         }
185     }
186
187     mod test_should_pass_further_inside {
188         fn insidefoo() {}
189         mod inner {
190             use super::*;
191             fn with_super() {
192                 let _ = insidefoo();
193             }
194         }
195     }
196
197     mod should_be_replaced_futher_inside {
198         fn insidefoo() {}
199         mod inner {
200             use super::insidefoo;
201             fn with_super() {
202                 let _ = insidefoo();
203             }
204         }
205     }
206
207     mod use_explicit_should_be_replaced {
208         use super_imports::foofoo;
209
210         fn with_explicit() {
211             let _ = foofoo();
212         }
213     }
214
215     mod use_double_super_should_be_replaced {
216         mod inner {
217             use super::super::foofoo;
218
219             fn with_double_super() {
220                 let _ = foofoo();
221             }
222         }
223     }
224
225     mod use_super_explicit_should_be_replaced {
226         use super::super::super_imports::foofoo;
227
228         fn with_super_explicit() {
229             let _ = foofoo();
230         }
231     }
232 }