diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-11-25 10:12:03 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2019-11-25 10:12:03 +0000 |
commit | 9f7fcc6ecd5334c5e3caa365c4a6d7bf3f37b649 (patch) | |
tree | 5dda185ddeba593b7af36f66eeb6098e4f913c05 /crates/ra_hir/src/ty/infer | |
parent | e00e6554ddc13be86733dc8a37a0a229931f378a (diff) | |
parent | 8c3e372835243c922b0eff7ca23f79f227991e88 (diff) |
Merge #2397
2397: Remove Resolver from autoderef r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/ty/infer')
-rw-r--r-- | crates/ra_hir/src/ty/infer/coerce.rs | 13 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/infer/expr.rs | 40 |
2 files changed, 35 insertions, 18 deletions
diff --git a/crates/ra_hir/src/ty/infer/coerce.rs b/crates/ra_hir/src/ty/infer/coerce.rs index 54765da35..4b53bba73 100644 --- a/crates/ra_hir/src/ty/infer/coerce.rs +++ b/crates/ra_hir/src/ty/infer/coerce.rs | |||
@@ -14,7 +14,7 @@ use crate::{ | |||
14 | Adt, Mutability, | 14 | Adt, Mutability, |
15 | }; | 15 | }; |
16 | 16 | ||
17 | use super::{InferTy, InferenceContext, TypeVarValue}; | 17 | use super::{InEnvironment, InferTy, InferenceContext, TypeVarValue}; |
18 | 18 | ||
19 | impl<'a, D: HirDatabase> InferenceContext<'a, D> { | 19 | impl<'a, D: HirDatabase> InferenceContext<'a, D> { |
20 | /// Unify two types, but may coerce the first one to the second one | 20 | /// Unify two types, but may coerce the first one to the second one |
@@ -320,9 +320,14 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
320 | let canonicalized = self.canonicalizer().canonicalize_ty(from_ty.clone()); | 320 | let canonicalized = self.canonicalizer().canonicalize_ty(from_ty.clone()); |
321 | let to_ty = self.resolve_ty_shallow(&to_ty); | 321 | let to_ty = self.resolve_ty_shallow(&to_ty); |
322 | // FIXME: Auto DerefMut | 322 | // FIXME: Auto DerefMut |
323 | for derefed_ty in | 323 | for derefed_ty in autoderef::autoderef( |
324 | autoderef::autoderef(self.db, &self.resolver.clone(), canonicalized.value.clone()) | 324 | self.db, |
325 | { | 325 | self.resolver.krate(), |
326 | InEnvironment { | ||
327 | value: canonicalized.value.clone(), | ||
328 | environment: self.trait_env.clone(), | ||
329 | }, | ||
330 | ) { | ||
326 | let derefed_ty = canonicalized.decanonicalize_ty(derefed_ty.value); | 331 | let derefed_ty = canonicalized.decanonicalize_ty(derefed_ty.value); |
327 | match (&*self.resolve_ty_shallow(&derefed_ty), &*to_ty) { | 332 | match (&*self.resolve_ty_shallow(&derefed_ty), &*to_ty) { |
328 | // Stop when constructor matches. | 333 | // Stop when constructor matches. |
diff --git a/crates/ra_hir/src/ty/infer/expr.rs b/crates/ra_hir/src/ty/infer/expr.rs index 663ff9435..194e55819 100644 --- a/crates/ra_hir/src/ty/infer/expr.rs +++ b/crates/ra_hir/src/ty/infer/expr.rs | |||
@@ -15,9 +15,9 @@ use crate::{ | |||
15 | db::HirDatabase, | 15 | db::HirDatabase, |
16 | expr::{Array, BinaryOp, Expr, ExprId, Literal, Statement, UnaryOp}, | 16 | expr::{Array, BinaryOp, Expr, ExprId, Literal, Statement, UnaryOp}, |
17 | ty::{ | 17 | ty::{ |
18 | autoderef, method_resolution, op, CallableDef, InferTy, IntTy, Mutability, Namespace, | 18 | autoderef, method_resolution, op, traits::InEnvironment, CallableDef, InferTy, IntTy, |
19 | Obligation, ProjectionPredicate, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, TypeWalk, | 19 | Mutability, Namespace, Obligation, ProjectionPredicate, ProjectionTy, Substs, TraitRef, Ty, |
20 | Uncertain, | 20 | TypeCtor, TypeWalk, Uncertain, |
21 | }, | 21 | }, |
22 | Adt, Name, | 22 | Adt, Name, |
23 | }; | 23 | }; |
@@ -245,8 +245,11 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
245 | let canonicalized = self.canonicalizer().canonicalize_ty(receiver_ty); | 245 | let canonicalized = self.canonicalizer().canonicalize_ty(receiver_ty); |
246 | let ty = autoderef::autoderef( | 246 | let ty = autoderef::autoderef( |
247 | self.db, | 247 | self.db, |
248 | &self.resolver.clone(), | 248 | self.resolver.krate(), |
249 | canonicalized.value.clone(), | 249 | InEnvironment { |
250 | value: canonicalized.value.clone(), | ||
251 | environment: self.trait_env.clone(), | ||
252 | }, | ||
250 | ) | 253 | ) |
251 | .find_map(|derefed_ty| match canonicalized.decanonicalize_ty(derefed_ty.value) { | 254 | .find_map(|derefed_ty| match canonicalized.decanonicalize_ty(derefed_ty.value) { |
252 | Ty::Apply(a_ty) => match a_ty.ctor { | 255 | Ty::Apply(a_ty) => match a_ty.ctor { |
@@ -337,16 +340,25 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
337 | Expr::UnaryOp { expr, op } => { | 340 | Expr::UnaryOp { expr, op } => { |
338 | let inner_ty = self.infer_expr(*expr, &Expectation::none()); | 341 | let inner_ty = self.infer_expr(*expr, &Expectation::none()); |
339 | match op { | 342 | match op { |
340 | UnaryOp::Deref => { | 343 | UnaryOp::Deref => match self.resolver.krate() { |
341 | let canonicalized = self.canonicalizer().canonicalize_ty(inner_ty); | 344 | Some(krate) => { |
342 | if let Some(derefed_ty) = | 345 | let canonicalized = self.canonicalizer().canonicalize_ty(inner_ty); |
343 | autoderef::deref(self.db, &self.resolver, &canonicalized.value) | 346 | match autoderef::deref( |
344 | { | 347 | self.db, |
345 | canonicalized.decanonicalize_ty(derefed_ty.value) | 348 | krate, |
346 | } else { | 349 | InEnvironment { |
347 | Ty::Unknown | 350 | value: &canonicalized.value, |
351 | environment: self.trait_env.clone(), | ||
352 | }, | ||
353 | ) { | ||
354 | Some(derefed_ty) => { | ||
355 | canonicalized.decanonicalize_ty(derefed_ty.value) | ||
356 | } | ||
357 | None => Ty::Unknown, | ||
358 | } | ||
348 | } | 359 | } |
349 | } | 360 | None => Ty::Unknown, |
361 | }, | ||
350 | UnaryOp::Neg => { | 362 | UnaryOp::Neg => { |
351 | match &inner_ty { | 363 | match &inner_ty { |
352 | Ty::Apply(a_ty) => match a_ty.ctor { | 364 | Ty::Apply(a_ty) => match a_ty.ctor { |