fix box-default ignoring trait objects' types

This commit is contained in:
Andre Bogus 2022-10-10 13:05:07 +02:00
parent 272bbfb857
commit bd61fdbd5f
4 changed files with 38 additions and 4 deletions

View File

@ -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);
}

View File

@ -40,4 +40,18 @@ fn ret_ty_fn() -> Box<bool> {
}
#[allow(clippy::boxed_local)]
fn call_ty_fn(_b: Box<u8>) {}
fn call_ty_fn(_b: Box<u8>) {
issue_9621_dyn_trait();
}
use std::io::{Read, Result};
impl Read for ImplementsDefault {
fn read(&mut self, _: &mut [u8]) -> Result<usize> {
Ok(0)
}
}
fn issue_9621_dyn_trait() {
let _: Box<dyn Read> = Box::<ImplementsDefault>::default();
}

View File

@ -40,4 +40,18 @@ fn ret_ty_fn() -> Box<bool> {
}
#[allow(clippy::boxed_local)]
fn call_ty_fn(_b: Box<u8>) {}
fn call_ty_fn(_b: Box<u8>) {
issue_9621_dyn_trait();
}
use std::io::{Read, Result};
impl Read for ImplementsDefault {
fn read(&mut self, _: &mut [u8]) -> Result<usize> {
Ok(0)
}
}
fn issue_9621_dyn_trait() {
let _: Box<dyn Read> = Box::new(ImplementsDefault::default());
}

View File

@ -78,5 +78,11 @@ error: `Box::new(_)` of default value
LL | Box::new(bool::default())
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::<bool>::default()`
error: aborting due to 13 previous errors
error: `Box::new(_)` of default value
--> $DIR/box_default.rs:56:28
|
LL | let _: Box<dyn Read> = Box::new(ImplementsDefault::default());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::<ImplementsDefault>::default()`
error: aborting due to 14 previous errors