aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/infer/expr.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_ty/src/infer/expr.rs')
-rw-r--r--crates/hir_ty/src/infer/expr.rs21
1 files changed, 12 insertions, 9 deletions
diff --git a/crates/hir_ty/src/infer/expr.rs b/crates/hir_ty/src/infer/expr.rs
index 7852b3d23..cf1f1038a 100644
--- a/crates/hir_ty/src/infer/expr.rs
+++ b/crates/hir_ty/src/infer/expr.rs
@@ -3,7 +3,7 @@
3use std::iter::{repeat, repeat_with}; 3use std::iter::{repeat, repeat_with};
4use std::{mem, sync::Arc}; 4use std::{mem, sync::Arc};
5 5
6use chalk_ir::TyVariableKind; 6use chalk_ir::{Mutability, TyVariableKind};
7use hir_def::{ 7use hir_def::{
8 expr::{Array, BinaryOp, Expr, ExprId, Literal, Statement, UnaryOp}, 8 expr::{Array, BinaryOp, Expr, ExprId, Literal, Statement, UnaryOp},
9 path::{GenericArg, GenericArgs}, 9 path::{GenericArg, GenericArgs},
@@ -15,12 +15,14 @@ use syntax::ast::RangeOp;
15use test_utils::mark; 15use test_utils::mark;
16 16
17use crate::{ 17use crate::{
18 autoderef, method_resolution, op, 18 autoderef,
19 lower::lower_to_chalk_mutability,
20 method_resolution, op,
19 primitive::{self, UintTy}, 21 primitive::{self, UintTy},
20 traits::{FnTrait, InEnvironment}, 22 traits::{FnTrait, InEnvironment},
21 utils::{generics, variant_data, Generics}, 23 utils::{generics, variant_data, Generics},
22 Binders, CallableDefId, FnPointer, FnSig, Mutability, Obligation, OpaqueTyId, Rawness, Scalar, 24 Binders, CallableDefId, FnPointer, FnSig, Obligation, OpaqueTyId, Rawness, Scalar, Substs,
23 Substs, TraitRef, Ty, 25 TraitRef, Ty,
24}; 26};
25 27
26use super::{ 28use super::{
@@ -462,10 +464,11 @@ impl<'a> InferenceContext<'a> {
462 cast_ty 464 cast_ty
463 } 465 }
464 Expr::Ref { expr, rawness, mutability } => { 466 Expr::Ref { expr, rawness, mutability } => {
467 let mutability = lower_to_chalk_mutability(*mutability);
465 let expectation = if let Some((exp_inner, exp_rawness, exp_mutability)) = 468 let expectation = if let Some((exp_inner, exp_rawness, exp_mutability)) =
466 &expected.ty.as_reference_or_ptr() 469 &expected.ty.as_reference_or_ptr()
467 { 470 {
468 if *exp_mutability == Mutability::Mut && *mutability == Mutability::Shared { 471 if *exp_mutability == Mutability::Mut && mutability == Mutability::Not {
469 // FIXME: throw type error - expected mut reference but found shared ref, 472 // FIXME: throw type error - expected mut reference but found shared ref,
470 // which cannot be coerced 473 // which cannot be coerced
471 } 474 }
@@ -479,8 +482,8 @@ impl<'a> InferenceContext<'a> {
479 }; 482 };
480 let inner_ty = self.infer_expr_inner(*expr, &expectation); 483 let inner_ty = self.infer_expr_inner(*expr, &expectation);
481 match rawness { 484 match rawness {
482 Rawness::RawPtr => Ty::Raw(*mutability, Substs::single(inner_ty)), 485 Rawness::RawPtr => Ty::Raw(mutability, Substs::single(inner_ty)),
483 Rawness::Ref => Ty::Ref(*mutability, Substs::single(inner_ty)), 486 Rawness::Ref => Ty::Ref(mutability, Substs::single(inner_ty)),
484 } 487 }
485 } 488 }
486 Expr::Box { expr } => { 489 Expr::Box { expr } => {
@@ -684,11 +687,11 @@ impl<'a> InferenceContext<'a> {
684 } 687 }
685 Expr::Literal(lit) => match lit { 688 Expr::Literal(lit) => match lit {
686 Literal::Bool(..) => Ty::Scalar(Scalar::Bool), 689 Literal::Bool(..) => Ty::Scalar(Scalar::Bool),
687 Literal::String(..) => Ty::Ref(Mutability::Shared, Substs::single(Ty::Str)), 690 Literal::String(..) => Ty::Ref(Mutability::Not, Substs::single(Ty::Str)),
688 Literal::ByteString(..) => { 691 Literal::ByteString(..) => {
689 let byte_type = Ty::Scalar(Scalar::Uint(UintTy::U8)); 692 let byte_type = Ty::Scalar(Scalar::Uint(UintTy::U8));
690 let array_type = Ty::Array(Substs::single(byte_type)); 693 let array_type = Ty::Array(Substs::single(byte_type));
691 Ty::Ref(Mutability::Shared, Substs::single(array_type)) 694 Ty::Ref(Mutability::Not, Substs::single(array_type))
692 } 695 }
693 Literal::Char(..) => Ty::Scalar(Scalar::Char), 696 Literal::Char(..) => Ty::Scalar(Scalar::Char),
694 Literal::Int(_v, ty) => match ty { 697 Literal::Int(_v, ty) => match ty {