]> git.proxmox.com Git - rustc.git/blob - src/tools/clippy/tests/ui/wildcard_imports_2021.edition2018.fixed
New upstream version 1.75.0+dfsg1
[rustc.git] / src / tools / clippy / tests / ui / wildcard_imports_2021.edition2018.fixed
1 //@revisions: edition2018 edition2021
2 //@[edition2018] edition:2018
3 //@[edition2021] edition:2021
4
5 //@aux-build:wildcard_imports_helper.rs
6
7 #![warn(clippy::wildcard_imports)]
8 #![allow(unused, clippy::unnecessary_wraps, clippy::let_unit_value)]
9 #![warn(unused_imports)]
10
11 extern crate wildcard_imports_helper;
12
13 use crate::fn_mod::foo;
14 use crate::mod_mod::inner_mod;
15 use crate::multi_fn_mod::{multi_bar, multi_foo, multi_inner_mod};
16 use crate::struct_mod::{A, inner_struct_mod};
17
18 #[allow(unused_imports)]
19 use wildcard_imports_helper::inner::inner_for_self_import::inner_extern_bar;
20 use wildcard_imports_helper::prelude::v1::*;
21 use wildcard_imports_helper::{ExternA, extern_foo};
22
23 use std::io::prelude::*;
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 // issue 9942
68 mod underscore_mod {
69 // allow use of `deref` so that `clippy --fix` includes `Deref`.
70 #![allow(noop_method_call)]
71
72 mod exports_underscore {
73 pub use std::ops::Deref as _;
74 pub fn dummy() {}
75 }
76
77 mod exports_underscore_ish {
78 pub use std::ops::Deref as _Deref;
79 pub fn dummy() {}
80 }
81
82 fn does_not_lint() {
83 use exports_underscore::*;
84 let _ = (&0).deref();
85 dummy();
86 }
87
88 fn does_lint() {
89 use exports_underscore_ish::{_Deref, dummy};
90 let _ = (&0).deref();
91 dummy();
92 }
93 }
94
95 fn main() {
96 foo();
97 multi_foo();
98 multi_bar();
99 multi_inner_mod::foo();
100 inner_mod::foo();
101 extern_foo();
102 inner_extern_bar();
103
104 let _ = A;
105 let _ = inner_struct_mod::C;
106 let _ = ExternA;
107 let _ = PreludeModAnywhere;
108
109 double_struct_import_test!();
110 double_struct_import_test!();
111 }
112
113 mod in_fn_test {
114 pub use self::inner_exported::*;
115 #[allow(unused_imports)]
116 pub(crate) use self::inner_exported2::*;
117
118 fn test_intern() {
119 use crate::fn_mod::foo;
120
121 foo();
122 }
123
124 fn test_extern() {
125 use wildcard_imports_helper::inner::inner_for_self_import::{self, inner_extern_foo};
126 use wildcard_imports_helper::{ExternA, extern_foo};
127
128 inner_for_self_import::inner_extern_foo();
129 inner_extern_foo();
130
131 extern_foo();
132
133 let _ = ExternA;
134 }
135
136 fn test_inner_nested() {
137 #[rustfmt::skip]
138 use self::{inner::inner_foo, inner2::inner_bar};
139
140 inner_foo();
141 inner_bar();
142 }
143
144 fn test_extern_reexported() {
145 use wildcard_imports_helper::{ExternExportedEnum, ExternExportedStruct, extern_exported};
146
147 extern_exported();
148 let _ = ExternExportedStruct;
149 let _ = ExternExportedEnum::A;
150 }
151
152 mod inner_exported {
153 pub fn exported() {}
154 pub struct ExportedStruct;
155 pub enum ExportedEnum {
156 A,
157 }
158 }
159
160 mod inner_exported2 {
161 pub(crate) fn exported2() {}
162 }
163
164 mod inner {
165 pub fn inner_foo() {}
166 }
167
168 mod inner2 {
169 pub fn inner_bar() {}
170 }
171 }
172
173 fn test_reexported() {
174 use crate::in_fn_test::{ExportedEnum, ExportedStruct, exported};
175
176 exported();
177 let _ = ExportedStruct;
178 let _ = ExportedEnum::A;
179 }
180
181 #[rustfmt::skip]
182 fn test_weird_formatting() {
183 use crate:: in_fn_test::exported;
184 use crate:: fn_mod::foo;
185
186 exported();
187 foo();
188 }
189
190 mod super_imports {
191 fn foofoo() {}
192
193 mod should_be_replaced {
194 use super::foofoo;
195
196 fn with_super() {
197 let _ = foofoo();
198 }
199 }
200
201 mod test_should_pass {
202 use super::*;
203
204 fn with_super() {
205 let _ = foofoo();
206 }
207 }
208
209 mod test_should_pass_inside_function {
210 fn with_super_inside_function() {
211 use super::*;
212 let _ = foofoo();
213 }
214 }
215
216 mod test_should_pass_further_inside {
217 fn insidefoo() {}
218 mod inner {
219 use super::*;
220 fn with_super() {
221 let _ = insidefoo();
222 }
223 }
224 }
225
226 mod should_be_replaced_further_inside {
227 fn insidefoo() {}
228 mod inner {
229 use super::insidefoo;
230 fn with_super() {
231 let _ = insidefoo();
232 }
233 }
234 }
235
236 mod use_explicit_should_be_replaced {
237 use crate::super_imports::foofoo;
238
239 fn with_explicit() {
240 let _ = foofoo();
241 }
242 }
243
244 mod use_double_super_should_be_replaced {
245 mod inner {
246 use super::super::foofoo;
247
248 fn with_double_super() {
249 let _ = foofoo();
250 }
251 }
252 }
253
254 mod use_super_explicit_should_be_replaced {
255 use super::super::super_imports::foofoo;
256
257 fn with_super_explicit() {
258 let _ = foofoo();
259 }
260 }
261
262 mod attestation_should_be_replaced {
263 use super::foofoo;
264
265 fn with_explicit() {
266 let _ = foofoo();
267 }
268 }
269 }