@@ -68,7 +68,7 @@ use middle::traits::{predicate_for_trait_def, report_selection_error};
68
68
use middle:: ty:: adjustment:: { AutoAdjustment , AutoDerefRef , AdjustDerefRef } ;
69
69
use middle:: ty:: adjustment:: { AutoPtr , AutoUnsafe , AdjustReifyFnPointer } ;
70
70
use middle:: ty:: adjustment:: { AdjustUnsafeFnPointer } ;
71
- use middle:: ty:: { self , LvaluePreference , TypeAndMut , Ty } ;
71
+ use middle:: ty:: { self , HasTypeFlags , LvaluePreference , TypeAndMut , Ty } ;
72
72
use middle:: ty:: error:: TypeError ;
73
73
use middle:: ty:: relate:: RelateResult ;
74
74
use util:: common:: indent;
@@ -110,10 +110,15 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
110
110
a,
111
111
b) ;
112
112
113
+ let a = self . fcx . infcx ( ) . shallow_resolve ( a) ;
114
+
115
+ // Just ignore error types.
116
+ if a. references_error ( ) || b. references_error ( ) {
117
+ return Ok ( None ) ;
118
+ }
119
+
113
120
// Consider coercing the subtype to a DST
114
- let unsize = self . unpack_actual_value ( a, |a| {
115
- self . coerce_unsized ( a, b)
116
- } ) ;
121
+ let unsize = self . coerce_unsized ( a, b) ;
117
122
if unsize. is_ok ( ) {
118
123
return unsize;
119
124
}
@@ -124,39 +129,33 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
124
129
// See above for details.
125
130
match b. sty {
126
131
ty:: TyRawPtr ( mt_b) => {
127
- return self . unpack_actual_value ( a, |a| {
128
- self . coerce_unsafe_ptr ( a, b, mt_b. mutbl )
129
- } ) ;
132
+ return self . coerce_unsafe_ptr ( a, b, mt_b. mutbl ) ;
130
133
}
131
134
132
135
ty:: TyRef ( _, mt_b) => {
133
- return self . unpack_actual_value ( a, |a| {
134
- self . coerce_borrowed_pointer ( expr_a, a, b, mt_b. mutbl )
135
- } ) ;
136
+ return self . coerce_borrowed_pointer ( expr_a, a, b, mt_b. mutbl ) ;
136
137
}
137
138
138
139
_ => { }
139
140
}
140
141
141
- self . unpack_actual_value ( a, |a| {
142
- match a. sty {
143
- ty:: TyBareFn ( Some ( _) , a_f) => {
144
- // Function items are coercible to any closure
145
- // type; function pointers are not (that would
146
- // require double indirection).
147
- self . coerce_from_fn_item ( a, a_f, b)
148
- }
149
- ty:: TyBareFn ( None , a_f) => {
150
- // We permit coercion of fn pointers to drop the
151
- // unsafe qualifier.
152
- self . coerce_from_fn_pointer ( a, a_f, b)
153
- }
154
- _ => {
155
- // Otherwise, just use subtyping rules.
156
- self . subtype ( a, b)
157
- }
142
+ match a. sty {
143
+ ty:: TyBareFn ( Some ( _) , a_f) => {
144
+ // Function items are coercible to any closure
145
+ // type; function pointers are not (that would
146
+ // require double indirection).
147
+ self . coerce_from_fn_item ( a, a_f, b)
158
148
}
159
- } )
149
+ ty:: TyBareFn ( None , a_f) => {
150
+ // We permit coercion of fn pointers to drop the
151
+ // unsafe qualifier.
152
+ self . coerce_from_fn_pointer ( a, a_f, b)
153
+ }
154
+ _ => {
155
+ // Otherwise, just use subtyping rules.
156
+ self . subtype ( a, b)
157
+ }
158
+ }
160
159
}
161
160
162
161
/// Reborrows `&mut A` to `&mut B` and `&(mut) A` to `&B`.
0 commit comments