Description
As part of the coercion logic, we sometimes invoke coerce_unsized
:
rust/src/librustc_typeck/check/coercion.rs
Line 457 in cb1ce7d
This would e.g. coerce from &[T; 32]
to &[T]
or from Arc<T>
to Arc<dyn Trait>
where T: Trait
. To decide whether or not we are going to do this, we want to check if Arc<T>: CoerceUnsized<Arc<dyn Trait>>
is implemented (or something like that). We do this in this funky little loop here:
rust/src/librustc_typeck/check/coercion.rs
Lines 538 to 552 in cb1ce7d
This kind of pulls out all the (transitive) requires to prove CoerceUnsized
and ignores the rest. However, if we ever hope to define coercions in terms of the trait system, what we really ought to be doing is using an evaluate_obligation
check.
Hopefully we can get away with this backwards compatibly.
@eddyb told me at some point -- iirc -- that the reason this loop exists is for diagnostics. So making this change may require some work on that point.
cc @leodasvacas @mikeyhew