@@ -17,8 +17,8 @@ use crate::{
1717 autoderef, method_resolution, op,
1818 traits:: InEnvironment ,
1919 utils:: { generics, variant_data, Generics } ,
20- ApplicationTy , Binders , CallableDef , InferTy , IntTy , Mutability , Obligation , Substs , TraitRef ,
21- Ty , TypeCtor , Uncertain ,
20+ ApplicationTy , Binders , CallableDef , InferTy , IntTy , Mutability , Obligation , Rawness , Substs ,
21+ TraitRef , Ty , TypeCtor , Uncertain ,
2222} ;
2323
2424use super :: {
@@ -350,19 +350,28 @@ impl<'a> InferenceContext<'a> {
350350 // FIXME check the cast...
351351 cast_ty
352352 }
353- Expr :: Ref { expr, mutability } => {
354- let expectation =
355- if let Some ( ( exp_inner, exp_mutability) ) = & expected. ty . as_reference ( ) {
356- if * exp_mutability == Mutability :: Mut && * mutability == Mutability :: Shared {
357- // FIXME: throw type error - expected mut reference but found shared ref,
358- // which cannot be coerced
359- }
360- Expectation :: rvalue_hint ( Ty :: clone ( exp_inner) )
361- } else {
362- Expectation :: none ( )
363- } ;
353+ Expr :: Ref { expr, rawness, mutability } => {
354+ let expectation = if let Some ( ( exp_inner, exp_rawness, exp_mutability) ) =
355+ & expected. ty . as_reference_or_ptr ( )
356+ {
357+ if * exp_mutability == Mutability :: Mut && * mutability == Mutability :: Shared {
358+ // FIXME: throw type error - expected mut reference but found shared ref,
359+ // which cannot be coerced
360+ }
361+ if * exp_rawness == Rawness :: Ref && * rawness == Rawness :: RawPtr {
362+ // FIXME: throw type error - expected reference but found ptr,
363+ // which cannot be coerced
364+ }
365+ Expectation :: rvalue_hint ( Ty :: clone ( exp_inner) )
366+ } else {
367+ Expectation :: none ( )
368+ } ;
364369 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)
366375 }
367376 Expr :: Box { expr } => {
368377 let inner_ty = self . infer_expr_inner ( * expr, & Expectation :: none ( ) ) ;
0 commit comments