@@ -987,9 +987,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
987
987
let target = self . infcx . shallow_resolve ( target) ;
988
988
debug ! ( ?source, ?target, "confirm_builtin_unsize_candidate" ) ;
989
989
990
- let mut nested = vec ! [ ] ;
991
- let src;
992
- match ( source. kind ( ) , target. kind ( ) ) {
990
+ Ok ( match ( source. kind ( ) , target. kind ( ) ) {
993
991
// Trait+Kx+'a -> Trait+Ky+'b (auto traits and lifetime subtyping).
994
992
( & ty:: Dynamic ( ref data_a, r_a, dyn_a) , & ty:: Dynamic ( ref data_b, r_b, dyn_b) )
995
993
if dyn_a == dyn_b =>
@@ -1016,24 +1014,23 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1016
1014
1017
1015
// Require that the traits involved in this upcast are **equal**;
1018
1016
// only the **lifetime bound** is changed.
1019
- let InferOk { obligations, .. } = self
1017
+ let InferOk { mut obligations, .. } = self
1020
1018
. infcx
1021
1019
. at ( & obligation. cause , obligation. param_env )
1022
1020
. sup ( DefineOpaqueTypes :: No , target, source_trait)
1023
1021
. map_err ( |_| Unimplemented ) ?;
1024
- nested. extend ( obligations) ;
1025
1022
1026
1023
// Register one obligation for 'a: 'b.
1027
1024
let outlives = ty:: OutlivesPredicate ( r_a, r_b) ;
1028
- nested . push ( Obligation :: with_depth (
1025
+ obligations . push ( Obligation :: with_depth (
1029
1026
tcx,
1030
1027
obligation. cause . clone ( ) ,
1031
1028
obligation. recursion_depth + 1 ,
1032
1029
obligation. param_env ,
1033
1030
obligation. predicate . rebind ( outlives) ,
1034
1031
) ) ;
1035
1032
1036
- src = BuiltinImplSource :: Misc ;
1033
+ ImplSource :: Builtin ( BuiltinImplSource :: Misc , obligations )
1037
1034
}
1038
1035
1039
1036
// `T` -> `Trait`
@@ -1059,11 +1056,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1059
1056
// words, if the object type is `Foo + Send`, this would create an obligation for
1060
1057
// the `Send` check.)
1061
1058
// - Projection predicates
1062
- nested. extend (
1063
- data. iter ( ) . map ( |predicate| {
1064
- predicate_to_obligation ( predicate. with_self_ty ( tcx, source) )
1065
- } ) ,
1066
- ) ;
1059
+ let mut nested: Vec < _ > = data
1060
+ . iter ( )
1061
+ . map ( |predicate| predicate_to_obligation ( predicate. with_self_ty ( tcx, source) ) )
1062
+ . collect ( ) ;
1067
1063
1068
1064
// We can only make objects from sized types.
1069
1065
let tr = ty:: TraitRef :: from_lang_item (
@@ -1081,7 +1077,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1081
1077
ty:: Binder :: dummy ( ty:: ClauseKind :: TypeOutlives ( outlives) ) . to_predicate ( tcx) ,
1082
1078
) ) ;
1083
1079
1084
- src = BuiltinImplSource :: Misc ;
1080
+ ImplSource :: Builtin ( BuiltinImplSource :: Misc , nested )
1085
1081
}
1086
1082
1087
1083
// `[T; n]` -> `[T]`
@@ -1091,9 +1087,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1091
1087
. at ( & obligation. cause , obligation. param_env )
1092
1088
. eq ( DefineOpaqueTypes :: No , b, a)
1093
1089
. map_err ( |_| Unimplemented ) ?;
1094
- nested. extend ( obligations) ;
1095
1090
1096
- src = BuiltinImplSource :: Misc ;
1091
+ ImplSource :: Builtin ( BuiltinImplSource :: Misc , obligations )
1097
1092
}
1098
1093
1099
1094
// `Struct<T>` -> `Struct<U>`
@@ -1106,6 +1101,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1106
1101
let tail_field = def. non_enum_variant ( ) . tail ( ) ;
1107
1102
let tail_field_ty = tcx. type_of ( tail_field. did ) ;
1108
1103
1104
+ let mut nested = vec ! [ ] ;
1105
+
1109
1106
// Extract `TailField<T>` and `TailField<U>` from `Struct<T>` and `Struct<U>`,
1110
1107
// normalizing in the process, since `type_of` returns something directly from
1111
1108
// astconv (which means it's un-normalized).
@@ -1151,7 +1148,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1151
1148
) ;
1152
1149
nested. push ( tail_unsize_obligation) ;
1153
1150
1154
- src = BuiltinImplSource :: Misc ;
1151
+ ImplSource :: Builtin ( BuiltinImplSource :: Misc , nested )
1155
1152
}
1156
1153
1157
1154
// `(.., T)` -> `(.., U)`
@@ -1166,27 +1163,24 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1166
1163
// last element is equal to the target.
1167
1164
let new_tuple =
1168
1165
Ty :: new_tup_from_iter ( tcx, a_mid. iter ( ) . copied ( ) . chain ( iter:: once ( b_last) ) ) ;
1169
- let InferOk { obligations, .. } = self
1166
+ let InferOk { mut obligations, .. } = self
1170
1167
. infcx
1171
1168
. at ( & obligation. cause , obligation. param_env )
1172
1169
. eq ( DefineOpaqueTypes :: No , target, new_tuple)
1173
1170
. map_err ( |_| Unimplemented ) ?;
1174
- nested. extend ( obligations) ;
1175
1171
1176
1172
// Add a nested `T: Unsize<U>` predicate.
1177
1173
let last_unsize_obligation = obligation. with (
1178
1174
tcx,
1179
1175
ty:: TraitRef :: new ( tcx, obligation. predicate . def_id ( ) , [ a_last, b_last] ) ,
1180
1176
) ;
1181
- nested . push ( last_unsize_obligation) ;
1177
+ obligations . push ( last_unsize_obligation) ;
1182
1178
1183
- src = BuiltinImplSource :: TupleUnsizing ;
1179
+ ImplSource :: Builtin ( BuiltinImplSource :: TupleUnsizing , obligations )
1184
1180
}
1185
1181
1186
1182
_ => bug ! ( "source: {source}, target: {target}" ) ,
1187
- } ;
1188
-
1189
- Ok ( ImplSource :: Builtin ( src, nested) )
1183
+ } )
1190
1184
}
1191
1185
1192
1186
fn confirm_const_destruct_candidate (
0 commit comments