Rollup merge of #86517 - camsteffen:unused-unsafe-async, r=LeSeulArtichaut

Fix `unused_unsafe` around `await`

Enables `unused_unsafe` lint for `unsafe { future.await }`.

The existing test for this is `unsafe { println!() }`, so I assume that `println!` used to contain compiler-generated unsafe but this is no longer true, and so the existing test is broken. I replaced the test with `unsafe { ...await }`. I believe `await` is currently the only instance of compiler-generated unsafe.

Reverts some parts of #85421, but the issue predates that PR.
This commit is contained in:
Yuki Okushi 2021-06-22 20:01:05 +09:00 committed by GitHub
commit 8ec4e7dfdd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 43 additions and 25 deletions

View file

@ -1,11 +1,11 @@
error: unnecessary `unsafe` block
--> $DIR/unsafe-around-compiler-generated-unsafe.rs:9:5
--> $DIR/unsafe-around-compiler-generated-unsafe.rs:9:9
|
LL | unsafe { println!("foo"); }
| ^^^^^^ unnecessary `unsafe` block
LL | unsafe { async {}.await; }
| ^^^^^^ unnecessary `unsafe` block
|
note: the lint level is defined here
--> $DIR/unsafe-around-compiler-generated-unsafe.rs:6:9
--> $DIR/unsafe-around-compiler-generated-unsafe.rs:5:9
|
LL | #![deny(unused_unsafe)]
| ^^^^^^^^^^^^^

View file

@ -1,10 +1,11 @@
// issue #12418
// edition:2018
// revisions: mir thir
// [thir]compile-flags: -Z thir-unsafeck
#![deny(unused_unsafe)]
fn main() {
unsafe { println!("foo"); } //~ ERROR unnecessary `unsafe`
let _ = async {
unsafe { async {}.await; } //~ ERROR unnecessary `unsafe`
};
}

View file

@ -1,11 +1,11 @@
error: unnecessary `unsafe` block
--> $DIR/unsafe-around-compiler-generated-unsafe.rs:9:5
--> $DIR/unsafe-around-compiler-generated-unsafe.rs:9:9
|
LL | unsafe { println!("foo"); }
| ^^^^^^ unnecessary `unsafe` block
LL | unsafe { async {}.await; }
| ^^^^^^ unnecessary `unsafe` block
|
note: the lint level is defined here
--> $DIR/unsafe-around-compiler-generated-unsafe.rs:6:9
--> $DIR/unsafe-around-compiler-generated-unsafe.rs:5:9
|
LL | #![deny(unused_unsafe)]
| ^^^^^^^^^^^^^