]> git.lizzy.rs Git - rust.git/blob - tests/ui/box_default.rs
Move MSRV tests into the lint specific test files
[rust.git] / tests / ui / box_default.rs
1 // run-rustfix
2 #![warn(clippy::box_default)]
3
4 #[derive(Default)]
5 struct ImplementsDefault;
6
7 struct OwnDefault;
8
9 impl OwnDefault {
10     fn default() -> Self {
11         Self
12     }
13 }
14
15 macro_rules! outer {
16     ($e: expr) => {
17         $e
18     };
19 }
20
21 fn main() {
22     let _string: Box<String> = Box::new(Default::default());
23     let _byte = Box::new(u8::default());
24     let _vec = Box::new(Vec::<u8>::new());
25     let _impl = Box::new(ImplementsDefault::default());
26     let _impl2 = Box::new(<ImplementsDefault as Default>::default());
27     let _impl3: Box<ImplementsDefault> = Box::new(Default::default());
28     let _own = Box::new(OwnDefault::default()); // should not lint
29     let _in_macro = outer!(Box::new(String::new()));
30     let _string_default = outer!(Box::new(String::from("")));
31     let _vec2: Box<Vec<ImplementsDefault>> = Box::new(vec![]);
32     let _vec3: Box<Vec<bool>> = Box::new(Vec::from([]));
33     let _vec4: Box<_> = Box::new(Vec::from([false; 0]));
34     let _more = ret_ty_fn();
35     call_ty_fn(Box::new(u8::default()));
36 }
37
38 fn ret_ty_fn() -> Box<bool> {
39     Box::new(bool::default())
40 }
41
42 #[allow(clippy::boxed_local)]
43 fn call_ty_fn(_b: Box<u8>) {}