diff --git a/rust-version b/rust-version index 45dbb37c86..e3e71f5c2f 100644 --- a/rust-version +++ b/rust-version @@ -1 +1 @@ -9c20b2a8cc7588decb6de25ac6a7912dcef24d65 +e1b28cd2f16bd5b832183d7968cae3bb9213e78d diff --git a/tests/fail/dyn-upcast-trait-mismatch.rs b/tests/fail/dyn-upcast-trait-mismatch.rs index f53e9a03f4..648ac07c43 100644 --- a/tests/fail/dyn-upcast-trait-mismatch.rs +++ b/tests/fail/dyn-upcast-trait-mismatch.rs @@ -51,8 +51,7 @@ impl Baz for i32 { fn main() { let baz: &dyn Baz = &1; - // We already fail on the implicit upcast inserted here. let baz_fake: &dyn Bar = unsafe { std::mem::transmute(baz) }; - //~^ERROR: upcast on a pointer whose vtable does not match its type let _err = baz_fake as &dyn Foo; + //~^ERROR: upcast on a pointer whose vtable does not match its type } diff --git a/tests/fail/dyn-upcast-trait-mismatch.stderr b/tests/fail/dyn-upcast-trait-mismatch.stderr index 0e5e22b9b4..cdd1421a66 100644 --- a/tests/fail/dyn-upcast-trait-mismatch.stderr +++ b/tests/fail/dyn-upcast-trait-mismatch.stderr @@ -1,8 +1,8 @@ error: Undefined Behavior: upcast on a pointer whose vtable does not match its type --> $DIR/dyn-upcast-trait-mismatch.rs:LL:CC | -LL | let baz_fake: &dyn Bar = unsafe { std::mem::transmute(baz) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^ upcast on a pointer whose vtable does not match its type +LL | let _err = baz_fake as &dyn Foo; + | ^^^^^^^^ upcast on a pointer whose vtable does not match its type | = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information diff --git a/tests/pass/dyn-upcast.rs b/tests/pass/dyn-upcast.rs index 030c2a7cbf..8432012a9b 100644 --- a/tests/pass/dyn-upcast.rs +++ b/tests/pass/dyn-upcast.rs @@ -6,6 +6,15 @@ fn main() { diamond(); struct_(); replace_vptr(); + vtable_mismatch_nop_cast(); +} + +fn vtable_mismatch_nop_cast() { + let ptr: &dyn std::fmt::Display = &0; + // Even though the vtable is for the wrong trait, this cast doesn't actually change the needed + // vtable so it should still be allowed. + let ptr: *const (dyn std::fmt::Debug + Send + Sync) = unsafe { std::mem::transmute(ptr) }; + let _ptr2 = ptr as *const dyn std::fmt::Debug; } fn basic() {