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