Skip to content

Commit 925d5ac

Browse files
Fix and bless tests
1 parent a3bae5c commit 925d5ac

File tree

2 files changed

+168
-21
lines changed

2 files changed

+168
-21
lines changed
Lines changed: 59 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![feature(unsafe_block_in_unsafe_fn)]
2-
#![warn(unsafe_op_in_unsafe_fn)]
2+
#![deny(unsafe_op_in_unsafe_fn)]
33
#![deny(unused_unsafe)]
44
#![deny(safe_packed_borrows)]
55

@@ -14,18 +14,34 @@ pub struct Packed {
1414

1515
const PACKED: Packed = Packed { data: &0 };
1616

17-
unsafe fn foo() {
17+
unsafe fn deny_level() {
1818
unsf();
19-
//~^ WARNING call to unsafe function is unsafe and requires unsafe block
19+
//~^ ERROR call to unsafe function is unsafe and requires unsafe block
2020
*PTR;
21-
//~^ WARNING dereference of raw pointer is unsafe and requires unsafe block
21+
//~^ ERROR dereference of raw pointer is unsafe and requires unsafe block
2222
VOID = ();
23-
//~^ WARNING use of mutable static is unsafe and requires unsafe block
24-
&PACKED.data; // the level for the `safe_packed_borrows` lint is ignored
25-
//~^ WARNING borrow of packed field is unsafe and requires unsafe block
23+
//~^ ERROR use of mutable static is unsafe and requires unsafe block
24+
&PACKED.data;
25+
//~^ ERROR borrow of packed field is unsafe and requires unsafe block
26+
//~| WARNING this was previously accepted by the compiler but is being phased out
2627
}
2728

28-
unsafe fn bar() {
29+
// Check that `unsafe_op_in_unsafe_fn` works starting from the `warn` level.
30+
#[warn(unsafe_op_in_unsafe_fn)]
31+
#[deny(warnings)]
32+
unsafe fn warning_level() {
33+
unsf();
34+
//~^ ERROR call to unsafe function is unsafe and requires unsafe block
35+
*PTR;
36+
//~^ ERROR dereference of raw pointer is unsafe and requires unsafe block
37+
VOID = ();
38+
//~^ ERROR use of mutable static is unsafe and requires unsafe block
39+
&PACKED.data;
40+
//~^ ERROR borrow of packed field is unsafe and requires unsafe block
41+
//~| WARNING this was previously accepted by the compiler but is being phased out
42+
}
43+
44+
unsafe fn explicit_block() {
2945
// no error
3046
unsafe {
3147
unsf();
@@ -35,13 +51,25 @@ unsafe fn bar() {
3551
}
3652
}
3753

38-
unsafe fn baz() {
54+
unsafe fn two_explicit_blocks() {
3955
unsafe { unsafe { unsf() } }
4056
//~^ ERROR unnecessary `unsafe` block
4157
}
4258

59+
#[warn(safe_packed_borrows)]
60+
unsafe fn warn_packed_borrows() {
61+
&PACKED.data;
62+
//~^ WARNING borrow of packed field is unsafe and requires unsafe block
63+
//~| WARNING this was previously accepted by the compiler but is being phased out
64+
}
65+
66+
#[allow(safe_packed_borrows)]
67+
unsafe fn allow_packed_borrows() {
68+
&PACKED.data; // `safe_packed_borrows` is allowed, no error
69+
}
70+
4371
#[allow(unsafe_op_in_unsafe_fn)]
44-
unsafe fn qux() {
72+
unsafe fn allow_level() {
4573
// lint allowed -> no error
4674
unsf();
4775
*PTR;
@@ -52,7 +80,26 @@ unsafe fn qux() {
5280
//~^ ERROR unnecessary `unsafe` block
5381
}
5482

83+
unsafe fn nested_allow_level() {
84+
#[allow(unsafe_op_in_unsafe_fn)]
85+
{
86+
// lint allowed -> no error
87+
unsf();
88+
*PTR;
89+
VOID = ();
90+
&PACKED.data;
91+
92+
unsafe { unsf() }
93+
//~^ ERROR unnecessary `unsafe` block
94+
}
95+
}
96+
5597
fn main() {
56-
unsf()
57-
//~^ ERROR call to unsafe function is unsafe and requires unsafe function or block
98+
unsf();
99+
//~^ ERROR call to unsafe function is unsafe and requires unsafe block
100+
#[allow(unsafe_op_in_unsafe_fn)]
101+
{
102+
unsf();
103+
//~^ ERROR call to unsafe function is unsafe and requires unsafe function or block
104+
}
58105
}
Lines changed: 109 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,89 @@
1-
warning: call to unsafe function is unsafe and requires unsafe block (error E0133)
2-
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:8:5
1+
error: call to unsafe function is unsafe and requires unsafe block (error E0133)
2+
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:18:5
33
|
44
LL | unsf();
55
| ^^^^^^ call to unsafe function
66
|
77
note: the lint level is defined here
88
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:2:9
99
|
10-
LL | #![warn(unsafe_op_in_unsafe_fn)]
10+
LL | #![deny(unsafe_op_in_unsafe_fn)]
1111
| ^^^^^^^^^^^^^^^^^^^^^^
1212
= note: consult the function's documentation for information on how to avoid undefined behavior
1313

14+
error: dereference of raw pointer is unsafe and requires unsafe block (error E0133)
15+
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:20:5
16+
|
17+
LL | *PTR;
18+
| ^^^^ dereference of raw pointer
19+
|
20+
= note: raw pointers may be NULL, dangling or unaligned; they can violate aliasing rules and cause data races: all of these are undefined behavior
21+
22+
error: use of mutable static is unsafe and requires unsafe block (error E0133)
23+
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:22:5
24+
|
25+
LL | VOID = ();
26+
| ^^^^^^^^^ use of mutable static
27+
|
28+
= note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior
29+
30+
error: borrow of packed field is unsafe and requires unsafe block (error E0133)
31+
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:24:5
32+
|
33+
LL | &PACKED.data;
34+
| ^^^^^^^^^^^^ borrow of packed field
35+
|
36+
note: the lint level is defined here
37+
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:4:9
38+
|
39+
LL | #![deny(safe_packed_borrows)]
40+
| ^^^^^^^^^^^^^^^^^^^
41+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
42+
= note: for more information, see issue #46043 <https://github.com/rust-lang/rust/issues/46043>
43+
= note: fields of packed structs might be misaligned: dereferencing a misaligned pointer or even just creating a misaligned reference is undefined behavior
44+
45+
error: call to unsafe function is unsafe and requires unsafe block (error E0133)
46+
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:33:5
47+
|
48+
LL | unsf();
49+
| ^^^^^^ call to unsafe function
50+
|
51+
note: the lint level is defined here
52+
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:31:8
53+
|
54+
LL | #[deny(warnings)]
55+
| ^^^^^^^^
56+
= note: `#[deny(unsafe_op_in_unsafe_fn)]` implied by `#[deny(warnings)]`
57+
= note: consult the function's documentation for information on how to avoid undefined behavior
58+
59+
error: dereference of raw pointer is unsafe and requires unsafe block (error E0133)
60+
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:35:5
61+
|
62+
LL | *PTR;
63+
| ^^^^ dereference of raw pointer
64+
|
65+
= note: raw pointers may be NULL, dangling or unaligned; they can violate aliasing rules and cause data races: all of these are undefined behavior
66+
67+
error: use of mutable static is unsafe and requires unsafe block (error E0133)
68+
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:37:5
69+
|
70+
LL | VOID = ();
71+
| ^^^^^^^^^ use of mutable static
72+
|
73+
= note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior
74+
75+
error: borrow of packed field is unsafe and requires unsafe block (error E0133)
76+
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:39:5
77+
|
78+
LL | &PACKED.data;
79+
| ^^^^^^^^^^^^ borrow of packed field
80+
|
81+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
82+
= note: for more information, see issue #46043 <https://github.com/rust-lang/rust/issues/46043>
83+
= note: fields of packed structs might be misaligned: dereferencing a misaligned pointer or even just creating a misaligned reference is undefined behavior
84+
1485
error: unnecessary `unsafe` block
15-
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:17:14
86+
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:55:14
1687
|
1788
LL | unsafe { unsafe { unsf() } }
1889
| ------ ^^^^^^ unnecessary `unsafe` block
@@ -25,20 +96,49 @@ note: the lint level is defined here
2596
LL | #![deny(unused_unsafe)]
2697
| ^^^^^^^^^^^^^
2798

99+
warning: borrow of packed field is unsafe and requires unsafe block (error E0133)
100+
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:61:5
101+
|
102+
LL | &PACKED.data;
103+
| ^^^^^^^^^^^^ borrow of packed field
104+
|
105+
note: the lint level is defined here
106+
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:59:8
107+
|
108+
LL | #[warn(safe_packed_borrows)]
109+
| ^^^^^^^^^^^^^^^^^^^
110+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
111+
= note: for more information, see issue #46043 <https://github.com/rust-lang/rust/issues/46043>
112+
= note: fields of packed structs might be misaligned: dereferencing a misaligned pointer or even just creating a misaligned reference is undefined behavior
113+
28114
error: unnecessary `unsafe` block
29-
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:25:5
115+
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:79:5
30116
|
31117
LL | unsafe { unsf() }
32118
| ^^^^^^ unnecessary `unsafe` block
33119

34-
error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
35-
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:30:5
120+
error: unnecessary `unsafe` block
121+
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:92:9
36122
|
37-
LL | unsf()
123+
LL | unsafe { unsf() }
124+
| ^^^^^^ unnecessary `unsafe` block
125+
126+
error[E0133]: call to unsafe function is unsafe and requires unsafe block
127+
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:98:5
128+
|
129+
LL | unsf();
38130
| ^^^^^^ call to unsafe function
39131
|
40132
= note: consult the function's documentation for information on how to avoid undefined behavior
41133

42-
error: aborting due to 3 previous errors; 1 warning emitted
134+
error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
135+
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:102:9
136+
|
137+
LL | unsf();
138+
| ^^^^^^ call to unsafe function
139+
|
140+
= note: consult the function's documentation for information on how to avoid undefined behavior
141+
142+
error: aborting due to 13 previous errors; 1 warning emitted
43143

44144
For more information about this error, try `rustc --explain E0133`.

0 commit comments

Comments
 (0)