1
Fork 0

Rollup merge of #135042 - lukas-code:taint-dyn-incompat, r=compiler-errors

taint fcx on selection errors during unsizing

With `feature(dyn_compatible_for_dispatch)` we only check for dyn-compatibility by checking the `T: Unsize<dyn Trait>` predicate during the unsizing coercions checks. If the predicate doesn't hold, we emit an error, but pretend the coercion succeeded to prevent further errors. To prevent const eval from attempting to actually perform this coercion, we need to taint the fcx after reporting the trait errors in the coercion check.

fixes https://github.com/rust-lang/rust/issues/135021
fixes https://github.com/rust-lang/rust/issues/130521
This commit is contained in:
Matthias Krüger 2025-01-03 07:57:26 +01:00 committed by GitHub
commit e0f4dc955a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 119 additions and 14 deletions

View file

@ -666,7 +666,12 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
// Dyn-compatibility violations or miscellaneous.
Err(err) => {
self.err_ctxt().report_selection_error(obligation.clone(), &obligation, &err);
let guar = self.err_ctxt().report_selection_error(
obligation.clone(),
&obligation,
&err,
);
self.fcx.set_tainted_by_errors(guar);
// Treat this like an obligation and follow through
// with the unsizing - the lack of a coercion should
// be silent, as it causes a type mismatch later.