This commit is contained in:
Aleksey Kladov 2019-11-27 11:40:10 +03:00
parent aa45561183
commit a306531e6a
3 changed files with 29 additions and 19 deletions

View file

@ -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) => {

View file

@ -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),
}

View file

@ -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<AssociatedTyValue<ChalkIr>> {
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()),
};