Skip to content

Commit 75c0fd7

Browse files
committed
Auto merge of #113474 - compiler-errors:rollup-07x1up7, r=compiler-errors
Rollup of 8 pull requests Successful merges: - #113413 (Add needs-triage to all new issues) - #113426 (Don't ICE in `resolve_bound_vars` when associated return-type bounds are in bad positions) - #113427 (Remove `variances_of` on RPITIT GATs, remove its one use-case) - #113441 (miri: check that assignments do not self-overlap) - #113453 (Remove unused from_method from rustc_on_unimplemented) - #113456 (Avoid calling report_forbidden_specialization for RPITITs) - #113466 (Update cargo) - #113467 (Fix comment of `fn_can_unwind`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 8e01f3c + a49afbc commit 75c0fd7

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

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)