mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 12:54:58 +00:00
Auto merge of #15026 - lowr:fix/deduplicate-compl-fields, r=Veykril
fix: deduplicate fields and types in completion Fixes #15024 - `hir_ty::autoderef()` (which is only meant to be used outside `hir-ty`) now deduplicates types and completely resolves inference variables within. - field completion now deduplicates fields of the same name and only picks such field of the first type in the deref chain.
This commit is contained in:
commit
6b3659d38f
3 changed files with 118 additions and 6 deletions
|
@ -3818,14 +3818,16 @@ impl Type {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn autoderef<'a>(&'a self, db: &'a dyn HirDatabase) -> impl Iterator<Item = Type> + 'a {
|
||||
/// Returns types that this type dereferences to (including this type itself). The returned
|
||||
/// iterator won't yield the same type more than once even if the deref chain contains a cycle.
|
||||
pub fn autoderef(&self, db: &dyn HirDatabase) -> impl Iterator<Item = Type> + '_ {
|
||||
self.autoderef_(db).map(move |ty| self.derived(ty))
|
||||
}
|
||||
|
||||
fn autoderef_<'a>(&'a self, db: &'a dyn HirDatabase) -> impl Iterator<Item = Ty> + 'a {
|
||||
fn autoderef_(&self, db: &dyn HirDatabase) -> impl Iterator<Item = Ty> {
|
||||
// There should be no inference vars in types passed here
|
||||
let canonical = hir_ty::replace_errors_with_variables(&self.ty);
|
||||
autoderef(db, self.env.clone(), canonical).map(|canonical| canonical.value)
|
||||
autoderef(db, self.env.clone(), canonical)
|
||||
}
|
||||
|
||||
// This would be nicer if it just returned an iterator, but that runs into
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue