Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Changes from 1 commit
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
0f46f27
Migrate most of `ide_assists::utils` to format arg capture
DropDemBits Oct 10, 2022
d439fb2
Migrate assists to format args captures, part 1
DropDemBits Oct 10, 2022
b1909a8
Migrate assists to format args captures, part 3
DropDemBits Oct 10, 2022
8ebc96a
fix broken links in guide.md
notJoon Oct 20, 2022
e4ef0e5
addressed https://github.com/rust-lang/rust-analyzer/issues/12536
justinmmott Oct 21, 2022
8039a07
ide: Generate monikers for local crates.
emilio Oct 22, 2022
c4bdb8e
feat: add config for inserting must_use in `generate_enum_as_method`
feniljain Oct 6, 2022
4bf9b9b
refactor: remove repetitive string interpolation and doc changes
feniljain Oct 24, 2022
4a7f5ca
fix: async trait method for `unnecessary_async`
koka831 Oct 28, 2022
cf90e4f
Simplify the procedure
koka831 Oct 29, 2022
319611b
Record diverging match arms in `InferenceResult`
unexge Oct 29, 2022
48efc9d
Add `Convert match to let-else` assist
unexge Oct 29, 2022
f0a1434
Update auto generated tests
unexge Oct 29, 2022
98125b9
fix: make custom expr prefix completions to understand refs
feniljain Oct 30, 2022
8142d1f
Auto merge of #13445 - notJoon:modify-dead-links, r=lnicola
bors Oct 31, 2022
db8c752
fix: disregard type variable expectation for if expressions
lowr Oct 31, 2022
07f6efc
Auto merge of #13523 - lowr:fix/adjust-expectation-for-if, r=lnicola
bors Oct 31, 2022
ecad1a9
Create `Callable`s for generic types implementing `FnOnce`
Nov 1, 2022
9f1bb17
Import `option` in the tests
Nov 1, 2022
e110c78
Revert "Record diverging match arms in `InferenceResult`"
Nov 1, 2022
72d5b45
Fix doc test
Nov 1, 2022
d90cb1e
Auto merge of #13516 - unexge:add-convert-match-to-let-else-assist, r…
bors Nov 1, 2022
a8e97bc
Auto merge of #13508 - koka831:fix/13492, r=jonas-schievink
bors Nov 1, 2022
c1305fa
Auto merge of #13525 - jonas-schievink:generic-call-signature, r=jona…
bors Nov 1, 2022
62a6cdf
Use let-else statements in `Convert to guarded return` assist
unexge Nov 1, 2022
12ced8f
Auto merge of #13517 - feniljain:fix_completions, r=Veykril
bors Nov 2, 2022
691ce30
fix: indentation after inserting `#must_use`
feniljain Nov 2, 2022
af1f48d
Auto merge of #13359 - feniljain:feat-must-use-option, r=Veykril
bors Nov 2, 2022
6c3ab56
Auto merge of #13527 - unexge:use-let-else-stmt-in-convert-to-guarded…
bors Nov 2, 2022
adee109
Bump ovsx
lnicola Nov 2, 2022
56c97a8
Auto merge of #13530 - lnicola:bump-ovsx, r=lnicola
bors Nov 2, 2022
08c2b45
docs: add crates section to the manual
pd4d10 Nov 3, 2022
6073e58
Allow ovsx publishing to fail
lnicola Nov 3, 2022
f3a6871
Auto merge of #13537 - lnicola:ovsx-fail, r=lnicola
bors Nov 3, 2022
bbcb77e
Auto merge of #13456 - emilio:scip-local-symbol, r=Veykril
bors Nov 3, 2022
6750f6b
Clarify what commands are debug commands in VSCode
Veykril Nov 3, 2022
3508820
Add rustbot features related to PR state labels
HKalbasi Nov 4, 2022
ad633db
Auto merge of #13544 - HKalbasi:patch-2, r=Veykril
bors Nov 4, 2022
6f09c72
Lower unsafety of fn pointer and fn item types
Veykril Nov 4, 2022
cd26032
Auto merge of #13546 - Veykril:unsafe-fn-ptr, r=Veykril
bors Nov 4, 2022
26b5621
Mark the Memory Usage command as debug command
Veykril Nov 4, 2022
66900a7
Auto merge of #13541 - Veykril:dbg-cmd, r=Veykril
bors Nov 4, 2022
df38770
Auto merge of #13454 - justinmmott:master, r=flodiebold
bors Nov 5, 2022
17619de
fix: Fix reference searching only accounting substrings instead of wh…
Veykril Nov 5, 2022
2c37e7d
Auto merge of #13549 - Veykril:search-fix, r=Veykril
bors Nov 5, 2022
afe8f6b
Auto merge of #13379 - DropDemBits:ide-assists-format-args-capture, r…
bors Nov 5, 2022
ef46168
minor: Update github issue templates
Veykril Nov 5, 2022
25b1d6f
Auto merge of #13435 - DropDemBits:assists-format-args-capture-pt3, r…
bors Nov 5, 2022
c06bbfb
Auto merge of #13536 - pd4d10:patch-1, r=Veykril
bors Nov 5, 2022
e47460b
Auto merge of #13550 - Veykril:issue-template, r=lnicola
bors Nov 5, 2022
935eb3f
docs: fix adoc links
pd4d10 Nov 5, 2022
d03c1c8
Auto merge of #13556 - pd4d10:patch-1, r=lnicola
bors Nov 5, 2022
c199a39
bootstrap: add support for running Miri on a file
RalfJung Nov 6, 2022
a9edee7
bootstrap: put Miri sysroot into local build dir
RalfJung Nov 6, 2022
aa5a326
Parser: Recover from using colon as path separator in imports
mucinoab Nov 9, 2022
35ef05a
Ignore "Change InferCtxtBuilder from enter to build" in git blame
Noratrieb Nov 9, 2022
4c197c0
docs
BoxyUwU Nov 9, 2022
8f9bc6d
Migrate crate-search element to CSS variables
GuillaumeGomez Nov 7, 2022
0e804b4
Extend crate-search div GUI tests
GuillaumeGomez Nov 7, 2022
dc76687
Update browser-ui-test version to 0.13.1
GuillaumeGomez Nov 8, 2022
75b5a98
Add new option to prevent CORS failures
GuillaumeGomez Nov 8, 2022
9f0e376
Update to new browser-ui-test version
GuillaumeGomez Nov 9, 2022
fbce7de
DiagnosticBuilder -> Diagnostic
compiler-errors Oct 6, 2022
e807cb3
Make span_suggestions take IntoIterator
compiler-errors Oct 7, 2022
9568138
rebase conflict
compiler-errors Nov 5, 2022
ff118a8
:arrow_up: rust-analyzer
lnicola Nov 9, 2022
4205ebd
Rollup merge of #102763 - compiler-errors:nits, r=cjgillot
notriddle Nov 10, 2022
08046db
Rollup merge of #103443 - mucinoab:recover-colon-as-path-separetor, r…
notriddle Nov 10, 2022
81405ad
Rollup merge of #104046 - RalfJung:run-miri-run, r=oli-obk
notriddle Nov 10, 2022
f598efc
Rollup merge of #104115 - GuillaumeGomez:migrate-crate-search-div, r=…
notriddle Nov 10, 2022
1a2aee6
Rollup merge of #104190 - Nilstrieb:patch-1, r=compiler-errors
notriddle Nov 10, 2022
a26b48a
Rollup merge of #104194 - BoxyUwU:early_binder_docs, r=compiler-errors
notriddle Nov 10, 2022
52f286d
Rollup merge of #104201 - GuillaumeGomez:gui-test-check-file-errors, …
notriddle Nov 10, 2022
2b5db56
Rollup merge of #104211 - lnicola:rust-analyzer-2022-11-09, r=lnicola
notriddle Nov 10, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: async trait method for unnecessary_async
  • Loading branch information
