2 #![warn(clippy::box_default)]
5 struct ImplementsDefault;
10 fn default() -> Self {
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()));
38 fn ret_ty_fn() -> Box<bool> {
39 Box::new(bool::default())
42 #[allow(clippy::boxed_local)]
43 fn call_ty_fn(_b: Box<u8>) {
44 issue_9621_dyn_trait();
47 use std::io::{Read, Result};
49 impl Read for ImplementsDefault {
50 fn read(&mut self, _: &mut [u8]) -> Result<usize> {
55 fn issue_9621_dyn_trait() {
56 let _: Box<dyn Read> = Box::new(ImplementsDefault::default());