@@ -18,9 +18,13 @@ pub enum Expectation<'tcx> {
18
18
/// This expression will be cast to the `Ty`.
19
19
ExpectCastableToType ( Ty < ' tcx > ) ,
20
20
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 > ) ,
24
28
25
29
IsLast ( Span ) ,
26
30
}
@@ -48,7 +52,7 @@ impl<'a, 'tcx> Expectation<'tcx> {
48
52
let ety = fcx. shallow_resolve ( ety) ;
49
53
if !ety. is_ty_var ( ) { ExpectHasType ( ety) } else { NoExpectation }
50
54
}
51
- ExpectRvalueLikeUnsized ( ety) => ExpectRvalueLikeUnsized ( ety) ,
55
+ ExpectRvalueDeref ( ety) => ExpectRvalueDeref ( ety) ,
52
56
_ => NoExpectation ,
53
57
}
54
58
}
@@ -74,7 +78,7 @@ impl<'a, 'tcx> Expectation<'tcx> {
74
78
/// for examples of where this comes up,.
75
79
pub ( super ) fn rvalue_hint ( fcx : & FnCtxt < ' a , ' tcx > , ty : Ty < ' tcx > ) -> Expectation < ' tcx > {
76
80
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) ,
78
82
_ => ExpectHasType ( ty) ,
79
83
}
80
84
}
@@ -87,15 +91,15 @@ impl<'a, 'tcx> Expectation<'tcx> {
87
91
NoExpectation => NoExpectation ,
88
92
ExpectCastableToType ( t) => ExpectCastableToType ( fcx. resolve_vars_if_possible ( t) ) ,
89
93
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) ) ,
91
95
IsLast ( sp) => IsLast ( sp) ,
92
96
}
93
97
}
94
98
95
99
pub ( super ) fn to_option ( self , fcx : & FnCtxt < ' a , ' tcx > ) -> Option < Ty < ' tcx > > {
96
100
match self . resolve ( fcx) {
97
101
NoExpectation | IsLast ( _) => None ,
98
- ExpectCastableToType ( ty) | ExpectHasType ( ty) | ExpectRvalueLikeUnsized ( ty) => Some ( ty) ,
102
+ ExpectCastableToType ( ty) | ExpectHasType ( ty) | ExpectRvalueDeref ( ty) => Some ( ty) ,
99
103
}
100
104
}
101
105
@@ -106,9 +110,7 @@ impl<'a, 'tcx> Expectation<'tcx> {
106
110
pub ( super ) fn only_has_type ( self , fcx : & FnCtxt < ' a , ' tcx > ) -> Option < Ty < ' tcx > > {
107
111
match self {
108
112
ExpectHasType ( ty) => Some ( fcx. resolve_vars_if_possible ( ty) ) ,
109
- NoExpectation | ExpectCastableToType ( _) | ExpectRvalueLikeUnsized ( _) | IsLast ( _) => {
110
- None
111
- }
113
+ NoExpectation | ExpectCastableToType ( _) | ExpectRvalueDeref ( _) | IsLast ( _) => None ,
112
114
}
113
115
}
114
116
0 commit comments