diff options
author | Florian Diebold <[email protected]> | 2021-04-03 20:59:13 +0100 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2021-04-04 12:16:38 +0100 |
commit | 77333a571ffb401a6765bbc80dea082ad08238d9 (patch) | |
tree | d43b8f7881fc361ee347b32a2a19bbeee5ee1501 /crates | |
parent | 66fec39aa04ea59ac39d52f0872c0a6c52a27e35 (diff) |
More TyBuilder use
Diffstat (limited to 'crates')
-rw-r--r-- | crates/hir_ty/src/infer/coerce.rs | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/crates/hir_ty/src/infer/coerce.rs b/crates/hir_ty/src/infer/coerce.rs index 744f30a93..ed8c677a8 100644 --- a/crates/hir_ty/src/infer/coerce.rs +++ b/crates/hir_ty/src/infer/coerce.rs | |||
@@ -8,7 +8,7 @@ use chalk_ir::{cast::Cast, Mutability, TyVariableKind}; | |||
8 | use hir_def::lang_item::LangItemTarget; | 8 | use hir_def::lang_item::LangItemTarget; |
9 | 9 | ||
10 | use crate::{ | 10 | use crate::{ |
11 | autoderef, to_chalk_trait_id, traits::Solution, Interner, Substitution, TraitRef, Ty, | 11 | autoderef, traits::Solution, Interner, Ty, |
12 | TyBuilder, TyKind, | 12 | TyBuilder, TyKind, |
13 | }; | 13 | }; |
14 | 14 | ||
@@ -131,18 +131,15 @@ impl<'a> InferenceContext<'a> { | |||
131 | _ => return None, | 131 | _ => return None, |
132 | }; | 132 | }; |
133 | 133 | ||
134 | let generic_params = crate::utils::generics(self.db.upcast(), coerce_unsized_trait.into()); | 134 | let trait_ref = { |
135 | if generic_params.len() != 2 { | 135 | let b = TyBuilder::trait_ref(self.db, coerce_unsized_trait); |
136 | // The CoerceUnsized trait should have two generic params: Self and T. | 136 | if b.remaining() != 2 { |
137 | return None; | 137 | // The CoerceUnsized trait should have two generic params: Self and T. |
138 | } | 138 | return None; |
139 | } | ||
140 | b.push(from_ty.clone()).push(to_ty.clone()).build() | ||
141 | }; | ||
139 | 142 | ||
140 | let substs = Substitution::build_for_generics(&generic_params) | ||
141 | .push(from_ty.clone()) | ||
142 | .push(to_ty.clone()) | ||
143 | .build(); | ||
144 | let trait_ref = | ||
145 | TraitRef { trait_id: to_chalk_trait_id(coerce_unsized_trait), substitution: substs }; | ||
146 | let goal = InEnvironment::new(self.trait_env.env.clone(), trait_ref.cast(&Interner)); | 143 | let goal = InEnvironment::new(self.trait_env.env.clone(), trait_ref.cast(&Interner)); |
147 | 144 | ||
148 | let canonicalizer = self.canonicalizer(); | 145 | let canonicalizer = self.canonicalizer(); |