Skip to content

Commit 742db95

Browse files
committed
Auto merge of #2974 - RalfJung:rustup, r=RalfJung
Rustup
2 parents 3a6e7bb + 4979d32 commit 742db95

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

rust-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
d4096e0412ac5de785d739a0aa2b1c1c7b9d3b7d
1+
743333f3dd90721461c09387ec73d09c080d5f5f

tests/fail/overlapping_assignment.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#![feature(core_intrinsics)]
2+
#![feature(custom_mir)]
3+
4+
use std::intrinsics::mir::*;
5+
6+
// It's not that easy to fool the MIR validity check
7+
// which wants to prevent overlapping assignments...
8+
// So we use two separate pointer arguments, and then arrange for them to alias.
9+
#[custom_mir(dialect = "runtime", phase = "optimized")]
10+
pub fn self_copy(ptr1: *mut [i32; 4], ptr2: *mut [i32; 4]) {
11+
mir! {
12+
{
13+
*ptr1 = *ptr2; //~ERROR: overlapping ranges
14+
Return()
15+
}
16+
}
17+
}
18+
19+
pub fn main() {
20+
let mut x = [0; 4];
21+
let ptr = std::ptr::addr_of_mut!(x);
22+
self_copy(ptr, ptr);
23+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error: Undefined Behavior: `copy_nonoverlapping` called on overlapping ranges
2+
--> $DIR/overlapping_assignment.rs:LL:CC
3+
|
4+
LL | *ptr1 = *ptr2;
5+
| ^^^^^^^^^^^^^ `copy_nonoverlapping` called on overlapping ranges
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 `self_copy` at $DIR/overlapping_assignment.rs:LL:CC
11+
note: inside `main`
12+
--> $DIR/overlapping_assignment.rs:LL:CC
13+
|
14+
LL | self_copy(ptr, ptr);
15+
| ^^^^^^^^^^^^^^^^^^^
16+
17+
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
18+
19+
error: aborting due to previous error
20+

0 commit comments

Comments
 (0)