@@ -46,6 +46,7 @@ use rustc_infer::infer::relate::RelateResult;
4646use rustc_infer:: infer:: { Coercion , DefineOpaqueTypes , InferOk , InferResult } ;
4747use rustc_infer:: traits:: {
4848 IfExpressionCause , MatchExpressionArmCause , Obligation , PredicateObligation ,
49+ PredicateObligations ,
4950} ;
5051use rustc_middle:: lint:: in_external_macro;
5152use rustc_middle:: span_bug;
@@ -120,7 +121,7 @@ fn simple<'tcx>(kind: Adjust<'tcx>) -> impl FnOnce(Ty<'tcx>) -> Vec<Adjustment<'
120121fn success < ' tcx > (
121122 adj : Vec < Adjustment < ' tcx > > ,
122123 target : Ty < ' tcx > ,
123- obligations : Vec < traits :: PredicateObligation < ' tcx > > ,
124+ obligations : PredicateObligations < ' tcx > ,
124125) -> CoerceResult < ' tcx > {
125126 Ok ( InferOk { value : ( adj, target) , obligations } )
126127}
@@ -184,7 +185,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
184185 // Coercing from `!` to any type is allowed:
185186 if a. is_never ( ) {
186187 if self . coerce_never {
187- return success ( simple ( Adjust :: NeverToAny ) ( b) , b, vec ! [ ] ) ;
188+ return success ( simple ( Adjust :: NeverToAny ) ( b) , b, PredicateObligations :: new ( ) ) ;
188189 } else {
189190 // Otherwise the only coercion we can do is unification.
190191 return self . unify_and ( a, b, identity) ;
@@ -278,7 +279,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
278279 // Two unresolved type variables: create a `Coerce` predicate.
279280 let target_ty = if self . use_lub { self . next_ty_var ( self . cause . span ) } else { b } ;
280281
281- let mut obligations = Vec :: with_capacity ( 2 ) ;
282+ let mut obligations = PredicateObligations :: with_capacity ( 2 ) ;
282283 for & source_ty in & [ a, b] {
283284 if source_ty != target_ty {
284285 obligations. push ( Obligation :: new (
@@ -744,7 +745,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
744745
745746 // Check the obligations of the cast -- for example, when casting
746747 // `usize` to `dyn* Clone + 'static`:
747- let mut obligations: Vec < _ > = predicates
748+ let obligations = predicates
748749 . iter ( )
749750 . map ( |predicate| {
750751 // For each existential predicate (e.g., `?Self: Clone`) instantiate
@@ -764,21 +765,21 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
764765 ty:: OutlivesPredicate ( a, b_region) ,
765766 ) ) ) ,
766767 ) ,
768+ // Enforce that the type is `usize`/pointer-sized.
769+ Obligation :: new (
770+ self . tcx ,
771+ self . cause . clone ( ) ,
772+ self . param_env ,
773+ ty:: TraitRef :: new (
774+ self . tcx ,
775+ self . tcx
776+ . require_lang_item ( hir:: LangItem :: PointerLike , Some ( self . cause . span ) ) ,
777+ [ a] ,
778+ ) ,
779+ ) ,
767780 ] )
768781 . collect ( ) ;
769782
770- // Enforce that the type is `usize`/pointer-sized.
771- obligations. push ( Obligation :: new (
772- self . tcx ,
773- self . cause . clone ( ) ,
774- self . param_env ,
775- ty:: TraitRef :: new (
776- self . tcx ,
777- self . tcx . require_lang_item ( hir:: LangItem :: PointerLike , Some ( self . cause . span ) ) ,
778- [ a] ,
779- ) ,
780- ) ) ;
781-
782783 Ok ( InferOk {
783784 value : (
784785 vec ! [ Adjustment { kind: Adjust :: Pointer ( PointerCoercion :: DynStar ) , target: b } ] ,
0 commit comments