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