From 2745cb37c16600c99083cefdf5eb45a5205dd86d Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Fri, 19 Jun 2020 16:29:38 +0200 Subject: Use correct substs for super trait assoc types When referring to an associated type of a super trait, we used the substs of the subtrait. That led to the #4931 crash if the subtrait had less parameters, but it could also lead to other incorrectness if just the order was different. Fixes #4931. --- crates/ra_hir_ty/src/utils.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'crates/ra_hir_ty/src/utils.rs') diff --git a/crates/ra_hir_ty/src/utils.rs b/crates/ra_hir_ty/src/utils.rs index f98350bf9..c45820ff0 100644 --- a/crates/ra_hir_ty/src/utils.rs +++ b/crates/ra_hir_ty/src/utils.rs @@ -143,13 +143,14 @@ pub(super) fn find_super_trait_path( } pub(super) fn associated_type_by_name_including_super_traits( - db: &dyn DefDatabase, - trait_: TraitId, + db: &dyn HirDatabase, + trait_ref: TraitRef, name: &Name, -) -> Option { - all_super_traits(db, trait_) - .into_iter() - .find_map(|t| db.trait_data(t).associated_type_by_name(name)) +) -> Option<(TraitRef, TypeAliasId)> { + all_super_trait_refs(db, trait_ref).into_iter().find_map(|t| { + let assoc_type = db.trait_data(t.trait_).associated_type_by_name(name)?; + Some((t, assoc_type)) + }) } pub(super) fn variant_data(db: &dyn DefDatabase, var: VariantId) -> Arc { @@ -176,6 +177,7 @@ pub(crate) fn generics(db: &dyn DefDatabase, def: GenericDefId) -> Generics { Generics { def, params: db.generic_params(def), parent_generics } } +#[derive(Debug)] pub(crate) struct Generics { def: GenericDefId, pub(crate) params: Arc, -- cgit v1.2.3