Don't ICE on illegal dyn* casts
This commit is contained in:
@@ -721,13 +721,11 @@ impl<'a, 'tcx> CastCheck<'tcx> {
|
||||
use rustc_middle::ty::cast::IntTy::*;
|
||||
|
||||
if self.cast_ty.is_dyn_star() {
|
||||
if fcx.tcx.features().dyn_star() {
|
||||
span_bug!(self.span, "should be handled by `coerce`");
|
||||
} else {
|
||||
// Report "casting is invalid" rather than "non-primitive cast"
|
||||
// if the feature is not enabled.
|
||||
return Err(CastError::IllegalCast);
|
||||
}
|
||||
// This coercion will fail if the feature is not enabled, OR
|
||||
// if the coercion is (currently) illegal (e.g. `dyn* Foo + Send`
|
||||
// to `dyn* Foo`). Report "casting is invalid" rather than
|
||||
// "non-primitive cast".
|
||||
return Err(CastError::IllegalCast);
|
||||
}
|
||||
|
||||
let (t_from, t_cast) = match (CastTy::from_ty(self.expr_ty), CastTy::from_ty(self.cast_ty))
|
||||
|
||||
@@ -737,8 +737,10 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
|
||||
return Err(TypeError::Mismatch);
|
||||
}
|
||||
|
||||
if let ty::Dynamic(a_data, _, _) = a.kind()
|
||||
&& let ty::Dynamic(b_data, _, _) = b.kind()
|
||||
// FIXME(dyn_star): We should probably allow things like casting from
|
||||
// `dyn* Foo + Send` to `dyn* Foo`.
|
||||
if let ty::Dynamic(a_data, _, ty::DynStar) = a.kind()
|
||||
&& let ty::Dynamic(b_data, _, ty::DynStar) = b.kind()
|
||||
&& a_data.principal_def_id() == b_data.principal_def_id()
|
||||
{
|
||||
return self.unify_and(a, b, |_| vec![]);
|
||||
|
||||
Reference in New Issue
Block a user