diff --git a/crates/ra_hir/src/ty/method_resolution.rs b/crates/ra_hir/src/ty/method_resolution.rs index 92645e2a52..7df2649c90 100644 --- a/crates/ra_hir/src/ty/method_resolution.rs +++ b/crates/ra_hir/src/ty/method_resolution.rs @@ -62,7 +62,7 @@ impl CrateImplBlocks { let impl_data = db.impl_data(impl_id); let resolver = impl_id.resolver(db); - let target_ty = { Ty::from_hir(db, &resolver, &impl_data.target_type) }; + let target_ty = Ty::from_hir(db, &resolver, &impl_data.target_type); match &impl_data.target_trait { Some(trait_ref) => { diff --git a/crates/ra_hir/src/ty/traits.rs b/crates/ra_hir/src/ty/traits.rs index 39b489a4c9..99afeb35f2 100644 --- a/crates/ra_hir/src/ty/traits.rs +++ b/crates/ra_hir/src/ty/traits.rs @@ -2,13 +2,13 @@ use std::sync::{Arc, Mutex}; use chalk_ir::{cast::Cast, family::ChalkIr}; -use hir_def::{expr::ExprId, DefWithBodyId, TraitId}; +use hir_def::{expr::ExprId, DefWithBodyId, TraitId, TypeAliasId}; use log::debug; use ra_db::{impl_intern_key, salsa, CrateId}; use ra_prof::profile; use rustc_hash::FxHashSet; -use crate::{db::HirDatabase, ImplBlock, TypeAlias}; +use crate::{db::HirDatabase, ImplBlock}; use super::{Canonical, GenericPredicate, HirDisplay, ProjectionTy, TraitRef, Ty, TypeWalk}; @@ -317,7 +317,7 @@ impl_intern_key!(GlobalImplId); #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum AssocTyValue { /// A normal assoc type value from an impl block. - TypeAlias(TypeAlias), + TypeAlias(TypeAliasId), /// The output type of the Fn trait implementation. ClosureFnTraitImplOutput(ClosureFnTraitImplData), } diff --git a/crates/ra_hir/src/ty/traits/chalk.rs b/crates/ra_hir/src/ty/traits/chalk.rs index 49fa955081..76ff6f67ff 100644 --- a/crates/ra_hir/src/ty/traits/chalk.rs +++ b/crates/ra_hir/src/ty/traits/chalk.rs @@ -11,7 +11,8 @@ use chalk_rust_ir::{AssociatedTyDatum, AssociatedTyValue, ImplDatum, StructDatum use ra_db::CrateId; use hir_def::{ - lang_item::LangItemTarget, AstItemDef, ContainerId, GenericDefId, Lookup, TraitId, TypeAliasId, + lang_item::LangItemTarget, resolver::HasResolver, AstItemDef, ContainerId, GenericDefId, + Lookup, TraitId, TypeAliasId, }; use hir_expand::name; @@ -22,7 +23,7 @@ use crate::{ db::HirDatabase, ty::display::HirDisplay, ty::{ApplicationTy, GenericPredicate, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, TypeWalk}, - ImplBlock, TypeAlias, + ImplBlock, }; /// This represents a trait whose name we could not resolve. @@ -670,7 +671,7 @@ fn impl_block_datum( // don't include associated types that don't exist in the trait trait_data.associated_type_by_name(&type_alias.name(db)).is_some() }) - .map(|type_alias| AssocTyValue::TypeAlias(type_alias).to_chalk(db)) + .map(|type_alias| AssocTyValue::TypeAlias(type_alias.id).to_chalk(db)) .collect(); debug!("impl_datum: {:?}", impl_datum_bound); let impl_datum = ImplDatum { @@ -773,24 +774,33 @@ pub(crate) fn associated_ty_value_query( fn type_alias_associated_ty_value( db: &impl HirDatabase, _krate: CrateId, - type_alias: TypeAlias, + type_alias: TypeAliasId, ) -> Arc> { - let impl_block = type_alias.impl_block(db).expect("assoc ty value should be in impl"); - let impl_id = Impl::ImplBlock(impl_block).to_chalk(db); - let trait_ = impl_block - .target_trait_ref(db) - .expect("assoc ty value should not exist") // we don't return any assoc ty values if the impl'd trait can't be resolved - .trait_; + let type_alias_data = db.type_alias_data(type_alias); + let impl_id = match type_alias.lookup(db).container { + ContainerId::ImplId(it) => it, + _ => panic!("assoc ty value should be in impl"), + }; + + let impl_data = db.impl_data(impl_id); + let resolver = impl_id.resolver(db); + let target_ty = Ty::from_hir(db, &resolver, &impl_data.target_type); + let target_trait = impl_data + .target_trait + .as_ref() + .and_then(|trait_ref| TraitRef::from_hir(db, &resolver, &trait_ref, Some(target_ty))) + .expect("assoc ty value should not exist"); // we don't return any assoc ty values if the impl'd trait can't be resolved + let assoc_ty = db - .trait_data(trait_) - .associated_type_by_name(&type_alias.name(db)) + .trait_data(target_trait.trait_) + .associated_type_by_name(&type_alias_data.name) .expect("assoc ty value should not exist"); // validated when building the impl data as well - let generic_params = db.generic_params(impl_block.id.into()); + let generic_params = db.generic_params(impl_id.into()); let bound_vars = Substs::bound_vars(&generic_params); - let ty = db.ty(type_alias.id.into()).subst(&bound_vars); + let ty = db.ty(type_alias.into()).subst(&bound_vars); let value_bound = chalk_rust_ir::AssociatedTyValueBound { ty: ty.to_chalk(db) }; let value = chalk_rust_ir::AssociatedTyValue { - impl_id, + impl_id: Impl::ImplBlock(impl_id.into()).to_chalk(db), associated_ty_id: assoc_ty.to_chalk(db), value: make_binders(value_bound, bound_vars.len()), };