Skip to content

Commit a306531

Browse files
committed
Decouple
1 parent aa45561 commit a306531

File tree

3 files changed

+29
-19
lines changed

3 files changed

+29
-19
lines changed

crates/ra_hir/src/ty/method_resolution.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl CrateImplBlocks {
6262
let impl_data = db.impl_data(impl_id);
6363
let resolver = impl_id.resolver(db);
6464

65-
let target_ty = { Ty::from_hir(db, &resolver, &impl_data.target_type) };
65+
let target_ty = Ty::from_hir(db, &resolver, &impl_data.target_type);
6666

6767
match &impl_data.target_trait {
6868
Some(trait_ref) => {

crates/ra_hir/src/ty/traits.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
use std::sync::{Arc, Mutex};
33

44
use chalk_ir::{cast::Cast, family::ChalkIr};
5-
use hir_def::{expr::ExprId, DefWithBodyId, TraitId};
5+
use hir_def::{expr::ExprId, DefWithBodyId, TraitId, TypeAliasId};
66
use log::debug;
77
use ra_db::{impl_intern_key, salsa, CrateId};
88
use ra_prof::profile;
99
use rustc_hash::FxHashSet;
1010

11-
use crate::{db::HirDatabase, ImplBlock, TypeAlias};
11+
use crate::{db::HirDatabase, ImplBlock};
1212

1313
use super::{Canonical, GenericPredicate, HirDisplay, ProjectionTy, TraitRef, Ty, TypeWalk};
1414

@@ -317,7 +317,7 @@ impl_intern_key!(GlobalImplId);
317317
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
318318
pub enum AssocTyValue {
319319
/// A normal assoc type value from an impl block.
320-
TypeAlias(TypeAlias),
320+
TypeAlias(TypeAliasId),
321321
/// The output type of the Fn trait implementation.
322322
ClosureFnTraitImplOutput(ClosureFnTraitImplData),
323323
}

crates/ra_hir/src/ty/traits/chalk.rs

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ use chalk_rust_ir::{AssociatedTyDatum, AssociatedTyValue, ImplDatum, StructDatum
1111
use ra_db::CrateId;
1212

1313
use hir_def::{
14-
lang_item::LangItemTarget, AstItemDef, ContainerId, GenericDefId, Lookup, TraitId, TypeAliasId,
14+
lang_item::LangItemTarget, resolver::HasResolver, AstItemDef, ContainerId, GenericDefId,
15+
Lookup, TraitId, TypeAliasId,
1516
};
1617
use hir_expand::name;
1718

@@ -22,7 +23,7 @@ use crate::{
2223
db::HirDatabase,
2324
ty::display::HirDisplay,
2425
ty::{ApplicationTy, GenericPredicate, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, TypeWalk},
25-
ImplBlock, TypeAlias,
26+
ImplBlock,
2627
};
2728

2829
/// This represents a trait whose name we could not resolve.
@@ -670,7 +671,7 @@ fn impl_block_datum(
670671
// don't include associated types that don't exist in the trait
671672
trait_data.associated_type_by_name(&type_alias.name(db)).is_some()
672673
})
673-
.map(|type_alias| AssocTyValue::TypeAlias(type_alias).to_chalk(db))
674+
.map(|type_alias| AssocTyValue::TypeAlias(type_alias.id).to_chalk(db))
674675
.collect();
675676
debug!("impl_datum: {:?}", impl_datum_bound);
676677
let impl_datum = ImplDatum {
@@ -773,24 +774,33 @@ pub(crate) fn associated_ty_value_query(
773774
fn type_alias_associated_ty_value(
774775
db: &impl HirDatabase,
775776
_krate: CrateId,
776-
type_alias: TypeAlias,
777+
type_alias: TypeAliasId,
777778
) -> Arc<AssociatedTyValue<ChalkIr>> {
778-
let impl_block = type_alias.impl_block(db).expect("assoc ty value should be in impl");
779-
let impl_id = Impl::ImplBlock(impl_block).to_chalk(db);
780-
let trait_ = impl_block
781-
.target_trait_ref(db)
782-
.expect("assoc ty value should not exist") // we don't return any assoc ty values if the impl'd trait can't be resolved
783-
.trait_;
779+
let type_alias_data = db.type_alias_data(type_alias);
780+
let impl_id = match type_alias.lookup(db).container {
781+
ContainerId::ImplId(it) => it,
782+
_ => panic!("assoc ty value should be in impl"),
783+
};
784+
785+
let impl_data = db.impl_data(impl_id);
786+
let resolver = impl_id.resolver(db);
787+
let target_ty = Ty::from_hir(db, &resolver, &impl_data.target_type);
788+
let target_trait = impl_data
789+
.target_trait
790+
.as_ref()
791+
.and_then(|trait_ref| TraitRef::from_hir(db, &resolver, &trait_ref, Some(target_ty)))
792+
.expect("assoc ty value should not exist"); // we don't return any assoc ty values if the impl'd trait can't be resolved
793+
784794
let assoc_ty = db
785-
.trait_data(trait_)
786-
.associated_type_by_name(&type_alias.name(db))
795+
.trait_data(target_trait.trait_)
796+
.associated_type_by_name(&type_alias_data.name)
787797
.expect("assoc ty value should not exist"); // validated when building the impl data as well
788-
let generic_params = db.generic_params(impl_block.id.into());
798+
let generic_params = db.generic_params(impl_id.into());
789799
let bound_vars = Substs::bound_vars(&generic_params);
790-
let ty = db.ty(type_alias.id.into()).subst(&bound_vars);
800+
let ty = db.ty(type_alias.into()).subst(&bound_vars);
791801
let value_bound = chalk_rust_ir::AssociatedTyValueBound { ty: ty.to_chalk(db) };
792802
let value = chalk_rust_ir::AssociatedTyValue {
793-
impl_id,
803+
impl_id: Impl::ImplBlock(impl_id.into()).to_chalk(db),
794804
associated_ty_id: assoc_ty.to_chalk(db),
795805
value: make_binders(value_bound, bound_vars.len()),
796806
};

0 commit comments

Comments
 (0)