about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-11-01 16:38:40 +0000
committerbors <bors@rust-lang.org>2022-11-01 16:38:40 +0000
commita8e97bcf3c830f5f6c5a0a90ac5a9a989ea7b34b (patch)
tree25790011a8a0efe46ed0b28d782dbcd49ad98a69
parentd90cb1e77249856d530a522769048f4430933fde (diff)
parentcf90e4f32b677ac1cea2a14d1d041c0c0cb3db28 (diff)
downloadrust-a8e97bcf3c830f5f6c5a0a90ac5a9a989ea7b34b.tar.gz
rust-a8e97bcf3c830f5f6c5a0a90ac5a9a989ea7b34b.zip
Auto merge of #13508 - koka831:fix/13492, r=jonas-schievink
fix: async trait method for `unnecessary_async`

Fix https://github.com/rust-lang/rust-analyzer/issues/13492
-rw-r--r--crates/ide-assists/src/handlers/unnecessary_async.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/crates/ide-assists/src/handlers/unnecessary_async.rs b/crates/ide-assists/src/handlers/unnecessary_async.rs
index d5cd2d55134..04398832253 100644
--- a/crates/ide-assists/src/handlers/unnecessary_async.rs
+++ b/crates/ide-assists/src/handlers/unnecessary_async.rs
@@ -44,6 +44,12 @@ pub(crate) fn unnecessary_async(acc: &mut Assists, ctx: &AssistContext<'_>) -> O
     if function.body()?.syntax().descendants().find_map(ast::AwaitExpr::cast).is_some() {
         return None;
     }
+    // Do nothing if the method is a member of trait.
+    if let Some(impl_) = function.syntax().ancestors().nth(2).and_then(ast::Impl::cast) {
+        if let Some(_) = impl_.trait_() {
+            return None;
+        }
+    }
 
     // Remove the `async` keyword plus whitespace after it, if any.
     let async_range = {
@@ -254,4 +260,18 @@ pub async fn f(s: &S) { s.f2() }"#,
     fn does_not_apply_when_not_on_prototype() {
         check_assist_not_applicable(unnecessary_async, "pub async fn f() { $0f2() }")
     }
+
+    #[test]
+    fn does_not_apply_on_async_trait_method() {
+        check_assist_not_applicable(
+            unnecessary_async,
+            r#"
+trait Trait {
+    async fn foo();
+}
+impl Trait for () {
+    $0async fn foo() {}
+}"#,
+        );
+    }
 }