Auto merge of #16100 - Young-Flash:assoc_func_quickfix, r=Veykril

feat: add assoc func quickfix for `unresolved_method` diagnostic

![demo](1ea1d8b8-3436-4251-a512-e0f9de01a13c)

close https://github.com/rust-lang/rust-analyzer/issues/13247

EDIT: I think add a demo gif would be helpful to `@lnicola` when he make a release change log :)
This commit is contained in:
bors 2024-01-02 13:46:35 +00:00
commit f7a29e4e88
5 changed files with 220 additions and 9 deletions

View file

@ -8,7 +8,7 @@ pub use hir_ty::diagnostics::{CaseType, IncorrectCase};
use base_db::CrateId;
use cfg::{CfgExpr, CfgOptions};
use either::Either;
use hir_def::path::ModPath;
use hir_def::{path::ModPath, AssocItemId};
use hir_expand::{name::Name, HirFileId, InFile};
use syntax::{ast, AstPtr, SyntaxError, SyntaxNodePtr, TextRange};
@ -215,6 +215,7 @@ pub struct UnresolvedMethodCall {
pub receiver: Type,
pub name: Name,
pub field_with_same_name: Option<Type>,
pub assoc_func_with_same_name: Option<AssocItemId>,
}
#[derive(Debug)]

View file

@ -1680,6 +1680,7 @@ impl DefWithBody {
receiver,
name,
field_with_same_name,
assoc_func_with_same_name,
} => {
let expr = expr_syntax(*expr);
@ -1691,6 +1692,7 @@ impl DefWithBody {
field_with_same_name: field_with_same_name
.clone()
.map(|ty| Type::new(db, DefWithBodyId::from(self), ty)),
assoc_func_with_same_name: assoc_func_with_same_name.clone(),
}
.into(),
)