Skip to content

Commit adff091

Browse files
Check dyn flavor before registering upcast goal on wide pointer cast in MIR typeck
1 parent 8c39296 commit adff091

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
@@ -2120,8 +2120,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
21202120
//
21212121
// Note that other checks (such as denying `dyn Send` -> `dyn
21222122
// Debug`) are in `rustc_hir_typeck`.
2123-
if let ty::Dynamic(src_tty, _src_lt, _) = *src_tail.kind()
2124-
&& let ty::Dynamic(dst_tty, dst_lt, _) = *dst_tail.kind()
2123+
if let ty::Dynamic(src_tty, _src_lt, ty::Dyn) = *src_tail.kind()
2124+
&& let ty::Dynamic(dst_tty, dst_lt, ty::Dyn) = *dst_tail.kind()
21252125
&& src_tty.principal().is_some()
21262126
&& dst_tty.principal().is_some()
21272127
{
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)