Merge branch 'rust-lang:master' into clear-with-drain
This commit is contained in:
commit
d56c941792
4 changed files with 147 additions and 6 deletions
|
|
@ -3,6 +3,8 @@
|
|||
#![allow(unused)]
|
||||
#![warn(clippy::redundant_async_block)]
|
||||
|
||||
use std::future::Future;
|
||||
|
||||
async fn func1(n: usize) -> usize {
|
||||
n + 1
|
||||
}
|
||||
|
|
@ -62,3 +64,48 @@ fn main() {
|
|||
let fut = async_await_parameter_in_macro!(func2());
|
||||
let fut = async_await_in_macro!(std::convert::identity);
|
||||
}
|
||||
|
||||
#[allow(clippy::let_and_return)]
|
||||
fn capture_local() -> impl Future<Output = i32> {
|
||||
// Lint
|
||||
let fut = async { 17 };
|
||||
fut
|
||||
}
|
||||
|
||||
fn capture_local_closure(s: &str) -> impl Future<Output = &str> {
|
||||
let f = move || std::future::ready(s);
|
||||
// Do not lint: `f` would not live long enough
|
||||
async move { f().await }
|
||||
}
|
||||
|
||||
#[allow(clippy::let_and_return)]
|
||||
fn capture_arg(s: &str) -> impl Future<Output = &str> {
|
||||
// Lint
|
||||
let fut = async move { s };
|
||||
fut
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
struct F {}
|
||||
|
||||
impl F {
|
||||
async fn run(&self) {}
|
||||
}
|
||||
|
||||
pub async fn run() {
|
||||
let f = F {};
|
||||
let c = f.clone();
|
||||
// Do not lint: `c` would not live long enough
|
||||
spawn(async move { c.run().await });
|
||||
let _f = f;
|
||||
}
|
||||
|
||||
fn spawn<F: Future + 'static>(_: F) {}
|
||||
|
||||
async fn work(_: &str) {}
|
||||
|
||||
fn capture() {
|
||||
let val = "Hello World".to_owned();
|
||||
// Do not lint: `val` would not live long enough
|
||||
spawn(async { work(&{ val }).await });
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@
|
|||
#![allow(unused)]
|
||||
#![warn(clippy::redundant_async_block)]
|
||||
|
||||
use std::future::Future;
|
||||
|
||||
async fn func1(n: usize) -> usize {
|
||||
n + 1
|
||||
}
|
||||
|
|
@ -62,3 +64,48 @@ fn main() {
|
|||
let fut = async_await_parameter_in_macro!(func2());
|
||||
let fut = async_await_in_macro!(std::convert::identity);
|
||||
}
|
||||
|
||||
#[allow(clippy::let_and_return)]
|
||||
fn capture_local() -> impl Future<Output = i32> {
|
||||
// Lint
|
||||
let fut = async { 17 };
|
||||
async move { fut.await }
|
||||
}
|
||||
|
||||
fn capture_local_closure(s: &str) -> impl Future<Output = &str> {
|
||||
let f = move || std::future::ready(s);
|
||||
// Do not lint: `f` would not live long enough
|
||||
async move { f().await }
|
||||
}
|
||||
|
||||
#[allow(clippy::let_and_return)]
|
||||
fn capture_arg(s: &str) -> impl Future<Output = &str> {
|
||||
// Lint
|
||||
let fut = async move { s };
|
||||
async move { fut.await }
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
struct F {}
|
||||
|
||||
impl F {
|
||||
async fn run(&self) {}
|
||||
}
|
||||
|
||||
pub async fn run() {
|
||||
let f = F {};
|
||||
let c = f.clone();
|
||||
// Do not lint: `c` would not live long enough
|
||||
spawn(async move { c.run().await });
|
||||
let _f = f;
|
||||
}
|
||||
|
||||
fn spawn<F: Future + 'static>(_: F) {}
|
||||
|
||||
async fn work(_: &str) {}
|
||||
|
||||
fn capture() {
|
||||
let val = "Hello World".to_owned();
|
||||
// Do not lint: `val` would not live long enough
|
||||
spawn(async { work(&{ val }).await });
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
error: this async expression only awaits a single future
|
||||
--> $DIR/redundant_async_block.rs:13:13
|
||||
--> $DIR/redundant_async_block.rs:15:13
|
||||
|
|
||||
LL | let x = async { f.await };
|
||||
| ^^^^^^^^^^^^^^^^^ help: you can reduce it to: `f`
|
||||
|
|
@ -7,22 +7,34 @@ LL | let x = async { f.await };
|
|||
= note: `-D clippy::redundant-async-block` implied by `-D warnings`
|
||||
|
||||
error: this async expression only awaits a single future
|
||||
--> $DIR/redundant_async_block.rs:46:16
|
||||
--> $DIR/redundant_async_block.rs:48:16
|
||||
|
|
||||
LL | let fut2 = async { fut1.await };
|
||||
| ^^^^^^^^^^^^^^^^^^^^ help: you can reduce it to: `fut1`
|
||||
|
||||
error: this async expression only awaits a single future
|
||||
--> $DIR/redundant_async_block.rs:49:16
|
||||
--> $DIR/redundant_async_block.rs:51:16
|
||||
|
|
||||
LL | let fut2 = async move { fut1.await };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can reduce it to: `fut1`
|
||||
|
||||
error: this async expression only awaits a single future
|
||||
--> $DIR/redundant_async_block.rs:51:15
|
||||
--> $DIR/redundant_async_block.rs:53:15
|
||||
|
|
||||
LL | let fut = async { async { 42 }.await };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can reduce it to: `async { 42 }`
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
error: this async expression only awaits a single future
|
||||
--> $DIR/redundant_async_block.rs:72:5
|
||||
|
|
||||
LL | async move { fut.await }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: you can reduce it to: `fut`
|
||||
|
||||
error: this async expression only awaits a single future
|
||||
--> $DIR/redundant_async_block.rs:85:5
|
||||
|
|
||||
LL | async move { fut.await }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: you can reduce it to: `fut`
|
||||
|
||||
error: aborting due to 6 previous errors
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue