#![warn(clippy::box_default)] #![allow(clippy::default_constructed_unit_structs)] #[derive(Default)] struct ImplementsDefault; struct OwnDefault; impl OwnDefault { fn default() -> Self { Self } } macro_rules! outer { ($e: expr) => { $e }; } fn main() { let _string: Box = Box::default(); let _byte = Box::::default(); let _vec = Box::>::default(); let _impl = Box::::default(); let _impl2 = Box::::default(); let _impl3: Box = Box::default(); let _own = Box::new(OwnDefault::default()); // should not lint let _in_macro = outer!(Box::::default()); let _string_default = outer!(Box::::default()); let _vec2: Box> = Box::default(); let _vec3: Box> = Box::default(); let _vec4: Box<_> = Box::>::default(); let _more = ret_ty_fn(); call_ty_fn(Box::default()); issue_10381(); // `Box::>::default()` would be valid here, but not `Box::default()` or // `Box::::default()` // // Would have a suggestion after https://github.com/rust-lang/rust/blob/fdd030127cc68afec44a8d3f6341525dd34e50ae/compiler/rustc_middle/src/ty/diagnostics.rs#L554-L563 let mut unnameable = Box::new(Option::default()); let _ = unnameable.insert(|| {}); } fn ret_ty_fn() -> Box { Box::::default() } #[allow(clippy::boxed_local)] fn call_ty_fn(_b: Box) { issue_9621_dyn_trait(); } use std::io::{Read, Result}; impl Read for ImplementsDefault { fn read(&mut self, _: &mut [u8]) -> Result { Ok(0) } } fn issue_9621_dyn_trait() { let _: Box = Box::::default(); issue_10089(); } fn issue_10089() { let _closure = || { #[derive(Default)] struct WeirdPathed; let _ = Box::::default(); }; } fn issue_10381() { #[derive(Default)] pub struct Foo {} pub trait Bar {} impl Bar for Foo {} fn maybe_get_bar(i: u32) -> Option> { if i % 2 == 0 { Some(Box::::default()) } else { None } } assert!(maybe_get_bar(2).is_some()); } #[allow(unused)] fn issue_11868() { fn foo(_: &mut Vec) {} macro_rules! bar { ($baz:expr) => { Box::leak(Box::new($baz)) }; } foo(bar!(vec![])); foo(bar!(vec![1])); }