]> git.lizzy.rs Git - rust.git/commitdiff
Apply suggestions from PR review
authorEduardo Broto <ebroto@tutanota.com>
Thu, 7 May 2020 20:40:28 +0000 (22:40 +0200)
committerEduardo Broto <ebroto@tutanota.com>
Thu, 7 May 2020 20:40:28 +0000 (22:40 +0200)
clippy_lints/src/manual_async_fn.rs
clippy_lints/src/utils/paths.rs
tests/ui/manual_async_fn.fixed
tests/ui/manual_async_fn.rs
tests/ui/manual_async_fn.stderr

index b4be3ecfd16211ed27c33d9ec7e117d46ca13a85..cb72a24058234dcafce74496cc8431f2391f67db 100644 (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 @@ fn check_fn(
                     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);
         }
index 74040a96c78a4a0ceafc4c2df4a8eb8456f6f3eb..b3ad2ad9d9987e73205b42299003e146a7c80bd6 100644 (file)
@@ -42,9 +42,7 @@
 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"];
index 84c02bba4dcbfe64bfcfb14d91b94065316f1f42..6bb1032a17299108a9a2603662e5b25531e7114f 100644 (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 }
 
index bd5f9d1cf5f2ee62b4af834646760518cb568ac5..d50c919188be13c4ff4111fa17e604771453da13 100644 (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> {
index 016fdf959772a8320f12cd667168bccd44b0ceca..f278ee41aa335607a9f26dd265ddb16bcc9206d7 100644 (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 = ()> {
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^