fork/rust

git clone https://git.julia.blue/fork/rust

borsAuto merge of #103046 - JanBeh:PR_clarify_cmp_terminology, r=workingjubilee3bcad65fbf6

master
5.0 KiB247 linesraw
1//@edition:2015
2
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
9#![warn(clippy::wildcard_imports)]
10#![allow(unused, clippy::unnecessary_wraps, clippy::let_unit_value)]
11#![warn(unused_imports)]
12
13extern crate wildcard_imports_helper;
14
15use crate::fn_mod::foo;
16use crate::mod_mod::inner_mod;
17use crate::multi_fn_mod::{multi_bar, multi_foo, multi_inner_mod};
18#[macro_use]
19use crate::struct_mod::{A, inner_struct_mod};
20
21#[allow(unused_imports)]
22use wildcard_imports_helper::inner::inner_for_self_import;
23use wildcard_imports_helper::inner::inner_for_self_import::inner_extern_bar;
24use wildcard_imports_helper::{ExternA, extern_foo};
25
26use std::io::prelude::*;
27use wildcard_imports_helper::extern_prelude::v1::*;
28use wildcard_imports_helper::prelude::v1::*;
29
30struct ReadFoo;
31
32impl Read for ReadFoo {
33    fn read(&mut self, _buf: &mut [u8]) -> std::io::Result<usize> {
34        Ok(0)
35    }
36}
37
38mod fn_mod {
39    pub fn foo() {}
40}
41
42mod mod_mod {
43    pub mod inner_mod {
44        pub fn foo() {}
45    }
46}
47
48mod 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
57mod 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
72fn 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    let _ = ExternPreludeModAnywhere;
86
87    double_struct_import_test!();
88    double_struct_import_test!();
89}
90
91mod 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::foo;
98
99        foo();
100    }
101
102    fn test_extern() {
103        use wildcard_imports_helper::inner::inner_for_self_import::{self, inner_extern_foo};
104        use wildcard_imports_helper::{ExternA, extern_foo};
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        #[rustfmt::skip]
116        use self::{inner::inner_foo, inner2::inner_bar};
117
118        inner_foo();
119        inner_bar();
120    }
121
122    fn test_extern_reexported() {
123        use wildcard_imports_helper::{ExternExportedEnum, ExternExportedStruct, extern_exported};
124
125        extern_exported();
126        let _ = ExternExportedStruct;
127        let _ = ExternExportedEnum::A;
128    }
129
130    mod inner_exported {
131        pub fn exported() {}
132        pub struct ExportedStruct;
133        pub enum ExportedEnum {
134            A,
135        }
136    }
137
138    mod inner_exported2 {
139        pub(crate) fn exported2() {}
140    }
141
142    mod inner {
143        pub fn inner_foo() {}
144    }
145
146    mod inner2 {
147        pub fn inner_bar() {}
148    }
149}
150
151fn test_reexported() {
152    use crate::in_fn_test::{ExportedEnum, ExportedStruct, exported};
153
154    exported();
155    let _ = ExportedStruct;
156    let _ = ExportedEnum::A;
157}
158
159#[rustfmt::skip]
160fn test_weird_formatting() {
161    use crate:: in_fn_test::exported;
162    use crate:: fn_mod::foo;
163
164    exported();
165    foo();
166}
167
168mod super_imports {
169    fn foofoo() {}
170
171    mod should_be_replaced {
172        use super::foofoo;
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_further_inside {
205        fn insidefoo() {}
206        mod inner {
207            use super::insidefoo;
208            fn with_super() {
209                let _ = insidefoo();
210            }
211        }
212    }
213
214    mod use_explicit_should_be_replaced {
215        use crate::super_imports::foofoo;
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::foofoo;
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::foofoo;
234
235        fn with_super_explicit() {
236            let _ = foofoo();
237        }
238    }
239
240    mod attestation_should_be_replaced {
241        use super::foofoo;
242
243        fn with_explicit() {
244            let _ = foofoo();
245        }
246    }
247}