Skip to content

Commit bb9255b

Browse files
Check dyn flavor before registering upcast goal on wide pointer cast in MIR typeck
1 parent c51b9b6 commit bb9255b

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

compiler/rustc_borrowck/src/type_check/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2121,8 +2121,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
21212121
//
21222122
// Note that other checks (such as denying `dyn Send` -> `dyn
21232123
// Debug`) are in `rustc_hir_typeck`.
2124-
if let ty::Dynamic(src_tty, ..) = src_tail.kind()
2125-
&& let ty::Dynamic(dst_tty, ..) = dst_tail.kind()
2124+
if let ty::Dynamic(src_tty, _, ty::Dyn) = src_tail.kind()
2125+
&& let ty::Dynamic(dst_tty, _, ty::Dyn) = dst_tail.kind()
21262126
&& src_tty.principal().is_some()
21272127
&& dst_tty.principal().is_some()
21282128
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// While somewhat nonsensical, this is a cast from a wide pointer to a thin pointer.
2+
// Thus, we don't need to check an unsize goal here; there isn't any vtable casting
3+
// happening at all.
4+
5+
// Regression test for <https://github.com/rust-lang/rust/issues/137579>.
6+
7+
//@ check-pass
8+
9+
#![allow(incomplete_features)]
10+
#![feature(dyn_star)]
11+
12+
trait Foo {}
13+
trait Bar {}
14+
15+
fn cast(x: *const dyn Foo) {
16+
x as *const dyn* Bar;
17+
}
18+
19+
fn main() {}

0 commit comments

Comments
 (0)