Fix and bless tests
This commit is contained in:
parent
a3bae5ce73
commit
925d5ac45f
2 changed files with 169 additions and 22 deletions
|
@ -1,5 +1,5 @@
|
|||
#![feature(unsafe_block_in_unsafe_fn)]
|
||||
#![warn(unsafe_op_in_unsafe_fn)]
|
||||
#![deny(unsafe_op_in_unsafe_fn)]
|
||||
#![deny(unused_unsafe)]
|
||||
#![deny(safe_packed_borrows)]
|
||||
|
||||
|
@ -14,18 +14,34 @@ pub struct Packed {
|
|||
|
||||
const PACKED: Packed = Packed { data: &0 };
|
||||
|
||||
unsafe fn foo() {
|
||||
unsafe fn deny_level() {
|
||||
unsf();
|
||||
//~^ WARNING call to unsafe function is unsafe and requires unsafe block
|
||||
//~^ ERROR call to unsafe function is unsafe and requires unsafe block
|
||||
*PTR;
|
||||
//~^ WARNING dereference of raw pointer is unsafe and requires unsafe block
|
||||
//~^ ERROR dereference of raw pointer is unsafe and requires unsafe block
|
||||
VOID = ();
|
||||
//~^ WARNING use of mutable static is unsafe and requires unsafe block
|
||||
&PACKED.data; // the level for the `safe_packed_borrows` lint is ignored
|
||||
//~^ WARNING borrow of packed field is unsafe and requires unsafe block
|
||||
//~^ ERROR use of mutable static is unsafe and requires unsafe block
|
||||
&PACKED.data;
|
||||
//~^ ERROR borrow of packed field is unsafe and requires unsafe block
|
||||
//~| WARNING this was previously accepted by the compiler but is being phased out
|
||||
}
|
||||
|
||||
unsafe fn bar() {
|
||||
// Check that `unsafe_op_in_unsafe_fn` works starting from the `warn` level.
|
||||
#[warn(unsafe_op_in_unsafe_fn)]
|
||||
#[deny(warnings)]
|
||||
unsafe fn warning_level() {
|
||||
unsf();
|
||||
//~^ ERROR call to unsafe function is unsafe and requires unsafe block
|
||||
*PTR;
|
||||
//~^ ERROR dereference of raw pointer is unsafe and requires unsafe block
|
||||
VOID = ();
|
||||
//~^ ERROR use of mutable static is unsafe and requires unsafe block
|
||||
&PACKED.data;
|
||||
//~^ ERROR borrow of packed field is unsafe and requires unsafe block
|
||||
//~| WARNING this was previously accepted by the compiler but is being phased out
|
||||
}
|
||||
|
||||
unsafe fn explicit_block() {
|
||||
// no error
|
||||
unsafe {
|
||||
unsf();
|
||||
|
@ -35,13 +51,25 @@ unsafe fn bar() {
|
|||
}
|
||||
}
|
||||
|
||||
unsafe fn baz() {
|
||||
unsafe fn two_explicit_blocks() {
|
||||
unsafe { unsafe { unsf() } }
|
||||
//~^ ERROR unnecessary `unsafe` block
|
||||
}
|
||||
|
||||
#[warn(safe_packed_borrows)]
|
||||
unsafe fn warn_packed_borrows() {
|
||||
&PACKED.data;
|
||||
//~^ WARNING borrow of packed field is unsafe and requires unsafe block
|
||||
//~| WARNING this was previously accepted by the compiler but is being phased out
|
||||
}
|
||||
|
||||
#[allow(safe_packed_borrows)]
|
||||
unsafe fn allow_packed_borrows() {
|
||||
&PACKED.data; // `safe_packed_borrows` is allowed, no error
|
||||
}
|
||||
|
||||
#[allow(unsafe_op_in_unsafe_fn)]
|
||||
unsafe fn qux() {
|
||||
unsafe fn allow_level() {
|
||||
// lint allowed -> no error
|
||||
unsf();
|
||||
*PTR;
|
||||
|
@ -52,7 +80,26 @@ unsafe fn qux() {
|
|||
//~^ ERROR unnecessary `unsafe` block
|
||||
}
|
||||
|
||||
unsafe fn nested_allow_level() {
|
||||
#[allow(unsafe_op_in_unsafe_fn)]
|
||||
{
|
||||
// lint allowed -> no error
|
||||
unsf();
|
||||
*PTR;
|
||||
VOID = ();
|
||||
&PACKED.data;
|
||||
|
||||
unsafe { unsf() }
|
||||
//~^ ERROR unnecessary `unsafe` block
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
unsf()
|
||||
unsf();
|
||||
//~^ ERROR call to unsafe function is unsafe and requires unsafe block
|
||||
#[allow(unsafe_op_in_unsafe_fn)]
|
||||
{
|
||||
unsf();
|
||||
//~^ ERROR call to unsafe function is unsafe and requires unsafe function or block
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
warning: call to unsafe function is unsafe and requires unsafe block (error E0133)
|
||||
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:8:5
|
||||
error: call to unsafe function is unsafe and requires unsafe block (error E0133)
|
||||
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:18:5
|
||||
|
|
||||
LL | unsf();
|
||||
| ^^^^^^ call to unsafe function
|
||||
|
@ -7,12 +7,83 @@ LL | unsf();
|
|||
note: the lint level is defined here
|
||||
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:2:9
|
||||
|
|
||||
LL | #![warn(unsafe_op_in_unsafe_fn)]
|
||||
LL | #![deny(unsafe_op_in_unsafe_fn)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
= note: consult the function's documentation for information on how to avoid undefined behavior
|
||||
|
||||
error: dereference of raw pointer is unsafe and requires unsafe block (error E0133)
|
||||
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:20:5
|
||||
|
|
||||
LL | *PTR;
|
||||
| ^^^^ dereference of raw pointer
|
||||
|
|
||||
= note: raw pointers may be NULL, dangling or unaligned; they can violate aliasing rules and cause data races: all of these are undefined behavior
|
||||
|
||||
error: use of mutable static is unsafe and requires unsafe block (error E0133)
|
||||
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:22:5
|
||||
|
|
||||
LL | VOID = ();
|
||||
| ^^^^^^^^^ use of mutable static
|
||||
|
|
||||
= note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior
|
||||
|
||||
error: borrow of packed field is unsafe and requires unsafe block (error E0133)
|
||||
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:24:5
|
||||
|
|
||||
LL | &PACKED.data;
|
||||
| ^^^^^^^^^^^^ borrow of packed field
|
||||
|
|
||||
note: the lint level is defined here
|
||||
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:4:9
|
||||
|
|
||||
LL | #![deny(safe_packed_borrows)]
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= note: for more information, see issue #46043 <https://github.com/rust-lang/rust/issues/46043>
|
||||
= note: fields of packed structs might be misaligned: dereferencing a misaligned pointer or even just creating a misaligned reference is undefined behavior
|
||||
|
||||
error: call to unsafe function is unsafe and requires unsafe block (error E0133)
|
||||
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:33:5
|
||||
|
|
||||
LL | unsf();
|
||||
| ^^^^^^ call to unsafe function
|
||||
|
|
||||
note: the lint level is defined here
|
||||
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:31:8
|
||||
|
|
||||
LL | #[deny(warnings)]
|
||||
| ^^^^^^^^
|
||||
= note: `#[deny(unsafe_op_in_unsafe_fn)]` implied by `#[deny(warnings)]`
|
||||
= note: consult the function's documentation for information on how to avoid undefined behavior
|
||||
|
||||
error: dereference of raw pointer is unsafe and requires unsafe block (error E0133)
|
||||
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:35:5
|
||||
|
|
||||
LL | *PTR;
|
||||
| ^^^^ dereference of raw pointer
|
||||
|
|
||||
= note: raw pointers may be NULL, dangling or unaligned; they can violate aliasing rules and cause data races: all of these are undefined behavior
|
||||
|
||||
error: use of mutable static is unsafe and requires unsafe block (error E0133)
|
||||
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:37:5
|
||||
|
|
||||
LL | VOID = ();
|
||||
| ^^^^^^^^^ use of mutable static
|
||||
|
|
||||
= note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior
|
||||
|
||||
error: borrow of packed field is unsafe and requires unsafe block (error E0133)
|
||||
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:39:5
|
||||
|
|
||||
LL | &PACKED.data;
|
||||
| ^^^^^^^^^^^^ borrow of packed field
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= note: for more information, see issue #46043 <https://github.com/rust-lang/rust/issues/46043>
|
||||
= note: fields of packed structs might be misaligned: dereferencing a misaligned pointer or even just creating a misaligned reference is undefined behavior
|
||||
|
||||
error: unnecessary `unsafe` block
|
||||
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:17:14
|
||||
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:55:14
|
||||
|
|
||||
LL | unsafe { unsafe { unsf() } }
|
||||
| ------ ^^^^^^ unnecessary `unsafe` block
|
||||
|
@ -25,20 +96,49 @@ note: the lint level is defined here
|
|||
LL | #![deny(unused_unsafe)]
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
warning: borrow of packed field is unsafe and requires unsafe block (error E0133)
|
||||
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:61:5
|
||||
|
|
||||
LL | &PACKED.data;
|
||||
| ^^^^^^^^^^^^ borrow of packed field
|
||||
|
|
||||
note: the lint level is defined here
|
||||
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:59:8
|
||||
|
|
||||
LL | #[warn(safe_packed_borrows)]
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= note: for more information, see issue #46043 <https://github.com/rust-lang/rust/issues/46043>
|
||||
= note: fields of packed structs might be misaligned: dereferencing a misaligned pointer or even just creating a misaligned reference is undefined behavior
|
||||
|
||||
error: unnecessary `unsafe` block
|
||||
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:25:5
|
||||
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:79:5
|
||||
|
|
||||
LL | unsafe { unsf() }
|
||||
| ^^^^^^ unnecessary `unsafe` block
|
||||
|
||||
error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
|
||||
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:30:5
|
||||
error: unnecessary `unsafe` block
|
||||
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:92:9
|
||||
|
|
||||
LL | unsf()
|
||||
LL | unsafe { unsf() }
|
||||
| ^^^^^^ unnecessary `unsafe` block
|
||||
|
||||
error[E0133]: call to unsafe function is unsafe and requires unsafe block
|
||||
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:98:5
|
||||
|
|
||||
LL | unsf();
|
||||
| ^^^^^^ call to unsafe function
|
||||
|
|
||||
= note: consult the function's documentation for information on how to avoid undefined behavior
|
||||
|
||||
error: aborting due to 3 previous errors; 1 warning emitted
|
||||
error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
|
||||
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:102:9
|
||||
|
|
||||
LL | unsf();
|
||||
| ^^^^^^ call to unsafe function
|
||||
|
|
||||
= note: consult the function's documentation for information on how to avoid undefined behavior
|
||||
|
||||
error: aborting due to 13 previous errors; 1 warning emitted
|
||||
|
||||
For more information about this error, try `rustc --explain E0133`.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue