Skip to content

Commit 2bcee7e

Browse files
committed
Auto merge of #120903 - matthiaskrgr:rollup-tmsuzth, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - #119213 (simd intrinsics: add simd_shuffle_generic and other missing intrinsics) - #120272 (Suppress suggestions in derive macro) - #120773 (large_assignments: Allow moves into functions) - #120874 (Take empty `where` bounds into account when suggesting predicates) - #120882 (interpret/write_discriminant: when encoding niched variant, ensure the stored value matches) - #120883 (interpret: rename ReadExternStatic → ExternStatic) - #120890 (Adapt `llvm-has-rust-patches` validation to take `llvm-config` into account.) - #120895 (don't skip coercions for types with errors) - #120896 (Print kind of coroutine closure) r? `@ghost` `@rustbot` modify labels: rollup
2 parents f588631 + 1b6ab56 commit 2bcee7e

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#![feature(core_intrinsics)]
2+
#![feature(custom_mir)]
3+
4+
use std::intrinsics::mir::*;
5+
use std::num::NonZeroI32;
6+
7+
// We define our own option type so that we can control the varian indices.
8+
#[allow(unused)]
9+
enum Option<T> {
10+
None,
11+
Some(T),
12+
}
13+
use Option::*;
14+
15+
#[custom_mir(dialect = "runtime", phase = "optimized")]
16+
fn set_discriminant(ptr: &mut Option<NonZeroI32>) {
17+
mir! {
18+
{
19+
// We set the discriminant to `Some`, which is a NOP since this is the niched variant.
20+
// However, the enum is actually encoding `None` currently! That's not good...
21+
SetDiscriminant(*ptr, 1);
22+
//~^ ERROR: trying to set discriminant of a Option<std::num::NonZero<i32>> to the niched variant, but the value does not match
23+
Return()
24+
}
25+
}
26+
}
27+
28+
pub fn main() {
29+
let mut v = None;
30+
set_discriminant(&mut v);
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error: Undefined Behavior: trying to set discriminant of a Option<std::num::NonZero<i32>> to the niched variant, but the value does not match
2+
--> $DIR/enum-set-discriminant-niche-variant-wrong.rs:LL:CC
3+
|
4+
LL | SetDiscriminant(*ptr, 1);
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^ trying to set discriminant of a Option<std::num::NonZero<i32>> to the niched variant, but the value does not match
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 `set_discriminant` at $DIR/enum-set-discriminant-niche-variant-wrong.rs:LL:CC
11+
note: inside `main`
12+
--> $DIR/enum-set-discriminant-niche-variant-wrong.rs:LL:CC
13+
|
14+
LL | set_discriminant(&mut v);
15+
| ^^^^^^^^^^^^^^^^^^^^^^^^
16+
17+
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
18+
19+
error: aborting due to 1 previous error
20+

0 commit comments

Comments
 (0)