@@ -1528,7 +1528,10 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
15281528 _ => { }
15291529 }
15301530
1531- data. principal . with_self_ty ( this. tcx ( ) , self_ty)
1531+ match data. principal ( ) {
1532+ Some ( ref p) => p. with_self_ty ( this. tcx ( ) , self_ty) ,
1533+ None => return ,
1534+ }
15321535 }
15331536 ty:: TyInfer ( ty:: TyVar ( _) ) => {
15341537 debug ! ( "assemble_candidates_from_object_ty: ambiguous" ) ;
@@ -1611,8 +1614,11 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
16111614 //
16121615 // We always upcast when we can because of reason
16131616 // #2 (region bounds).
1614- data_a. principal . def_id ( ) == data_b. principal . def_id ( ) &&
1615- data_a. builtin_bounds . is_superset ( & data_b. builtin_bounds )
1617+ match ( data_a. principal ( ) , data_b. principal ( ) ) {
1618+ ( Some ( ref a) , Some ( ref b) ) => a. def_id ( ) == b. def_id ( ) &&
1619+ data_a. builtin_bounds . is_superset ( & data_b. builtin_bounds ) ,
1620+ _ => false
1621+ }
16161622 }
16171623
16181624 // T -> Trait.
@@ -2167,7 +2173,8 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
21672173 match self_ty. sty {
21682174 ty:: TyTrait ( ref data) => {
21692175 // OK to skip the binder, it is reintroduced below
2170- let input_types = data. principal . input_types ( ) ;
2176+ let principal = data. principal ( ) . unwrap ( ) ;
2177+ let input_types = principal. input_types ( ) ;
21712178 let assoc_types = data. projection_bounds . iter ( )
21722179 . map ( |pb| pb. skip_binder ( ) . ty ) ;
21732180 let all_types: Vec < _ > = input_types. chain ( assoc_types)
@@ -2301,7 +2308,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
23012308 let self_ty = self . infcx . shallow_resolve ( * obligation. self_ty ( ) . skip_binder ( ) ) ;
23022309 let poly_trait_ref = match self_ty. sty {
23032310 ty:: TyTrait ( ref data) => {
2304- data. principal . with_self_ty ( self . tcx ( ) , self_ty)
2311+ data. principal ( ) . unwrap ( ) . with_self_ty ( self . tcx ( ) , self_ty)
23052312 }
23062313 _ => {
23072314 span_bug ! ( obligation. cause. span,
@@ -2471,12 +2478,13 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
24712478 // Trait+Kx+'a -> Trait+Ky+'b (upcasts).
24722479 ( & ty:: TyTrait ( ref data_a) , & ty:: TyTrait ( ref data_b) ) => {
24732480 // See assemble_candidates_for_unsizing for more info.
2474- let new_trait = tcx. mk_trait ( ty:: TraitObject {
2475- principal : data_a. principal ,
2476- region_bound : data_b. region_bound ,
2477- builtin_bounds : data_b. builtin_bounds ,
2478- projection_bounds : data_a. projection_bounds . clone ( ) ,
2479- } ) ;
2481+ let new_trait = tcx. mk_trait ( ty:: TraitObject :: new (
2482+ data_a. principal ( ) ,
2483+ data_b. region_bound ,
2484+ data_b. builtin_bounds ,
2485+ data_a. projection_bounds . clone ( ) ,
2486+ ) ) ;
2487+ let origin = TypeOrigin :: Misc ( obligation. cause . span ) ;
24802488 let InferOk { obligations, .. } =
24812489 self . infcx . sub_types ( false , & obligation. cause , new_trait, target)
24822490 . map_err ( |_| Unimplemented ) ?;
@@ -2499,7 +2507,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
24992507 data. builtin_bounds . iter ( ) . flat_map ( |bound| {
25002508 tcx. lang_items . from_builtin_kind ( bound) . ok ( )
25012509 } )
2502- . chain ( Some ( data. principal . def_id ( ) ) ) ;
2510+ . chain ( data. principal ( ) . map ( | ref p| p . def_id ( ) ) ) ;
25032511 if let Some ( did) = object_dids. find ( |did| {
25042512 !tcx. is_object_safe ( * did)
25052513 } ) {
@@ -2516,7 +2524,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
25162524 } ;
25172525
25182526 // Create the obligation for casting from T to Trait.
2519- push ( data. principal . with_self_ty ( tcx, source) . to_predicate ( ) ) ;
2527+ push ( data. principal ( ) . unwrap ( ) . with_self_ty ( tcx, source) . to_predicate ( ) ) ;
25202528
25212529 // We can only make objects from sized types.
25222530 let mut builtin_bounds = data. builtin_bounds ;
0 commit comments