From 3a0929fca7a52605526c6f89be4e3e86c5d0359d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 27 Nov 2019 12:02:54 +0300 Subject: Decouple --- crates/ra_hir/src/ty/infer/coerce.rs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'crates/ra_hir/src/ty/infer/coerce.rs') diff --git a/crates/ra_hir/src/ty/infer/coerce.rs b/crates/ra_hir/src/ty/infer/coerce.rs index 5ed4470af..cf45ede7c 100644 --- a/crates/ra_hir/src/ty/infer/coerce.rs +++ b/crates/ra_hir/src/ty/infer/coerce.rs @@ -4,13 +4,17 @@ //! //! See: https://doc.rust-lang.org/nomicon/coercions.html -use hir_def::{lang_item::LangItemTarget, resolver::Resolver, AdtId}; +use hir_def::{ + lang_item::LangItemTarget, + resolver::{HasResolver, Resolver}, + AdtId, +}; use rustc_hash::FxHashMap; use test_utils::tested_by; use crate::{ db::HirDatabase, - ty::{autoderef, Substs, Ty, TypeCtor, TypeWalk}, + ty::{autoderef, Substs, TraitRef, Ty, TypeCtor, TypeWalk}, Mutability, }; @@ -57,9 +61,18 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { impls .iter() - .filter_map(|impl_block| { + .filter_map(|&impl_id| { + 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); + // `CoerseUnsized` has one generic parameter for the target type. - let trait_ref = impl_block.target_trait_ref(db)?; + let trait_ref = TraitRef::from_hir( + db, + &resolver, + impl_data.target_trait.as_ref()?, + Some(target_ty), + )?; let cur_from_ty = trait_ref.substs.0.get(0)?; let cur_to_ty = trait_ref.substs.0.get(1)?; -- cgit v1.2.3