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