Skip to content

Commit f68fc2e

Browse files
committed
Auto merge of #3506 - rust-lang:rustup-2024-04-24, r=RalfJung
Automatic Rustup
2 parents ed5e0e6 + e32bf5f commit f68fc2e

16 files changed

+120
-34
lines changed

rust-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
aca749eefceaed0cda19a7ec5e472fce9387bc00
1+
c1feb3eceef7d5f0126c309a87062cf413fe0a25

src/shims/intrinsics/simd.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
163163
}
164164
}
165165
Op::Numeric(name) => {
166-
this.numeric_intrinsic(name, op.to_scalar(), op.layout)?
166+
this.numeric_intrinsic(name, op.to_scalar(), op.layout, op.layout)?
167167
}
168168
};
169169
this.write_scalar(val, &dest)?;

tests/fail/dyn-call-trait-mismatch.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Validation stops this too early.
2+
//@compile-flags: -Zmiri-disable-validation
3+
14
trait T1 {
25
#[allow(dead_code)]
36
fn method1(self: Box<Self>);
@@ -13,5 +16,5 @@ impl T1 for i32 {
1316
fn main() {
1417
let r = Box::new(0) as Box<dyn T1>;
1518
let r2: Box<dyn T2> = unsafe { std::mem::transmute(r) };
16-
r2.method2(); //~ERROR: call on a pointer whose vtable does not match its type
19+
r2.method2(); //~ERROR: using vtable for trait `T1` but trait `T2` was expected
1720
}

tests/fail/dyn-call-trait-mismatch.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error: Undefined Behavior: `dyn` call on a pointer whose vtable does not match its type
1+
error: Undefined Behavior: using vtable for trait `T1` but trait `T2` was expected
22
--> $DIR/dyn-call-trait-mismatch.rs:LL:CC
33
|
44
LL | r2.method2();
5-
| ^^^^^^^^^^^^ `dyn` call on a pointer whose vtable does not match its type
5+
| ^^^^^^^^^^^^ using vtable for trait `T1` but trait `T2` was expected
66
|
77
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
88
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// This upcast is currently forbidden because it involves an invalid value.
2+
// However, if in the future we relax the validity requirements for raw pointer vtables,
3+
// we could consider allowing this again -- the cast itself isn't doing anything wrong,
4+
// only the transmutes needed to set up the testcase are wrong.
5+
6+
use std::fmt;
7+
8+
fn main() {
9+
// vtable_mismatch_nop_cast
10+
let ptr: &dyn fmt::Display = &0;
11+
let ptr: *const (dyn fmt::Debug + Send + Sync) = unsafe { std::mem::transmute(ptr) }; //~ERROR: wrong trait
12+
// Even though the vtable is for the wrong trait, this cast doesn't actually change the needed
13+
// vtable so it should still be allowed -- if we ever allow the line above.
14+
let _ptr2 = ptr as *const dyn fmt::Debug;
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error: Undefined Behavior: constructing invalid value: wrong trait in wide pointer vtable: expected `std::fmt::Debug + std::marker::Send + std::marker::Sync`, but encountered `std::fmt::Display`
2+
--> $DIR/dyn-upcast-nop-wrong-trait.rs:LL:CC
3+
|
4+
LL | let ptr: *const (dyn fmt::Debug + Send + Sync) = unsafe { std::mem::transmute(ptr) };
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: wrong trait in wide pointer vtable: expected `std::fmt::Debug + std::marker::Send + std::marker::Sync`, but encountered `std::fmt::Display`
6+
|
7+
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
8+
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
9+
= note: BACKTRACE:
10+
= note: inside `main` at $DIR/dyn-upcast-nop-wrong-trait.rs:LL:CC
11+
12+
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
13+
14+
error: aborting due to 1 previous error
15+

tests/fail/dyn-upcast-trait-mismatch.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Validation stops this too early.
2+
//@compile-flags: -Zmiri-disable-validation
3+
14
#![feature(trait_upcasting)]
25
#![allow(incomplete_features)]
36

@@ -57,7 +60,7 @@ impl Baz for i32 {
5760

5861
fn main() {
5962
let baz: &dyn Baz = &1;
60-
let baz_fake: &dyn Bar = unsafe { std::mem::transmute(baz) };
61-
let _err = baz_fake as &dyn Foo;
62-
//~^ERROR: upcast on a pointer whose vtable does not match its type
63+
let baz_fake: *const dyn Bar = unsafe { std::mem::transmute(baz) };
64+
let _err = baz_fake as *const dyn Foo;
65+
//~^ERROR: using vtable for trait `Baz` but trait `Bar` was expected
6366
}

tests/fail/dyn-upcast-trait-mismatch.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error: Undefined Behavior: upcast on a pointer whose vtable does not match its type
1+
error: Undefined Behavior: using vtable for trait `Baz` but trait `Bar` was expected
22
--> $DIR/dyn-upcast-trait-mismatch.rs:LL:CC
33
|
4-
LL | let _err = baz_fake as &dyn Foo;
5-
| ^^^^^^^^ upcast on a pointer whose vtable does not match its type
4+
LL | let _err = baz_fake as *const dyn Foo;
5+
| ^^^^^^^^ using vtable for trait `Baz` but trait `Bar` was expected
66
|
77
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
88
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information

tests/fail/intrinsics/ctlz_nonzero.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
mod rusti {
44
extern "rust-intrinsic" {
5-
pub fn ctlz_nonzero<T>(x: T) -> T;
5+
pub fn ctlz_nonzero<T>(x: T) -> u32;
66
}
77
}
88

tests/fail/intrinsics/cttz_nonzero.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
mod rusti {
44
extern "rust-intrinsic" {
5-
pub fn cttz_nonzero<T>(x: T) -> T;
5+
pub fn cttz_nonzero<T>(x: T) -> u32;
66
}
77
}
88

0 commit comments

Comments
 (0)