]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/box_default.rs
Rollup merge of #102072 - scottmcm:ptr-alignment-type, r=thomcc
[rust.git] / src / tools / clippy / tests / ui / box_default.rs
1 #![warn(clippy::box_default)]
2
3 #[derive(Default)]
4 struct ImplementsDefault;
5
6 struct OwnDefault;
7
8 impl OwnDefault {
9     fn default() -> Self {
10         Self
11     }
12 }
13
14 macro_rules! outer {
15     ($e: expr) => {
16         $e
17     };
18 }
19
20 fn main() {
21     let _string: Box<String> = Box::new(Default::default());
22     let _byte = Box::new(u8::default());
23     let _vec = Box::new(Vec::<u8>::new());
24     let _impl = Box::new(ImplementsDefault::default());
25     let _impl2 = Box::new(<ImplementsDefault as Default>::default());
26     let _impl3: Box<ImplementsDefault> = Box::new(Default::default());
27     let _own = Box::new(OwnDefault::default()); // should not lint
28     let _in_macro = outer!(Box::new(String::new()));
29     // false negative: default is from different expansion
30     let _vec2: Box<Vec<ImplementsDefault>> = Box::new(vec![]);
31 }