Apply suggestions from PR review

This commit is contained in:
Eduardo Broto 2020-05-07 22:40:28 +02:00
parent 4ac348b308
commit 3e4bc026e2
5 changed files with 45 additions and 19 deletions

View file

@ -1,5 +1,5 @@
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;
@ -66,7 +66,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ManualAsyncFn {
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);
@ -104,8 +104,7 @@ fn future_trait_ref<'tcx>(cx: &LateContext<'_, 'tcx>, ty: &'tcx Ty<'tcx>) -> Opt
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);
}

View file

@ -42,9 +42,7 @@ pub const FMT_ARGUMENTS_NEW_V1_FORMATTED: [&str; 4] = ["core", "fmt", "Arguments
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"];

View file

@ -29,7 +29,19 @@ async fn already_async() -> impl Future<Output = i32> {
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 }

View file

@ -36,7 +36,19 @@ async fn already_async() -> impl Future<Output = i32> {
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> {

View file

@ -1,4 +1,4 @@
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> {
@ -14,7 +14,7 @@ help: move the body of the async block to the enclosing function
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 = ()> {
@ -29,7 +29,7 @@ help: move the body of the async block to the enclosing function
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> {
@ -44,7 +44,7 @@ help: move the body of the async block to the enclosing function
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> {
@ -56,11 +56,16 @@ LL | async fn inh_fut() -> 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> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -74,8 +79,8 @@ help: move the body of the async block to the enclosing function
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 = ()> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^