-use crate::utils::paths::{FUTURE_CORE, FUTURE_FROM_GENERATOR, FUTURE_STD};
-use crate::utils::{match_function_call, match_path, snippet_block, snippet_opt, span_lint_and_then};
+use crate::utils::paths::FUTURE_FROM_GENERATOR;
+use crate::utils::{match_function_call, snippet_block, snippet_opt, span_lint_and_then};
use if_chain::if_chain;
use rustc_errors::Applicability;
use rustc_hir::intravisit::FnKind;
cx,
MANUAL_ASYNC_FN,
header_span,
- "this function can be simplified using async syntax",
+ "this function can be simplified using the `async fn` syntax",
|diag| {
if_chain! {
if let Some(header_snip) = snippet_opt(cx, header_span);
if let ItemKind::OpaqueTy(opaque) = &item.kind;
if opaque.bounds.len() == 1;
if let GenericBound::Trait(poly, _) = &opaque.bounds[0];
- let path = poly.trait_ref.path;
- if match_path(&path, &FUTURE_CORE) || match_path(&path, &FUTURE_STD);
+ if poly.trait_ref.trait_def_id() == cx.tcx.lang_items().future_trait();
then {
return Some(&poly.trait_ref);
}
pub const FMT_ARGUMENTV1_NEW: [&str; 4] = ["core", "fmt", "ArgumentV1", "new"];
pub const FROM_FROM: [&str; 4] = ["core", "convert", "From", "from"];
pub const FROM_TRAIT: [&str; 3] = ["core", "convert", "From"];
-pub const FUTURE_CORE: [&str; 3] = ["core", "future", "Future"];
pub const FUTURE_FROM_GENERATOR: [&str; 3] = ["core", "future", "from_generator"];
-pub const FUTURE_STD: [&str; 3] = ["std", "future", "Future"];
pub const HASH: [&str; 2] = ["hash", "Hash"];
pub const HASHMAP: [&str; 5] = ["std", "collections", "hash", "map", "HashMap"];
pub const HASHMAP_ENTRY: [&str; 5] = ["std", "collections", "hash", "map", "Entry"];
struct S {}
impl S {
- async fn inh_fut() -> i32 { 42 }
+ async fn inh_fut() -> i32 {
+ // NOTE: this code is here just to check that the identation is correct in the suggested fix
+ let a = 42;
+ let b = 21;
+ if a < b {
+ let c = 21;
+ let d = 42;
+ if c < d {
+ let _ = 42;
+ }
+ }
+ 42
+ }
async fn meth_fut(&self) -> i32 { 42 }
struct S {}
impl S {
fn inh_fut() -> impl Future<Output = i32> {
- async { 42 }
+ async {
+ // NOTE: this code is here just to check that the identation is correct in the suggested fix
+ let a = 42;
+ let b = 21;
+ if a < b {
+ let c = 21;
+ let d = 42;
+ if c < d {
+ let _ = 42;
+ }
+ }
+ 42
+ }
}
fn meth_fut(&self) -> impl Future<Output = i32> {
-error: this function can be simplified using async syntax
+error: this function can be simplified using the `async fn` syntax
--> $DIR/manual_async_fn.rs:8:1
|
LL | fn fut() -> impl Future<Output = i32> {
LL | fn fut() -> impl Future<Output = i32> { 42 }
| ^^^^^^
-error: this function can be simplified using async syntax
+error: this function can be simplified using the `async fn` syntax
--> $DIR/manual_async_fn.rs:12:1
|
LL | fn empty_fut() -> impl Future<Output = ()> {
LL | fn empty_fut() -> impl Future<Output = ()> {}
| ^^
-error: this function can be simplified using async syntax
+error: this function can be simplified using the `async fn` syntax
--> $DIR/manual_async_fn.rs:16:1
|
LL | fn core_fut() -> impl core::future::Future<Output = i32> {
LL | fn core_fut() -> impl core::future::Future<Output = i32> { 42 }
| ^^^^^^
-error: this function can be simplified using async syntax
+error: this function can be simplified using the `async fn` syntax
--> $DIR/manual_async_fn.rs:38:5
|
LL | fn inh_fut() -> impl Future<Output = i32> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^
help: move the body of the async block to the enclosing function
|
-LL | fn inh_fut() -> impl Future<Output = i32> { 42 }
- | ^^^^^^
+LL | fn inh_fut() -> impl Future<Output = i32> {
+LL | // NOTE: this code is here just to check that the identation is correct in the suggested fix
+LL | let a = 42;
+LL | let b = 21;
+LL | if a < b {
+LL | let c = 21;
+ ...
-error: this function can be simplified using async syntax
- --> $DIR/manual_async_fn.rs:42:5
+error: this function can be simplified using the `async fn` syntax
+ --> $DIR/manual_async_fn.rs:54:5
|
LL | fn meth_fut(&self) -> impl Future<Output = i32> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | fn meth_fut(&self) -> impl Future<Output = i32> { 42 }
| ^^^^^^
-error: this function can be simplified using async syntax
- --> $DIR/manual_async_fn.rs:46:5
+error: this function can be simplified using the `async fn` syntax
+ --> $DIR/manual_async_fn.rs:58:5
|
LL | fn empty_fut(&self) -> impl Future<Output = ()> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^