Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit c530b2d

Browse files
Add rustc_peek test for liveness with borrows
1 parent a6a87e8 commit c530b2d

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#![feature(core_intrinsics, rustc_attrs)]
2+
3+
use std::intrinsics::rustc_peek;
4+
5+
#[rustc_mir(rustc_peek_liveness, stop_after_dataflow)]
6+
fn foo() -> i32 {
7+
let mut x: i32;
8+
let mut p: *const i32;
9+
10+
x = 0;
11+
12+
// `x` is live here since it is used in the next statement...
13+
unsafe { rustc_peek(x); }
14+
15+
p = &x;
16+
17+
// ... but not here, even while it can be accessed through `p`.
18+
unsafe { rustc_peek(x); } //~ ERROR rustc_peek: bit not set
19+
let tmp = unsafe { *p };
20+
21+
x = tmp + 1;
22+
23+
unsafe { rustc_peek(x); }
24+
25+
x
26+
}
27+
28+
fn main() {}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: rustc_peek: bit not set
2+
--> $DIR/liveness-ptr.rs:18:14
3+
|
4+
LL | unsafe { rustc_peek(x); }
5+
| ^^^^^^^^^^^^^
6+
7+
error: stop_after_dataflow ended compilation
8+
9+
error: aborting due to 2 previous errors
10+

0 commit comments

Comments
 (0)