@@ -350,8 +350,7 @@ impl<'f> Coerce<'f> {
350
350
}
351
351
} )
352
352
}
353
- ( & ty:: ty_ptr( ty:: mt { ty : t_a, ..} ) , & ty:: ty_ptr( mt_b) )
354
- | ( & ty:: ty_rptr( _, ty:: mt { ty : t_a, ..} ) , & ty:: ty_ptr( mt_b) ) => {
353
+ ( & ty:: ty_rptr( _, ty:: mt { ty : t_a, ..} ) , & ty:: ty_ptr( mt_b) ) => {
355
354
self . unpack_actual_value ( t_a, |sty_a| {
356
355
match self . unsize_ty ( sty_a, mt_b. ty ) {
357
356
Some ( ( ty, kind) ) => {
@@ -478,63 +477,52 @@ impl<'f> Coerce<'f> {
478
477
b. repr( tcx) ) ;
479
478
480
479
let coercion = Coercion ( self . get_ref ( ) . trace . clone ( ) ) ;
480
+ let r_a = self . get_ref ( ) . infcx . next_region_var ( coercion) ;
481
481
482
- match * sty_a {
483
- ty:: ty_uniq( ty) | ty:: ty_rptr( _, ty:: mt { ty, ..} ) => match ty:: get ( ty) . sty {
484
- ty:: ty_trait( box ty:: TyTrait {
485
- def_id,
486
- ref substs,
487
- bounds,
488
- ..
489
- } ) => {
490
- let tr = ty:: mk_trait ( tcx, def_id, substs. clone ( ) , bounds) ;
491
- let r_a = self . get_ref ( ) . infcx . next_region_var ( coercion) ;
492
- let a_borrowed = ty:: mk_rptr ( tcx, r_a, ty:: mt { mutbl : b_mutbl, ty : tr } ) ;
493
-
494
- try!( self . subtype ( a_borrowed, b) ) ;
495
- Ok ( Some ( AutoDerefRef ( AutoDerefRef {
496
- autoderefs : 1 ,
497
- autoref : Some ( AutoPtr ( r_a, b_mutbl, None ) )
498
- } ) ) )
499
- }
500
- _ => {
501
- self . subtype ( a, b)
502
- }
503
- } ,
504
- _ => {
505
- self . subtype ( a, b)
506
- }
507
- }
482
+ self . coerce_object ( a, sty_a, b,
483
+ |tr| ty:: mk_rptr ( tcx, r_a, ty:: mt { mutbl : b_mutbl, ty : tr } ) ,
484
+ || AutoPtr ( r_a, b_mutbl, None ) )
508
485
}
509
486
510
487
fn coerce_unsafe_object ( & self ,
511
- a : ty:: t ,
512
- sty_a : & ty:: sty ,
513
- b : ty:: t ,
514
- b_mutbl : ast:: Mutability ) -> CoerceResult
488
+ a : ty:: t ,
489
+ sty_a : & ty:: sty ,
490
+ b : ty:: t ,
491
+ b_mutbl : ast:: Mutability ) -> CoerceResult
515
492
{
516
493
let tcx = self . get_ref ( ) . infcx . tcx ;
517
494
518
495
debug ! ( "coerce_unsafe_object(a={}, sty_a={:?}, b={})" ,
519
496
a. repr( tcx) , sty_a,
520
497
b. repr( tcx) ) ;
521
498
499
+ self . coerce_object ( a, sty_a, b,
500
+ |tr| ty:: mk_ptr ( tcx, ty:: mt { mutbl : b_mutbl, ty : tr } ) ,
501
+ || AutoUnsafe ( b_mutbl, None ) )
502
+ }
503
+
504
+ fn coerce_object ( & self ,
505
+ a : ty:: t ,
506
+ sty_a : & ty:: sty ,
507
+ b : ty:: t ,
508
+ mk_ty: |ty:: t| -> ty:: t,
509
+ mk_adjust: || -> ty:: AutoRef ) -> CoerceResult
510
+ {
511
+ let tcx = self . get_ref ( ) . infcx . tcx ;
512
+
522
513
match * sty_a {
523
- ty:: ty_uniq( ty) | ty:: ty_rptr( _, ty:: mt { ty, ..} ) |
524
- ty:: ty_ptr( ty:: mt { ty, ..} ) => match ty:: get ( ty) . sty {
514
+ ty:: ty_uniq( ty) | ty:: ty_rptr( _, ty:: mt { ty, ..} ) => match ty:: get ( ty) . sty {
525
515
ty:: ty_trait( box ty:: TyTrait {
526
516
def_id,
527
517
ref substs,
528
518
bounds,
529
519
..
530
520
} ) => {
531
521
let tr = ty:: mk_trait ( tcx, def_id, substs. clone ( ) , bounds) ;
532
- let a_raw = ty:: mk_ptr ( tcx, ty:: mt { mutbl : b_mutbl, ty : tr } ) ;
533
-
534
- try!( self . subtype ( a_raw, b) ) ;
522
+ try!( self . subtype ( mk_ty ( tr) , b) ) ;
535
523
Ok ( Some ( AutoDerefRef ( AutoDerefRef {
536
524
autoderefs : 1 ,
537
- autoref : Some ( AutoUnsafe ( b_mutbl , None ) )
525
+ autoref : Some ( mk_adjust ( ) )
538
526
} ) ) )
539
527
}
540
528
_ => {
0 commit comments