Skip to content

Don't bug if we're trying to cast dyn* to another type #105710

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion compiler/rustc_hir_typeck/src/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}

Expand Down
11 changes: 11 additions & 0 deletions src/test/ui/dyn-star/dyn-to-rigid.rs
Original file line number Diff line number Diff line change
@@ -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() {}
9 changes: 9 additions & 0 deletions src/test/ui/dyn-star/dyn-to-rigid.stderr
Original file line number Diff line number Diff line change
@@ -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`.