@@ -350,8 +350,7 @@ impl<'f> Coerce<'f> {
350350 }
351351 } )
352352 }
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) ) => {
355354 self . unpack_actual_value ( t_a, |sty_a| {
356355 match self . unsize_ty ( sty_a, mt_b. ty ) {
357356 Some ( ( ty, kind) ) => {
@@ -478,63 +477,52 @@ impl<'f> Coerce<'f> {
478477 b. repr( tcx) ) ;
479478
480479 let coercion = Coercion ( self . get_ref ( ) . trace . clone ( ) ) ;
480+ let r_a = self . get_ref ( ) . infcx . next_region_var ( coercion) ;
481481
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 ) )
508485 }
509486
510487 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
515492 {
516493 let tcx = self . get_ref ( ) . infcx . tcx ;
517494
518495 debug ! ( "coerce_unsafe_object(a={}, sty_a={:?}, b={})" ,
519496 a. repr( tcx) , sty_a,
520497 b. repr( tcx) ) ;
521498
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+
522513 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 {
525515 ty:: ty_trait( box ty:: TyTrait {
526516 def_id,
527517 ref substs,
528518 bounds,
529519 ..
530520 } ) => {
531521 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) ) ;
535523 Ok ( Some ( AutoDerefRef ( AutoDerefRef {
536524 autoderefs : 1 ,
537- autoref : Some ( AutoUnsafe ( b_mutbl , None ) )
525+ autoref : Some ( mk_adjust ( ) )
538526 } ) ) )
539527 }
540528 _ => {
0 commit comments