@@ -84,10 +84,14 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
84
84
let Coerce ( ref v) = * self ; v
85
85
}
86
86
87
+ fn tcx ( & self ) -> & ty:: ctxt < ' tcx > {
88
+ self . get_ref ( ) . infcx . tcx
89
+ }
90
+
87
91
pub fn tys ( & self , a : Ty < ' tcx > , b : Ty < ' tcx > ) -> CoerceResult < ' tcx > {
88
92
debug ! ( "Coerce.tys({} => {})" ,
89
- a. repr( self . get_ref ( ) . infcx . tcx ) ,
90
- b. repr( self . get_ref ( ) . infcx . tcx ) ) ;
93
+ a. repr( self . tcx ( ) ) ,
94
+ b. repr( self . tcx ( ) ) ) ;
91
95
92
96
// Consider coercing the subtype to a DST
93
97
let unsize = self . unpack_actual_value ( a, |a| {
@@ -170,13 +174,11 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
170
174
171
175
self . unpack_actual_value ( a, |a| {
172
176
match a. sty {
173
- ty:: ty_bare_fn( ref a_f) => {
174
- // Bare functions are coercible to any closure type.
175
- //
176
- // FIXME(#3320) this should go away and be
177
- // replaced with proper inference, got a patch
178
- // underway - ndm
179
- self . coerce_from_bare_fn ( a, a_f, b)
177
+ ty:: ty_bare_fn( Some ( a_def_id) , ref a_f) => {
178
+ // Function items are coercible to any closure
179
+ // type; function pointers are not (that would
180
+ // require double indirection).
181
+ self . coerce_from_fn_item ( a, a_def_id, a_f, b)
180
182
}
181
183
_ => {
182
184
// Otherwise, just use subtyping rules.
@@ -206,8 +208,8 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
206
208
mutbl_b : ast:: Mutability )
207
209
-> CoerceResult < ' tcx > {
208
210
debug ! ( "coerce_borrowed_pointer(a={}, b={})" ,
209
- a. repr( self . get_ref ( ) . infcx . tcx ) ,
210
- b. repr( self . get_ref ( ) . infcx . tcx ) ) ;
211
+ a. repr( self . tcx ( ) ) ,
212
+ b. repr( self . tcx ( ) ) ) ;
211
213
212
214
// If we have a parameter of type `&M T_a` and the value
213
215
// provided is `expr`, we will be adding an implicit borrow,
@@ -227,7 +229,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
227
229
}
228
230
} ;
229
231
230
- let a_borrowed = ty:: mk_rptr ( self . get_ref ( ) . infcx . tcx ,
232
+ let a_borrowed = ty:: mk_rptr ( self . tcx ( ) ,
231
233
r_borrow,
232
234
mt { ty : inner_ty, mutbl : mutbl_b} ) ;
233
235
try!( sub. tys ( a_borrowed, b) ) ;
@@ -247,8 +249,8 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
247
249
b : Ty < ' tcx > )
248
250
-> CoerceResult < ' tcx > {
249
251
debug ! ( "coerce_unsized(a={}, b={})" ,
250
- a. repr( self . get_ref ( ) . infcx . tcx ) ,
251
- b. repr( self . get_ref ( ) . infcx . tcx ) ) ;
252
+ a. repr( self . tcx ( ) ) ,
253
+ b. repr( self . tcx ( ) ) ) ;
252
254
253
255
// Note, we want to avoid unnecessary unsizing. We don't want to coerce to
254
256
// a DST unless we have to. This currently comes out in the wash since
@@ -268,7 +270,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
268
270
269
271
let coercion = Coercion ( self . get_ref ( ) . trace . clone ( ) ) ;
270
272
let r_borrow = self . get_ref ( ) . infcx . next_region_var ( coercion) ;
271
- let ty = ty:: mk_rptr ( self . get_ref ( ) . infcx . tcx ,
273
+ let ty = ty:: mk_rptr ( self . tcx ( ) ,
272
274
r_borrow,
273
275
ty:: mt { ty : ty, mutbl : mt_b. mutbl } ) ;
274
276
try!( self . get_ref ( ) . infcx . try ( |_| sub. tys ( ty, b) ) ) ;
@@ -292,7 +294,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
292
294
return Err ( ty:: terr_mutability) ;
293
295
}
294
296
295
- let ty = ty:: mk_ptr ( self . get_ref ( ) . infcx . tcx ,
297
+ let ty = ty:: mk_ptr ( self . tcx ( ) ,
296
298
ty:: mt { ty : ty, mutbl : mt_b. mutbl } ) ;
297
299
try!( self . get_ref ( ) . infcx . try ( |_| sub. tys ( ty, b) ) ) ;
298
300
debug ! ( "Success, coerced with AutoDerefRef(1, \
@@ -311,7 +313,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
311
313
self . unpack_actual_value ( t_a, |a| {
312
314
match self . unsize_ty ( t_a, a, t_b) {
313
315
Some ( ( ty, kind) ) => {
314
- let ty = ty:: mk_uniq ( self . get_ref ( ) . infcx . tcx , ty) ;
316
+ let ty = ty:: mk_uniq ( self . tcx ( ) , ty) ;
315
317
try!( self . get_ref ( ) . infcx . try ( |_| sub. tys ( ty, b) ) ) ;
316
318
debug ! ( "Success, coerced with AutoDerefRef(1, \
317
319
AutoUnsizeUniq({}))", kind) ;
@@ -336,9 +338,9 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
336
338
a : Ty < ' tcx > ,
337
339
ty_b : Ty < ' tcx > )
338
340
-> Option < ( Ty < ' tcx > , ty:: UnsizeKind < ' tcx > ) > {
339
- debug ! ( "unsize_ty(a={}, ty_b={})" , a, ty_b. repr( self . get_ref ( ) . infcx . tcx ) ) ;
341
+ debug ! ( "unsize_ty(a={}, ty_b={})" , a, ty_b. repr( self . tcx ( ) ) ) ;
340
342
341
- let tcx = self . get_ref ( ) . infcx . tcx ;
343
+ let tcx = self . tcx ( ) ;
342
344
343
345
self . unpack_actual_value ( ty_b, |b|
344
346
match ( & a. sty , & b. sty ) {
@@ -412,7 +414,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
412
414
b : Ty < ' tcx > ,
413
415
b_mutbl : ast:: Mutability ) -> CoerceResult < ' tcx >
414
416
{
415
- let tcx = self . get_ref ( ) . infcx . tcx ;
417
+ let tcx = self . tcx ( ) ;
416
418
417
419
debug ! ( "coerce_borrowed_object(a={}, b={}, b_mutbl={})" ,
418
420
a. repr( tcx) ,
@@ -431,7 +433,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
431
433
b : Ty < ' tcx > ,
432
434
b_mutbl : ast:: Mutability ) -> CoerceResult < ' tcx >
433
435
{
434
- let tcx = self . get_ref ( ) . infcx . tcx ;
436
+ let tcx = self . tcx ( ) ;
435
437
436
438
debug ! ( "coerce_unsafe_object(a={}, b={}, b_mutbl={})" ,
437
439
a. repr( tcx) ,
@@ -451,7 +453,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
451
453
F : FnOnce ( Ty < ' tcx > ) -> Ty < ' tcx > ,
452
454
G : FnOnce ( ) -> ty:: AutoRef < ' tcx > ,
453
455
{
454
- let tcx = self . get_ref ( ) . infcx . tcx ;
456
+ let tcx = self . tcx ( ) ;
455
457
456
458
match a. sty {
457
459
ty:: ty_rptr( _, ty:: mt { ty, mutbl} ) => match ty. sty {
@@ -480,8 +482,8 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
480
482
b : Ty < ' tcx > )
481
483
-> CoerceResult < ' tcx > {
482
484
debug ! ( "coerce_borrowed_fn(a={}, b={})" ,
483
- a. repr( self . get_ref ( ) . infcx . tcx ) ,
484
- b. repr( self . get_ref ( ) . infcx . tcx ) ) ;
485
+ a. repr( self . tcx ( ) ) ,
486
+ b. repr( self . tcx ( ) ) ) ;
485
487
486
488
match a. sty {
487
489
ty:: ty_bare_fn( ref f) => {
@@ -528,8 +530,8 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
528
530
mutbl_b : ast:: Mutability )
529
531
-> CoerceResult < ' tcx > {
530
532
debug ! ( "coerce_unsafe_ptr(a={}, b={})" ,
531
- a. repr( self . get_ref ( ) . infcx . tcx ) ,
532
- b. repr( self . get_ref ( ) . infcx . tcx ) ) ;
533
+ a. repr( self . tcx ( ) ) ,
534
+ b. repr( self . tcx ( ) ) ) ;
533
535
534
536
let mt_a = match a. sty {
535
537
ty:: ty_rptr( _, mt) | ty:: ty_ptr( mt) => mt,
@@ -539,7 +541,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
539
541
} ;
540
542
541
543
// Check that the types which they point at are compatible.
542
- let a_unsafe = ty:: mk_ptr ( self . get_ref ( ) . infcx . tcx , ty:: mt { mutbl : mutbl_b, ty : mt_a. ty } ) ;
544
+ let a_unsafe = ty:: mk_ptr ( self . tcx ( ) , ty:: mt { mutbl : mutbl_b, ty : mt_a. ty } ) ;
543
545
try!( self . subtype ( a_unsafe, b) ) ;
544
546
if !can_coerce_mutbls ( mt_a. mutbl , mutbl_b) {
545
547
return Err ( ty:: terr_mutability) ;
0 commit comments