koka831 committed Oct 28, 2022
commit 4a7f5cac9dee32f3c8e43425339a2413b645bf39
67 changes: 65 additions & 2 deletions crates/ide-assists/src/handlers/unnecessary_async.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use hir::AssocItem;
use ide_db::{
assists::{AssistId, AssistKind},
base_db::FileId,
defs::Definition,
search::FileReference,
syntax_helpers::node_ext::full_path_of_name_ref,
traits::resolve_target_trait,
};
use syntax::{
ast::{self, NameLike, NameRef},
ast::{self, HasName, NameLike, NameRef},
AstNode, SyntaxKind, TextRange,
};

Expand Down Expand Up @@ -44,7 +46,16 @@ 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 an async member of trait.
if let Some(fname) = function.name() {
if let Some(trait_item) = find_corresponding_trait_member(ctx, fname.to_string()) {
if let AssocItem::Function(method) = trait_item {
if method.is_async(ctx.db()) {
return None;
}
}
}
}
// Remove the `async` keyword plus whitespace after it, if any.
let async_range = {
let async_token = function.async_token()?;
Expand Down Expand Up @@ -88,6 +99,23 @@ pub(crate) fn unnecessary_async(acc: &mut Assists, ctx: &AssistContext<'_>) -> O
)
}

fn find_corresponding_trait_member(
ctx: &AssistContext<'_>,
function_name: String,
) -> Option<AssocItem> {
let impl_ = ctx.find_node_at_offset::<ast::Impl>()?;
let trait_ = resolve_target_trait(&ctx.sema, &impl_)?;

trait_
.items(ctx.db())
.iter()
.find(|item| match item.name(ctx.db()) {
Some(method_name) => method_name.to_string() == function_name,
_ => false,
})
.cloned()
}

fn find_all_references(
ctx: &AssistContext<'_>,
def: &Definition,
Expand Down Expand Up @@ -254,4 +282,39 @@ 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 applies_on_unnecessary_async_on_trait_method() {
check_assist(
unnecessary_async,
r#"
trait Trait {
fn foo();
}
impl Trait for () {
$0async fn foo() {}
}"#,
r#"
trait Trait {
fn foo();
}
impl Trait for () {
fn foo() {}
}"#,
);
}

#[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() {}
}"#,
);
}
}