diff --git a/clippy_lints/src/box_default.rs b/clippy_lints/src/box_default.rs index f35a79dcc73..4c0ccd08ef2 100644 --- a/clippy_lints/src/box_default.rs +++ b/clippy_lints/src/box_default.rs @@ -88,7 +88,7 @@ fn is_vec_expn(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { impl<'tcx> Visitor<'tcx> for InferVisitor { fn visit_ty(&mut self, t: &rustc_hir::Ty<'_>) { - self.0 |= matches!(t.kind, TyKind::Infer); + self.0 |= matches!(t.kind, TyKind::Infer | TyKind::OpaqueDef(..) | TyKind::TraitObject(..)); if !self.0 { walk_ty(self, t); } diff --git a/tests/ui/box_default.fixed b/tests/ui/box_default.fixed index 7fbb272ce5a..911fa856aa0 100644 --- a/tests/ui/box_default.fixed +++ b/tests/ui/box_default.fixed @@ -40,4 +40,18 @@ fn ret_ty_fn() -> Box { } #[allow(clippy::boxed_local)] -fn call_ty_fn(_b: Box) {} +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(); +} diff --git a/tests/ui/box_default.rs b/tests/ui/box_default.rs index 64c4f3887af..20019c2ee5a 100644 --- a/tests/ui/box_default.rs +++ b/tests/ui/box_default.rs @@ -40,4 +40,18 @@ fn ret_ty_fn() -> Box { } #[allow(clippy::boxed_local)] -fn call_ty_fn(_b: Box) {} +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::new(ImplementsDefault::default()); +} diff --git a/tests/ui/box_default.stderr b/tests/ui/box_default.stderr index 313255fc950..5ea410331af 100644 --- a/tests/ui/box_default.stderr +++ b/tests/ui/box_default.stderr @@ -78,5 +78,11 @@ error: `Box::new(_)` of default value LL | Box::new(bool::default()) | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::::default()` -error: aborting due to 13 previous errors +error: `Box::new(_)` of default value + --> $DIR/box_default.rs:56:28 + | +LL | let _: Box = Box::new(ImplementsDefault::default()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::::default()` + +error: aborting due to 14 previous errors