Don't bug if we're trying to cast dyn* to a nother type

This commit is contained in:
Michael Goulet 2022-12-14 18:00:56 +00:00
parent ba64ba8b0d
commit d0db3279ab
3 changed files with 23 additions and 1 deletions

View file

@ -847,13 +847,15 @@ impl<'a, 'tcx> CastCheck<'tcx> {
(Int(_) | Float, Int(_) | Float) => Ok(CastKind::NumericCast),
(_, DynStar) | (DynStar, _) => {
(_, DynStar) => {
if fcx.tcx.features().dyn_star {
bug!("should be handled by `try_coerce`")
} else {
Err(CastError::IllegalCast)
}
}
(DynStar, _) => Err(CastError::IllegalCast),
}
}

View file

@ -0,0 +1,11 @@
#![feature(dyn_star)]
#![allow(incomplete_features)]
trait Tr {}
fn f(x: dyn* Tr) -> usize {
x as usize
//~^ ERROR casting `(dyn* Tr + 'static)` as `usize` is invalid
}
fn main() {}

View file

@ -0,0 +1,9 @@
error[E0606]: casting `(dyn* Tr + 'static)` as `usize` is invalid
--> $DIR/dyn-to-rigid.rs:7:5
|
LL | x as usize
| ^^^^^^^^^^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0606`.