@@ -18,9 +18,13 @@ pub enum Expectation<'tcx> {
1818 /// This expression will be cast to the `Ty`.
1919 ExpectCastableToType ( Ty < ' tcx > ) ,
2020
21- /// This rvalue expression will be wrapped in `&` or `Box` and coerced
22- /// to `&Ty` or `Box<Ty>`, respectively. `Ty` is `[A]` or `Trait`.
23- ExpectRvalueLikeUnsized ( Ty < ' tcx > ) ,
21+ /// This rvalue expression will be deref'd to the type Ty.
22+ ///
23+ /// Given, for example, if you have let x: &Ty = &<foo>, this
24+ /// hint would be given when type-checking <foo>. It is
25+ /// not required that foo has the type Ty, but it must have some
26+ /// type that derefs to Ty for the program to be legal.
27+ ExpectRvalueDeref ( Ty < ' tcx > ) ,
2428
2529 IsLast ( Span ) ,
2630}
@@ -48,7 +52,7 @@ impl<'a, 'tcx> Expectation<'tcx> {
4852 let ety = fcx. shallow_resolve ( ety) ;
4953 if !ety. is_ty_var ( ) { ExpectHasType ( ety) } else { NoExpectation }
5054 }
51- ExpectRvalueLikeUnsized ( ety) => ExpectRvalueLikeUnsized ( ety) ,
55+ ExpectRvalueDeref ( ety) => ExpectRvalueDeref ( ety) ,
5256 _ => NoExpectation ,
5357 }
5458 }
@@ -74,7 +78,7 @@ impl<'a, 'tcx> Expectation<'tcx> {
7478 /// for examples of where this comes up,.
7579 pub ( super ) fn rvalue_hint ( fcx : & FnCtxt < ' a , ' tcx > , ty : Ty < ' tcx > ) -> Expectation < ' tcx > {
7680 match fcx. tcx . struct_tail_without_normalization ( ty) . kind ( ) {
77- ty:: Slice ( _) | ty:: Str | ty:: Dynamic ( ..) => ExpectRvalueLikeUnsized ( ty) ,
81+ ty:: Slice ( _) | ty:: Str | ty:: Dynamic ( ..) => ExpectRvalueDeref ( ty) ,
7882 _ => ExpectHasType ( ty) ,
7983 }
8084 }
@@ -87,15 +91,15 @@ impl<'a, 'tcx> Expectation<'tcx> {
8791 NoExpectation => NoExpectation ,
8892 ExpectCastableToType ( t) => ExpectCastableToType ( fcx. resolve_vars_if_possible ( t) ) ,
8993 ExpectHasType ( t) => ExpectHasType ( fcx. resolve_vars_if_possible ( t) ) ,
90- ExpectRvalueLikeUnsized ( t) => ExpectRvalueLikeUnsized ( fcx. resolve_vars_if_possible ( t) ) ,
94+ ExpectRvalueDeref ( t) => ExpectRvalueDeref ( fcx. resolve_vars_if_possible ( t) ) ,
9195 IsLast ( sp) => IsLast ( sp) ,
9296 }
9397 }
9498
9599 pub ( super ) fn to_option ( self , fcx : & FnCtxt < ' a , ' tcx > ) -> Option < Ty < ' tcx > > {
96100 match self . resolve ( fcx) {
97101 NoExpectation | IsLast ( _) => None ,
98- ExpectCastableToType ( ty) | ExpectHasType ( ty) | ExpectRvalueLikeUnsized ( ty) => Some ( ty) ,
102+ ExpectCastableToType ( ty) | ExpectHasType ( ty) | ExpectRvalueDeref ( ty) => Some ( ty) ,
99103 }
100104 }
101105
@@ -106,9 +110,7 @@ impl<'a, 'tcx> Expectation<'tcx> {
106110 pub ( super ) fn only_has_type ( self , fcx : & FnCtxt < ' a , ' tcx > ) -> Option < Ty < ' tcx > > {
107111 match self {
108112 ExpectHasType ( ty) => Some ( fcx. resolve_vars_if_possible ( ty) ) ,
109- NoExpectation | ExpectCastableToType ( _) | ExpectRvalueLikeUnsized ( _) | IsLast ( _) => {
110- None
111- }
113+ NoExpectation | ExpectCastableToType ( _) | ExpectRvalueDeref ( _) | IsLast ( _) => None ,
112114 }
113115 }
114116
0 commit comments