Skip to content

Commit 66fb778

Browse files
committed
Make rustc_peek a safe intrinsic
1 parent 0cd7ff7 commit 66fb778

13 files changed

+79
-79
lines changed

src/librustc_typeck/check/intrinsic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ pub fn intrinsic_operation_unsafety(intrinsic: &str) -> hir::Unsafety {
7575
| "saturating_sub" | "rotate_left" | "rotate_right" | "ctpop" | "ctlz" | "cttz"
7676
| "bswap" | "bitreverse" | "discriminant_value" | "type_id" | "likely" | "unlikely"
7777
| "ptr_guaranteed_eq" | "ptr_guaranteed_ne" | "minnumf32" | "minnumf64" | "maxnumf32"
78-
| "maxnumf64" | "type_name" | "variant_count" => hir::Unsafety::Normal,
78+
| "rustc_peek" | "maxnumf64" | "type_name" | "variant_count" => hir::Unsafety::Normal,
7979
_ => hir::Unsafety::Unsafe,
8080
}
8181
}

src/test/ui/mir-dataflow/def-inits-1.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ struct S(i32);
1111
fn foo(test: bool, x: &mut S, y: S, mut z: S) -> S {
1212
let ret;
1313
// `ret` starts off uninitialized
14-
unsafe { rustc_peek(&ret); } //~ ERROR rustc_peek: bit not set
14+
rustc_peek(&ret); //~ ERROR rustc_peek: bit not set
1515

1616
// All function formal parameters start off initialized.
1717

18-
unsafe { rustc_peek(&x) };
19-
unsafe { rustc_peek(&y) };
20-
unsafe { rustc_peek(&z) };
18+
rustc_peek(&x);
19+
rustc_peek(&y);
20+
rustc_peek(&z);
2121

2222
ret = if test {
2323
::std::mem::replace(x, y)
@@ -27,21 +27,21 @@ fn foo(test: bool, x: &mut S, y: S, mut z: S) -> S {
2727
};
2828

2929
// `z` may be uninitialized here.
30-
unsafe { rustc_peek(&z); } //~ ERROR rustc_peek: bit not set
30+
rustc_peek(&z); //~ ERROR rustc_peek: bit not set
3131

3232
// `y` is definitely uninitialized here.
33-
unsafe { rustc_peek(&y); } //~ ERROR rustc_peek: bit not set
33+
rustc_peek(&y); //~ ERROR rustc_peek: bit not set
3434

3535
// `x` is still (definitely) initialized (replace above is a reborrow).
36-
unsafe { rustc_peek(&x); }
36+
rustc_peek(&x);
3737

3838
::std::mem::drop(x);
3939

4040
// `x` is *definitely* uninitialized here
41-
unsafe { rustc_peek(&x); } //~ ERROR rustc_peek: bit not set
41+
rustc_peek(&x); //~ ERROR rustc_peek: bit not set
4242

4343
// `ret` is now definitely initialized (via `if` above).
44-
unsafe { rustc_peek(&ret); }
44+
rustc_peek(&ret);
4545

4646
ret
4747
}

src/test/ui/mir-dataflow/def-inits-1.stderr

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
error: rustc_peek: bit not set
2-
--> $DIR/def-inits-1.rs:14:14
2+
--> $DIR/def-inits-1.rs:14:5
33
|
4-
LL | unsafe { rustc_peek(&ret); }
5-
| ^^^^^^^^^^^^^^^^
4+
LL | rustc_peek(&ret);
5+
| ^^^^^^^^^^^^^^^^
66

77
error: rustc_peek: bit not set
8-
--> $DIR/def-inits-1.rs:30:14
8+
--> $DIR/def-inits-1.rs:30:5
99
|
10-
LL | unsafe { rustc_peek(&z); }
11-
| ^^^^^^^^^^^^^^
10+
LL | rustc_peek(&z);
11+
| ^^^^^^^^^^^^^^
1212

1313
error: rustc_peek: bit not set
14-
--> $DIR/def-inits-1.rs:33:14
14+
--> $DIR/def-inits-1.rs:33:5
1515
|
16-
LL | unsafe { rustc_peek(&y); }
17-
| ^^^^^^^^^^^^^^
16+
LL | rustc_peek(&y);
17+
| ^^^^^^^^^^^^^^
1818

1919
error: rustc_peek: bit not set
20-
--> $DIR/def-inits-1.rs:41:14
20+
--> $DIR/def-inits-1.rs:41:5
2121
|
22-
LL | unsafe { rustc_peek(&x); }
23-
| ^^^^^^^^^^^^^^
22+
LL | rustc_peek(&x);
23+
| ^^^^^^^^^^^^^^
2424

2525
error: stop_after_dataflow ended compilation
2626

src/test/ui/mir-dataflow/indirect-mutation-offset.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const BOO: i32 = {
3838

3939
*rmut_cell = 42; // Mutates `x` indirectly even though `x` is not marked indirectly mutable!!!
4040
let val = *rmut_cell;
41-
unsafe { rustc_peek(x) }; //~ ERROR rustc_peek: bit not set
41+
rustc_peek(x); //~ ERROR rustc_peek: bit not set
4242

4343
val
4444
};

src/test/ui/mir-dataflow/indirect-mutation-offset.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error: rustc_peek: bit not set
2-
--> $DIR/indirect-mutation-offset.rs:41:14
2+
--> $DIR/indirect-mutation-offset.rs:41:5
33
|
4-
LL | unsafe { rustc_peek(x) };
5-
| ^^^^^^^^^^^^^
4+
LL | rustc_peek(x);
5+
| ^^^^^^^^^^^^^
66

77
error: stop_after_dataflow ended compilation
88

src/test/ui/mir-dataflow/inits-1.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ struct S(i32);
1111
fn foo(test: bool, x: &mut S, y: S, mut z: S) -> S {
1212
let ret;
1313
// `ret` starts off uninitialized, so we get an error report here.
14-
unsafe { rustc_peek(&ret); } //~ ERROR rustc_peek: bit not set
14+
rustc_peek(&ret); //~ ERROR rustc_peek: bit not set
1515

1616
// All function formal parameters start off initialized.
1717

18-
unsafe { rustc_peek(&x) };
19-
unsafe { rustc_peek(&y) };
20-
unsafe { rustc_peek(&z) };
18+
rustc_peek(&x);
19+
rustc_peek(&y);
20+
rustc_peek(&z);
2121

2222
ret = if test {
2323
::std::mem::replace(x, y)
@@ -28,21 +28,21 @@ fn foo(test: bool, x: &mut S, y: S, mut z: S) -> S {
2828

2929

3030
// `z` may be initialized here.
31-
unsafe { rustc_peek(&z); }
31+
rustc_peek(&z);
3232

3333
// `y` is definitely uninitialized here.
34-
unsafe { rustc_peek(&y); } //~ ERROR rustc_peek: bit not set
34+
rustc_peek(&y); //~ ERROR rustc_peek: bit not set
3535

3636
// `x` is still (definitely) initialized (replace above is a reborrow).
37-
unsafe { rustc_peek(&x); }
37+
rustc_peek(&x);
3838

3939
::std::mem::drop(x);
4040

4141
// `x` is *definitely* uninitialized here
42-
unsafe { rustc_peek(&x); } //~ ERROR rustc_peek: bit not set
42+
rustc_peek(&x); //~ ERROR rustc_peek: bit not set
4343

4444
// `ret` is now definitely initialized (via `if` above).
45-
unsafe { rustc_peek(&ret); }
45+
rustc_peek(&ret);
4646

4747
ret
4848
}

src/test/ui/mir-dataflow/inits-1.stderr

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
error: rustc_peek: bit not set
2-
--> $DIR/inits-1.rs:14:14
2+
--> $DIR/inits-1.rs:14:5
33
|
4-
LL | unsafe { rustc_peek(&ret); }
5-
| ^^^^^^^^^^^^^^^^
4+
LL | rustc_peek(&ret);
5+
| ^^^^^^^^^^^^^^^^
66

77
error: rustc_peek: bit not set
8-
--> $DIR/inits-1.rs:34:14
8+
--> $DIR/inits-1.rs:34:5
99
|
10-
LL | unsafe { rustc_peek(&y); }
11-
| ^^^^^^^^^^^^^^
10+
LL | rustc_peek(&y);
11+
| ^^^^^^^^^^^^^^
1212

1313
error: rustc_peek: bit not set
14-
--> $DIR/inits-1.rs:42:14
14+
--> $DIR/inits-1.rs:42:5
1515
|
16-
LL | unsafe { rustc_peek(&x); }
17-
| ^^^^^^^^^^^^^^
16+
LL | rustc_peek(&x);
17+
| ^^^^^^^^^^^^^^
1818

1919
error: stop_after_dataflow ended compilation
2020

src/test/ui/mir-dataflow/liveness-ptr.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ fn foo() -> i32 {
1010
x = 0;
1111

1212
// `x` is live here since it is used in the next statement...
13-
unsafe { rustc_peek(x); }
13+
rustc_peek(x);
1414

1515
p = &x;
1616

1717
// ... but not here, even while it can be accessed through `p`.
18-
unsafe { rustc_peek(x); } //~ ERROR rustc_peek: bit not set
18+
rustc_peek(x); //~ ERROR rustc_peek: bit not set
1919
let tmp = unsafe { *p };
2020

2121
x = tmp + 1;
2222

23-
unsafe { rustc_peek(x); }
23+
rustc_peek(x);
2424

2525
x
2626
}

src/test/ui/mir-dataflow/liveness-ptr.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error: rustc_peek: bit not set
2-
--> $DIR/liveness-ptr.rs:18:14
2+
--> $DIR/liveness-ptr.rs:18:5
33
|
4-
LL | unsafe { rustc_peek(x); }
5-
| ^^^^^^^^^^^^^
4+
LL | rustc_peek(x);
5+
| ^^^^^^^^^^^^^
66

77
error: stop_after_dataflow ended compilation
88

src/test/ui/mir-dataflow/uninits-1.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ struct S(i32);
1111
fn foo(test: bool, x: &mut S, y: S, mut z: S) -> S {
1212
let ret;
1313
// `ret` starts off uninitialized
14-
unsafe { rustc_peek(&ret); }
14+
rustc_peek(&ret);
1515

1616
// All function formal parameters start off initialized.
1717

18-
unsafe { rustc_peek(&x) }; //~ ERROR rustc_peek: bit not set
19-
unsafe { rustc_peek(&y) }; //~ ERROR rustc_peek: bit not set
20-
unsafe { rustc_peek(&z) }; //~ ERROR rustc_peek: bit not set
18+
rustc_peek(&x); //~ ERROR rustc_peek: bit not set
19+
rustc_peek(&y); //~ ERROR rustc_peek: bit not set
20+
rustc_peek(&z); //~ ERROR rustc_peek: bit not set
2121

2222
ret = if test {
2323
::std::mem::replace(x, y)
@@ -27,21 +27,21 @@ fn foo(test: bool, x: &mut S, y: S, mut z: S) -> S {
2727
};
2828

2929
// `z` may be uninitialized here.
30-
unsafe { rustc_peek(&z); }
30+
rustc_peek(&z);
3131

3232
// `y` is definitely uninitialized here.
33-
unsafe { rustc_peek(&y); }
33+
rustc_peek(&y);
3434

3535
// `x` is still (definitely) initialized (replace above is a reborrow).
36-
unsafe { rustc_peek(&x); } //~ ERROR rustc_peek: bit not set
36+
rustc_peek(&x); //~ ERROR rustc_peek: bit not set
3737

3838
::std::mem::drop(x);
3939

4040
// `x` is *definitely* uninitialized here
41-
unsafe { rustc_peek(&x); }
41+
rustc_peek(&x);
4242

4343
// `ret` is now definitely initialized (via `if` above).
44-
unsafe { rustc_peek(&ret); } //~ ERROR rustc_peek: bit not set
44+
rustc_peek(&ret); //~ ERROR rustc_peek: bit not set
4545

4646
ret
4747
}

src/test/ui/mir-dataflow/uninits-1.stderr

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
11
error: rustc_peek: bit not set
2-
--> $DIR/uninits-1.rs:18:14
2+
--> $DIR/uninits-1.rs:18:5
33
|
4-
LL | unsafe { rustc_peek(&x) };
5-
| ^^^^^^^^^^^^^^
4+
LL | rustc_peek(&x);
5+
| ^^^^^^^^^^^^^^
66

77
error: rustc_peek: bit not set
8-
--> $DIR/uninits-1.rs:19:14
8+
--> $DIR/uninits-1.rs:19:5
99
|
10-
LL | unsafe { rustc_peek(&y) };
11-
| ^^^^^^^^^^^^^^
10+
LL | rustc_peek(&y);
11+
| ^^^^^^^^^^^^^^
1212

1313
error: rustc_peek: bit not set
14-
--> $DIR/uninits-1.rs:20:14
14+
--> $DIR/uninits-1.rs:20:5
1515
|
16-
LL | unsafe { rustc_peek(&z) };
17-
| ^^^^^^^^^^^^^^
16+
LL | rustc_peek(&z);
17+
| ^^^^^^^^^^^^^^
1818

1919
error: rustc_peek: bit not set
20-
--> $DIR/uninits-1.rs:36:14
20+
--> $DIR/uninits-1.rs:36:5
2121
|
22-
LL | unsafe { rustc_peek(&x); }
23-
| ^^^^^^^^^^^^^^
22+
LL | rustc_peek(&x);
23+
| ^^^^^^^^^^^^^^
2424

2525
error: rustc_peek: bit not set
26-
--> $DIR/uninits-1.rs:44:14
26+
--> $DIR/uninits-1.rs:44:5
2727
|
28-
LL | unsafe { rustc_peek(&ret); }
29-
| ^^^^^^^^^^^^^^^^
28+
LL | rustc_peek(&ret);
29+
| ^^^^^^^^^^^^^^^^
3030

3131
error: stop_after_dataflow ended compilation
3232

src/test/ui/mir-dataflow/uninits-2.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ struct S(i32);
1111
fn foo(x: &mut S) {
1212
// `x` is initialized here, so maybe-uninit bit is 0.
1313

14-
unsafe { rustc_peek(&x) }; //~ ERROR rustc_peek: bit not set
14+
rustc_peek(&x); //~ ERROR rustc_peek: bit not set
1515

1616
::std::mem::drop(x);
1717

1818
// `x` definitely uninitialized here, so maybe-uninit bit is 1.
19-
unsafe { rustc_peek(&x) };
19+
rustc_peek(&x);
2020
}
2121
fn main() {
2222
foo(&mut S(13));

src/test/ui/mir-dataflow/uninits-2.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error: rustc_peek: bit not set
2-
--> $DIR/uninits-2.rs:14:14
2+
--> $DIR/uninits-2.rs:14:5
33
|
4-
LL | unsafe { rustc_peek(&x) };
5-
| ^^^^^^^^^^^^^^
4+
LL | rustc_peek(&x);
5+
| ^^^^^^^^^^^^^^
66

77
error: stop_after_dataflow ended compilation
88

0 commit comments

Comments
 (0)