mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 21:43:37 +00:00
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
This commit is contained in:
commit
a8e97bcf3c
1 changed files with 20 additions and 0 deletions
|
@ -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() {}
|
||||
}"#,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue