@@ -33,7 +33,7 @@ use infer::{InferCtxt, InferOk, TypeFreshener};
33
33
use middle:: lang_items;
34
34
use mir:: interpret:: GlobalId ;
35
35
use ty:: fast_reject;
36
- use ty:: relate:: { TypeRelation , TraitObjectMode } ;
36
+ use ty:: relate:: TypeRelation ;
37
37
use ty:: subst:: { Subst , Substs } ;
38
38
use ty:: { self , ToPolyTraitRef , ToPredicate , Ty , TyCtxt , TypeFoldable } ;
39
39
@@ -1416,13 +1416,6 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
1416
1416
return false ;
1417
1417
}
1418
1418
1419
- // Same idea as the above, but for alt trait object modes. These
1420
- // should only be used in intercrate mode - better safe than sorry.
1421
- if self . infcx . trait_object_mode ( ) != TraitObjectMode :: NoSquash {
1422
- bug ! ( "using squashing TraitObjectMode outside of intercrate mode? param_env={:?}" ,
1423
- param_env) ;
1424
- }
1425
-
1426
1419
// Otherwise, we can use the global cache.
1427
1420
true
1428
1421
}
@@ -2016,7 +2009,12 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
2016
2009
return ;
2017
2010
}
2018
2011
2019
- data. principal ( ) . with_self_ty ( self . tcx ( ) , self_ty)
2012
+ if let Some ( principal) = data. principal ( ) {
2013
+ principal. with_self_ty ( self . tcx ( ) , self_ty)
2014
+ } else {
2015
+ // Only auto-trait bounds exist.
2016
+ return ;
2017
+ }
2020
2018
}
2021
2019
ty:: Infer ( ty:: TyVar ( _) ) => {
2022
2020
debug ! ( "assemble_candidates_from_object_ty: ambiguous" ) ;
@@ -2108,7 +2106,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
2108
2106
//
2109
2107
// We always upcast when we can because of reason
2110
2108
// #2 (region bounds).
2111
- data_a. principal ( ) . def_id ( ) == data_b. principal ( ) . def_id ( )
2109
+ data_a. principal_def_id ( ) == data_b. principal_def_id ( )
2112
2110
&& data_b. auto_traits ( )
2113
2111
// All of a's auto traits need to be in b's auto traits.
2114
2112
. all ( |b| data_a. auto_traits ( ) . any ( |a| a == b) )
@@ -2262,7 +2260,8 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
2262
2260
ImplCandidate ( victim_def) => {
2263
2261
let tcx = self . tcx ( ) . global_tcx ( ) ;
2264
2262
return tcx. specializes ( ( other_def, victim_def) )
2265
- || tcx. impls_are_allowed_to_overlap ( other_def, victim_def) ;
2263
+ || tcx. impls_are_allowed_to_overlap (
2264
+ other_def, victim_def) . is_some ( ) ;
2266
2265
}
2267
2266
ParamCandidate ( ref cand) => {
2268
2267
// Prefer the impl to a global where clause candidate.
@@ -2919,7 +2918,10 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
2919
2918
let self_ty = self . infcx
2920
2919
. shallow_resolve ( * obligation. self_ty ( ) . skip_binder ( ) ) ;
2921
2920
let poly_trait_ref = match self_ty. sty {
2922
- ty:: Dynamic ( ref data, ..) => data. principal ( ) . with_self_ty ( self . tcx ( ) , self_ty) ,
2921
+ ty:: Dynamic ( ref data, ..) =>
2922
+ data. principal ( ) . unwrap_or_else ( || {
2923
+ span_bug ! ( obligation. cause. span, "object candidate with no principal" )
2924
+ } ) . with_self_ty ( self . tcx ( ) , self_ty) ,
2923
2925
_ => span_bug ! ( obligation. cause. span, "object candidate with non-object" ) ,
2924
2926
} ;
2925
2927
@@ -3222,8 +3224,9 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
3222
3224
( & ty:: Dynamic ( ref data_a, r_a) , & ty:: Dynamic ( ref data_b, r_b) ) => {
3223
3225
// See assemble_candidates_for_unsizing for more info.
3224
3226
let existential_predicates = data_a. map_bound ( |data_a| {
3225
- let iter = iter:: once ( ty:: ExistentialPredicate :: Trait ( data_a. principal ( ) ) )
3226
- . chain (
3227
+ let iter =
3228
+ data_a. principal ( ) . map ( |x| ty:: ExistentialPredicate :: Trait ( x) )
3229
+ . into_iter ( ) . chain (
3227
3230
data_a
3228
3231
. projection_bounds ( )
3229
3232
. map ( |x| ty:: ExistentialPredicate :: Projection ( x) ) ,
@@ -3260,7 +3263,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
3260
3263
// T -> Trait.
3261
3264
( _, & ty:: Dynamic ( ref data, r) ) => {
3262
3265
let mut object_dids = data. auto_traits ( )
3263
- . chain ( iter :: once ( data. principal ( ) . def_id ( ) ) ) ;
3266
+ . chain ( data. principal_def_id ( ) ) ;
3264
3267
if let Some ( did) = object_dids. find ( |did| !tcx. is_object_safe ( * did) ) {
3265
3268
return Err ( TraitNotObjectSafe ( did) ) ;
3266
3269
}
@@ -3571,8 +3574,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
3571
3574
previous : & ty:: PolyTraitRef < ' tcx > ,
3572
3575
current : & ty:: PolyTraitRef < ' tcx > ,
3573
3576
) -> bool {
3574
- let mut matcher = ty:: _match:: Match :: new (
3575
- self . tcx ( ) , self . infcx . trait_object_mode ( ) ) ;
3577
+ let mut matcher = ty:: _match:: Match :: new ( self . tcx ( ) ) ;
3576
3578
matcher. relate ( previous, current) . is_ok ( )
3577
3579
}
3578
3580
0 commit comments