Skip to content
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

Check dyn flavor before registering upcast goal on wide pointer cast in MIR typeck #137637

Merged
merged 1 commit into from
Mar 7, 2025
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: 2 additions & 2 deletions compiler/rustc_borrowck/src/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2120,8 +2120,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
//
// Note that other checks (such as denying `dyn Send` -> `dyn
// Debug`) are in `rustc_hir_typeck`.
if let ty::Dynamic(src_tty, _src_lt, _) = *src_tail.kind()
&& let ty::Dynamic(dst_tty, dst_lt, _) = *dst_tail.kind()
if let ty::Dynamic(src_tty, _src_lt, ty::Dyn) = *src_tail.kind()
&& let ty::Dynamic(dst_tty, dst_lt, ty::Dyn) = *dst_tail.kind()
&& src_tty.principal().is_some()
&& dst_tty.principal().is_some()
{
Expand Down
19 changes: 19 additions & 0 deletions tests/ui/traits/trait-upcasting/dyn-to-dyn-star.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// While somewhat nonsensical, this is a cast from a wide pointer to a thin pointer.
// Thus, we don't need to check an unsize goal here; there isn't any vtable casting
// happening at all.

// Regression test for <https://github.com/rust-lang/rust/issues/137579>.

//@ check-pass

#![allow(incomplete_features)]
#![feature(dyn_star)]

trait Foo {}
trait Bar {}

fn cast(x: *const dyn Foo) {
x as *const dyn* Bar;
}

fn main() {}
Loading