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