Skip to content

Commit 86bbc20

Browse files
authored
Rollup merge of #105710 - compiler-errors:dyn-star-rigid-cast, r=eholk
Don't bug if we're trying to cast `dyn*` to another type Fixes #105097
2 parents 505848a + d0db327 commit 86bbc20

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

compiler/rustc_hir_typeck/src/cast.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -847,13 +847,15 @@ impl<'a, 'tcx> CastCheck<'tcx> {
847847

848848
(Int(_) | Float, Int(_) | Float) => Ok(CastKind::NumericCast),
849849

850-
(_, DynStar) | (DynStar, _) => {
850+
(_, DynStar) => {
851851
if fcx.tcx.features().dyn_star {
852852
bug!("should be handled by `try_coerce`")
853853
} else {
854854
Err(CastError::IllegalCast)
855855
}
856856
}
857+
858+
(DynStar, _) => Err(CastError::IllegalCast),
857859
}
858860
}
859861

src/test/ui/dyn-star/dyn-to-rigid.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#![feature(dyn_star)]
2+
#![allow(incomplete_features)]
3+
4+
trait Tr {}
5+
6+
fn f(x: dyn* Tr) -> usize {
7+
x as usize
8+
//~^ ERROR casting `(dyn* Tr + 'static)` as `usize` is invalid
9+
}
10+
11+
fn main() {}
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0606]: casting `(dyn* Tr + 'static)` as `usize` is invalid
2+
--> $DIR/dyn-to-rigid.rs:7:5
3+
|
4+
LL | x as usize
5+
| ^^^^^^^^^^
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0606`.

0 commit comments

Comments
 (0)