Skip to content

Commit aa13c44

Browse files
committed
Account for object unsafe impl Trait on dyn Trait {}
1 parent 6c77456 commit aa13c44

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

compiler/rustc_infer/src/traits/error_reporting/mod.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_errors::{struct_span_err, DiagnosticBuilder, ErrorGuaranteed, MultiSpa
66
use rustc_hir as hir;
77
use rustc_hir::def_id::{DefId, LocalDefId};
88
use rustc_middle::ty::print::with_no_trimmed_paths;
9-
use rustc_middle::ty::TyCtxt;
9+
use rustc_middle::ty::{self, TyCtxt};
1010
use rustc_span::Span;
1111
use std::fmt;
1212
use std::iter;
@@ -112,7 +112,14 @@ pub fn report_object_safety_error<'tcx>(
112112

113113
let impls_of = tcx.trait_impls_of(trait_def_id);
114114
let impls = if impls_of.blanket_impls().is_empty() {
115-
impls_of.non_blanket_impls().values().flatten().collect::<Vec<_>>()
115+
impls_of
116+
.non_blanket_impls()
117+
.values()
118+
.flatten()
119+
.filter(|def_id| {
120+
!matches!(tcx.type_of(*def_id).instantiate_identity().kind(), ty::Dynamic(..))
121+
})
122+
.collect::<Vec<_>>()
116123
} else {
117124
vec![]
118125
};

tests/ui/coherence/coherence-impl-trait-for-trait-object-safe.stderr

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ LL | trait NotObjectSafe { fn eq(&self, other: Self); }
1212
| |
1313
| this trait cannot be made into an object...
1414
= help: consider moving `eq` to another trait
15-
= help: only type `(dyn NotObjectSafe + 'static)` implements the trait, consider using it directly instead
1615

1716
error: aborting due to previous error
1817

0 commit comments

Comments
 (0)