Skip to content

Commit 3e4bc02

Browse files
committed
Apply suggestions from PR review
1 parent 4ac348b commit 3e4bc02

File tree

5 files changed

+45
-19
lines changed

5 files changed

+45
-19
lines changed

clippy_lints/src/manual_async_fn.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use crate::utils::paths::{FUTURE_CORE, FUTURE_FROM_GENERATOR, FUTURE_STD};
2-
use crate::utils::{match_function_call, match_path, snippet_block, snippet_opt, span_lint_and_then};
1+
use crate::utils::paths::FUTURE_FROM_GENERATOR;
2+
use crate::utils::{match_function_call, snippet_block, snippet_opt, span_lint_and_then};
33
use if_chain::if_chain;
44
use rustc_errors::Applicability;
55
use rustc_hir::intravisit::FnKind;
@@ -66,7 +66,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ManualAsyncFn {
6666
cx,
6767
MANUAL_ASYNC_FN,
6868
header_span,
69-
"this function can be simplified using async syntax",
69+
"this function can be simplified using the `async fn` syntax",
7070
|diag| {
7171
if_chain! {
7272
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
104104
if let ItemKind::OpaqueTy(opaque) = &item.kind;
105105
if opaque.bounds.len() == 1;
106106
if let GenericBound::Trait(poly, _) = &opaque.bounds[0];
107-
let path = poly.trait_ref.path;
108-
if match_path(&path, &FUTURE_CORE) || match_path(&path, &FUTURE_STD);
107+
if poly.trait_ref.trait_def_id() == cx.tcx.lang_items().future_trait();
109108
then {
110109
return Some(&poly.trait_ref);
111110
}

clippy_lints/src/utils/paths.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ pub const FMT_ARGUMENTS_NEW_V1_FORMATTED: [&str; 4] = ["core", "fmt", "Arguments
4242
pub const FMT_ARGUMENTV1_NEW: [&str; 4] = ["core", "fmt", "ArgumentV1", "new"];
4343
pub const FROM_FROM: [&str; 4] = ["core", "convert", "From", "from"];
4444
pub const FROM_TRAIT: [&str; 3] = ["core", "convert", "From"];
45-
pub const FUTURE_CORE: [&str; 3] = ["core", "future", "Future"];
4645
pub const FUTURE_FROM_GENERATOR: [&str; 3] = ["core", "future", "from_generator"];
47-
pub const FUTURE_STD: [&str; 3] = ["std", "future", "Future"];
4846
pub const HASH: [&str; 2] = ["hash", "Hash"];
4947
pub const HASHMAP: [&str; 5] = ["std", "collections", "hash", "map", "HashMap"];
5048
pub const HASHMAP_ENTRY: [&str; 5] = ["std", "collections", "hash", "map", "Entry"];

tests/ui/manual_async_fn.fixed

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,19 @@ async fn already_async() -> impl Future<Output = i32> {
2929

3030
struct S {}
3131
impl S {
32-
async fn inh_fut() -> i32 { 42 }
32+
async fn inh_fut() -> i32 {
33+
// NOTE: this code is here just to check that the identation is correct in the suggested fix
34+
let a = 42;
35+
let b = 21;
36+
if a < b {
37+
let c = 21;
38+
let d = 42;
39+
if c < d {
40+
let _ = 42;
41+
}
42+
}
43+
42
44+
}
3345

3446
async fn meth_fut(&self) -> i32 { 42 }
3547

tests/ui/manual_async_fn.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,19 @@ async fn already_async() -> impl Future<Output = i32> {
3636
struct S {}
3737
impl S {
3838
fn inh_fut() -> impl Future<Output = i32> {
39-
async { 42 }
39+
async {
40+
// NOTE: this code is here just to check that the identation is correct in the suggested fix
41+
let a = 42;
42+
let b = 21;
43+
if a < b {
44+
let c = 21;
45+
let d = 42;
46+
if c < d {
47+
let _ = 42;
48+
}
49+
}
50+
42
51+
}
4052
}
4153

4254
fn meth_fut(&self) -> impl Future<Output = i32> {

tests/ui/manual_async_fn.stderr

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: this function can be simplified using async syntax
1+
error: this function can be simplified using the `async fn` syntax
22
--> $DIR/manual_async_fn.rs:8:1
33
|
44
LL | fn fut() -> impl Future<Output = i32> {
@@ -14,7 +14,7 @@ help: move the body of the async block to the enclosing function
1414
LL | fn fut() -> impl Future<Output = i32> { 42 }
1515
| ^^^^^^
1616

17-
error: this function can be simplified using async syntax
17+
error: this function can be simplified using the `async fn` syntax
1818
--> $DIR/manual_async_fn.rs:12:1
1919
|
2020
LL | fn empty_fut() -> impl Future<Output = ()> {
@@ -29,7 +29,7 @@ help: move the body of the async block to the enclosing function
2929
LL | fn empty_fut() -> impl Future<Output = ()> {}
3030
| ^^
3131

32-
error: this function can be simplified using async syntax
32+
error: this function can be simplified using the `async fn` syntax
3333
--> $DIR/manual_async_fn.rs:16:1
3434
|
3535
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
4444
LL | fn core_fut() -> impl core::future::Future<Output = i32> { 42 }
4545
| ^^^^^^
4646

47-
error: this function can be simplified using async syntax
47+
error: this function can be simplified using the `async fn` syntax
4848
--> $DIR/manual_async_fn.rs:38:5
4949
|
5050
LL | fn inh_fut() -> impl Future<Output = i32> {
@@ -56,11 +56,16 @@ LL | async fn inh_fut() -> i32 {
5656
| ^^^^^^^^^^^^^^^^^^^^^^^^^
5757
help: move the body of the async block to the enclosing function
5858
|
59-
LL | fn inh_fut() -> impl Future<Output = i32> { 42 }
60-
| ^^^^^^
59+
LL | fn inh_fut() -> impl Future<Output = i32> {
60+
LL | // NOTE: this code is here just to check that the identation is correct in the suggested fix
61+
LL | let a = 42;
62+
LL | let b = 21;
63+
LL | if a < b {
64+
LL | let c = 21;
65+
...
6166

62-
error: this function can be simplified using async syntax
63-
--> $DIR/manual_async_fn.rs:42:5
67+
error: this function can be simplified using the `async fn` syntax
68+
--> $DIR/manual_async_fn.rs:54:5
6469
|
6570
LL | fn meth_fut(&self) -> impl Future<Output = i32> {
6671
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -74,8 +79,8 @@ help: move the body of the async block to the enclosing function
7479
LL | fn meth_fut(&self) -> impl Future<Output = i32> { 42 }
7580
| ^^^^^^
7681

77-
error: this function can be simplified using async syntax
78-
--> $DIR/manual_async_fn.rs:46:5
82+
error: this function can be simplified using the `async fn` syntax
83+
--> $DIR/manual_async_fn.rs:58:5
7984
|
8085
LL | fn empty_fut(&self) -> impl Future<Output = ()> {
8186
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)