aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/infer.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_ty/src/infer.rs')
-rw-r--r--crates/hir_ty/src/infer.rs18
1 files changed, 7 insertions, 11 deletions
diff --git a/crates/hir_ty/src/infer.rs b/crates/hir_ty/src/infer.rs
index 0ee851a74..2a82f1b47 100644
--- a/crates/hir_ty/src/infer.rs
+++ b/crates/hir_ty/src/infer.rs
@@ -217,7 +217,7 @@ struct InferenceContext<'a> {
217 owner: DefWithBodyId, 217 owner: DefWithBodyId,
218 body: Arc<Body>, 218 body: Arc<Body>,
219 resolver: Resolver, 219 resolver: Resolver,
220 table: unify::InferenceTable, 220 table: unify::InferenceTable<'a>,
221 trait_env: Arc<TraitEnvironment>, 221 trait_env: Arc<TraitEnvironment>,
222 obligations: Vec<DomainGoal>, 222 obligations: Vec<DomainGoal>,
223 last_obligations_check: Option<u32>, 223 last_obligations_check: Option<u32>,
@@ -252,15 +252,15 @@ fn find_breakable<'c>(
252 252
253impl<'a> InferenceContext<'a> { 253impl<'a> InferenceContext<'a> {
254 fn new(db: &'a dyn HirDatabase, owner: DefWithBodyId, resolver: Resolver) -> Self { 254 fn new(db: &'a dyn HirDatabase, owner: DefWithBodyId, resolver: Resolver) -> Self {
255 let trait_env =
256 owner.as_generic_def_id().map_or_else(Default::default, |d| db.trait_environment(d));
255 InferenceContext { 257 InferenceContext {
256 result: InferenceResult::default(), 258 result: InferenceResult::default(),
257 table: unify::InferenceTable::new(), 259 table: unify::InferenceTable::new(db, trait_env.clone()),
258 obligations: Vec::default(), 260 obligations: Vec::default(),
259 last_obligations_check: None, 261 last_obligations_check: None,
260 return_ty: TyKind::Error.intern(&Interner), // set in collect_fn_signature 262 return_ty: TyKind::Error.intern(&Interner), // set in collect_fn_signature
261 trait_env: owner 263 trait_env,
262 .as_generic_def_id()
263 .map_or_else(Default::default, |d| db.trait_environment(d)),
264 db, 264 db,
265 owner, 265 owner,
266 body: db.body(owner), 266 body: db.body(owner),
@@ -346,17 +346,12 @@ impl<'a> InferenceContext<'a> {
346 } 346 }
347 347
348 fn resolve_obligations_as_possible(&mut self) { 348 fn resolve_obligations_as_possible(&mut self) {
349 if self.last_obligations_check == Some(self.table.revision) {
350 // no change
351 return;
352 }
353 let _span = profile::span("resolve_obligations_as_possible"); 349 let _span = profile::span("resolve_obligations_as_possible");
354 350
355 self.last_obligations_check = Some(self.table.revision);
356 let obligations = mem::replace(&mut self.obligations, Vec::new()); 351 let obligations = mem::replace(&mut self.obligations, Vec::new());
357 for obligation in obligations { 352 for obligation in obligations {
358 let in_env = InEnvironment::new(&self.trait_env.env, obligation.clone()); 353 let in_env = InEnvironment::new(&self.trait_env.env, obligation.clone());
359 let canonicalized = self.canonicalizer().canonicalize_obligation(in_env); 354 let canonicalized = self.canonicalize(in_env);
360 let solution = 355 let solution =
361 self.db.trait_solve(self.resolver.krate().unwrap(), canonicalized.value.clone()); 356 self.db.trait_solve(self.resolver.krate().unwrap(), canonicalized.value.clone());
362 357
@@ -395,6 +390,7 @@ impl<'a> InferenceContext<'a> {
395 self.table.unify(ty1, ty2) 390 self.table.unify(ty1, ty2)
396 } 391 }
397 392
393 // FIXME get rid of this, instead resolve shallowly where necessary
398 /// Resolves the type as far as currently possible, replacing type variables 394 /// Resolves the type as far as currently possible, replacing type variables
399 /// by their known types. All types returned by the infer_* functions should 395 /// by their known types. All types returned by the infer_* functions should
400 /// be resolved as far as possible, i.e. contain no type variables with 396 /// be resolved as far as possible, i.e. contain no type variables with