diff options
Diffstat (limited to 'crates/ra_hir_ty/src/infer')
-rw-r--r-- | crates/ra_hir_ty/src/infer/expr.rs | 37 |
1 files changed, 23 insertions, 14 deletions
diff --git a/crates/ra_hir_ty/src/infer/expr.rs b/crates/ra_hir_ty/src/infer/expr.rs index b28724f0e..54bab3476 100644 --- a/crates/ra_hir_ty/src/infer/expr.rs +++ b/crates/ra_hir_ty/src/infer/expr.rs | |||
@@ -17,8 +17,8 @@ use crate::{ | |||
17 | autoderef, method_resolution, op, | 17 | autoderef, method_resolution, op, |
18 | traits::InEnvironment, | 18 | traits::InEnvironment, |
19 | utils::{generics, variant_data, Generics}, | 19 | utils::{generics, variant_data, Generics}, |
20 | ApplicationTy, Binders, CallableDef, InferTy, IntTy, Mutability, Obligation, Substs, TraitRef, | 20 | ApplicationTy, Binders, CallableDef, InferTy, IntTy, Mutability, Obligation, Rawness, Substs, |
21 | Ty, TypeCtor, Uncertain, | 21 | TraitRef, Ty, TypeCtor, Uncertain, |
22 | }; | 22 | }; |
23 | 23 | ||
24 | use super::{ | 24 | use super::{ |
@@ -350,19 +350,28 @@ impl<'a> InferenceContext<'a> { | |||
350 | // FIXME check the cast... | 350 | // FIXME check the cast... |
351 | cast_ty | 351 | cast_ty |
352 | } | 352 | } |
353 | Expr::Ref { expr, mutability } => { | 353 | Expr::Ref { expr, rawness, mutability } => { |
354 | let expectation = | 354 | let expectation = if let Some((exp_inner, exp_rawness, exp_mutability)) = |
355 | if let Some((exp_inner, exp_mutability)) = &expected.ty.as_reference() { | 355 | &expected.ty.as_reference_or_ptr() |
356 | if *exp_mutability == Mutability::Mut && *mutability == Mutability::Shared { | 356 | { |
357 | // FIXME: throw type error - expected mut reference but found shared ref, | 357 | if *exp_mutability == Mutability::Mut && *mutability == Mutability::Shared { |
358 | // which cannot be coerced | 358 | // FIXME: throw type error - expected mut reference but found shared ref, |
359 | } | 359 | // which cannot be coerced |
360 | Expectation::rvalue_hint(Ty::clone(exp_inner)) | 360 | } |
361 | } else { | 361 | if *exp_rawness == Rawness::Ref && *rawness == Rawness::RawPtr { |
362 | Expectation::none() | 362 | // FIXME: throw type error - expected reference but found ptr, |
363 | }; | 363 | // which cannot be coerced |
364 | } | ||
365 | Expectation::rvalue_hint(Ty::clone(exp_inner)) | ||
366 | } else { | ||
367 | Expectation::none() | ||
368 | }; | ||
364 | let inner_ty = self.infer_expr_inner(*expr, &expectation); | 369 | let inner_ty = self.infer_expr_inner(*expr, &expectation); |
365 | Ty::apply_one(TypeCtor::Ref(*mutability), inner_ty) | 370 | let ty = match rawness { |
371 | Rawness::RawPtr => TypeCtor::RawPtr(*mutability), | ||
372 | Rawness::Ref => TypeCtor::Ref(*mutability), | ||
373 | }; | ||
374 | Ty::apply_one(ty, inner_ty) | ||
366 | } | 375 | } |
367 | Expr::Box { expr } => { | 376 | Expr::Box { expr } => { |
368 | let inner_ty = self.infer_expr_inner(*expr, &Expectation::none()); | 377 | let inner_ty = self.infer_expr_inner(*expr, &Expectation::none()); |