mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-03 07:04:49 +00:00
Resolve assoc. types of supertraits in the IDE layer
This commit is contained in:
parent
c42cb9af48
commit
7e45915aa4
3 changed files with 23 additions and 3 deletions
|
@ -54,7 +54,7 @@ use hir_def::{
|
||||||
};
|
};
|
||||||
use hir_expand::{name::name, MacroCallKind};
|
use hir_expand::{name::name, MacroCallKind};
|
||||||
use hir_ty::{
|
use hir_ty::{
|
||||||
autoderef,
|
all_super_traits, autoderef,
|
||||||
consteval::{unknown_const_as_generic, ComputedExpr, ConstEvalError, ConstExt},
|
consteval::{unknown_const_as_generic, ComputedExpr, ConstEvalError, ConstExt},
|
||||||
diagnostics::BodyValidationDiagnostic,
|
diagnostics::BodyValidationDiagnostic,
|
||||||
method_resolution::{self, TyFingerprint},
|
method_resolution::{self, TyFingerprint},
|
||||||
|
@ -1676,6 +1676,11 @@ impl Trait {
|
||||||
db.trait_data(self.id).items.iter().map(|(_name, it)| (*it).into()).collect()
|
db.trait_data(self.id).items.iter().map(|(_name, it)| (*it).into()).collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn items_with_supertraits(self, db: &dyn HirDatabase) -> Vec<AssocItem> {
|
||||||
|
let traits = all_super_traits(db.upcast(), self.into());
|
||||||
|
traits.iter().flat_map(|tr| Trait::from(*tr).items(db)).collect()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn is_auto(self, db: &dyn HirDatabase) -> bool {
|
pub fn is_auto(self, db: &dyn HirDatabase) -> bool {
|
||||||
db.trait_data(self.id).is_auto
|
db.trait_data(self.id).is_auto
|
||||||
}
|
}
|
||||||
|
|
|
@ -386,9 +386,8 @@ impl NameRefClass {
|
||||||
let containing_path = name_ref.syntax().ancestors().find_map(ast::Path::cast)?;
|
let containing_path = name_ref.syntax().ancestors().find_map(ast::Path::cast)?;
|
||||||
let resolved = sema.resolve_path(&containing_path)?;
|
let resolved = sema.resolve_path(&containing_path)?;
|
||||||
if let PathResolution::Def(ModuleDef::Trait(tr)) = resolved {
|
if let PathResolution::Def(ModuleDef::Trait(tr)) = resolved {
|
||||||
// FIXME: resolve in supertraits
|
|
||||||
if let Some(ty) = tr
|
if let Some(ty) = tr
|
||||||
.items(sema.db)
|
.items_with_supertraits(sema.db)
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|&assoc| match assoc {
|
.filter_map(|&assoc| match assoc {
|
||||||
hir::AssocItem::TypeAlias(it) => Some(it),
|
hir::AssocItem::TypeAlias(it) => Some(it),
|
||||||
|
|
|
@ -1012,6 +1012,22 @@ fn f() -> impl Iterator<Item$0 = u8> {}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn goto_def_for_super_assoc_ty_in_path() {
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
trait Super {
|
||||||
|
type Item;
|
||||||
|
//^^^^
|
||||||
|
}
|
||||||
|
|
||||||
|
trait Sub: Super {}
|
||||||
|
|
||||||
|
fn f() -> impl Sub<Item$0 = u8> {}
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn unknown_assoc_ty() {
|
fn unknown_assoc_ty() {
|
||||||
check_unresolved(
|
check_unresolved(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue