Skip to content

Commit a8e97bc

Browse files
committed
Auto merge of #13508 - koka831:fix/13492, r=jonas-schievink
fix: async trait method for `unnecessary_async` Fix #13492
2 parents d90cb1e + cf90e4f commit a8e97bc

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

crates/ide-assists/src/handlers/unnecessary_async.rs

+20
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ pub(crate) fn unnecessary_async(acc: &mut Assists, ctx: &AssistContext<'_>) -> O
4444
if function.body()?.syntax().descendants().find_map(ast::AwaitExpr::cast).is_some() {
4545
return None;
4646
}
47+
// Do nothing if the method is a member of trait.
48+
if let Some(impl_) = function.syntax().ancestors().nth(2).and_then(ast::Impl::cast) {
49+
if let Some(_) = impl_.trait_() {
50+
return None;
51+
}
52+
}
4753

4854
// Remove the `async` keyword plus whitespace after it, if any.
4955
let async_range = {
@@ -254,4 +260,18 @@ pub async fn f(s: &S) { s.f2() }"#,
254260
fn does_not_apply_when_not_on_prototype() {
255261
check_assist_not_applicable(unnecessary_async, "pub async fn f() { $0f2() }")
256262
}
263+
264+
#[test]
265+
fn does_not_apply_on_async_trait_method() {
266+
check_assist_not_applicable(
267+
unnecessary_async,
268+
r#"
269+
trait Trait {
270+
async fn foo();
271+
}
272+
impl Trait for () {
273+
$0async fn foo() {}
274+
}"#,
275+
);
276+
}
257277
}

0 commit comments

Comments
 (0)