@@ -158,67 +158,65 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
158158 obligation : & TraitObligation < ' tcx > ,
159159 idx : usize ,
160160 ) -> Result < Vec < PredicateObligation < ' tcx > > , SelectionError < ' tcx > > {
161- self . infcx . commit_unconditionally ( |_| {
162- let tcx = self . tcx ( ) ;
163-
164- let trait_predicate = self . infcx . shallow_resolve ( obligation. predicate ) ;
165- let placeholder_trait_predicate =
166- self . infcx ( ) . replace_bound_vars_with_placeholders ( trait_predicate) . trait_ref ;
167- let placeholder_self_ty = placeholder_trait_predicate. self_ty ( ) ;
168- let placeholder_trait_predicate = ty:: Binder :: dummy ( placeholder_trait_predicate) ;
169- let ( def_id, substs) = match * placeholder_self_ty. kind ( ) {
170- ty:: Projection ( proj) => ( proj. item_def_id , proj. substs ) ,
171- ty:: Opaque ( def_id, substs) => ( def_id, substs) ,
172- _ => bug ! ( "projection candidate for unexpected type: {:?}" , placeholder_self_ty) ,
173- } ;
161+ let tcx = self . tcx ( ) ;
174162
175- let candidate_predicate =
176- tcx. bound_item_bounds ( def_id) . map_bound ( |i| i[ idx] ) . subst ( tcx, substs) ;
177- let candidate = candidate_predicate
178- . to_opt_poly_trait_pred ( )
179- . expect ( "projection candidate is not a trait predicate" )
180- . map_bound ( |t| t. trait_ref ) ;
181- let mut obligations = Vec :: new ( ) ;
182- let candidate = normalize_with_depth_to (
183- self ,
184- obligation. param_env ,
185- obligation. cause . clone ( ) ,
186- obligation. recursion_depth + 1 ,
187- candidate,
188- & mut obligations,
189- ) ;
163+ let trait_predicate = self . infcx . shallow_resolve ( obligation. predicate ) ;
164+ let placeholder_trait_predicate =
165+ self . infcx ( ) . replace_bound_vars_with_placeholders ( trait_predicate) . trait_ref ;
166+ let placeholder_self_ty = placeholder_trait_predicate. self_ty ( ) ;
167+ let placeholder_trait_predicate = ty:: Binder :: dummy ( placeholder_trait_predicate) ;
168+ let ( def_id, substs) = match * placeholder_self_ty. kind ( ) {
169+ ty:: Projection ( proj) => ( proj. item_def_id , proj. substs ) ,
170+ ty:: Opaque ( def_id, substs) => ( def_id, substs) ,
171+ _ => bug ! ( "projection candidate for unexpected type: {:?}" , placeholder_self_ty) ,
172+ } ;
190173
191- obligations. extend ( self . infcx . commit_if_ok ( |_| {
192- self . infcx
193- . at ( & obligation. cause , obligation. param_env )
194- . sup ( placeholder_trait_predicate, candidate)
195- . map ( |InferOk { obligations, .. } | obligations)
196- . map_err ( |_| Unimplemented )
197- } ) ?) ;
198-
199- if let ty:: Projection ( ..) = placeholder_self_ty. kind ( ) {
200- let predicates = tcx. predicates_of ( def_id) . instantiate_own ( tcx, substs) . predicates ;
201- debug ! ( ?predicates, "projection predicates" ) ;
202- for predicate in predicates {
203- let normalized = normalize_with_depth_to (
204- self ,
205- obligation. param_env ,
206- obligation. cause . clone ( ) ,
207- obligation. recursion_depth + 1 ,
208- predicate,
209- & mut obligations,
210- ) ;
211- obligations. push ( Obligation :: with_depth (
212- obligation. cause . clone ( ) ,
213- obligation. recursion_depth + 1 ,
214- obligation. param_env ,
215- normalized,
216- ) ) ;
217- }
174+ let candidate_predicate =
175+ tcx. bound_item_bounds ( def_id) . map_bound ( |i| i[ idx] ) . subst ( tcx, substs) ;
176+ let candidate = candidate_predicate
177+ . to_opt_poly_trait_pred ( )
178+ . expect ( "projection candidate is not a trait predicate" )
179+ . map_bound ( |t| t. trait_ref ) ;
180+ let mut obligations = Vec :: new ( ) ;
181+ let candidate = normalize_with_depth_to (
182+ self ,
183+ obligation. param_env ,
184+ obligation. cause . clone ( ) ,
185+ obligation. recursion_depth + 1 ,
186+ candidate,
187+ & mut obligations,
188+ ) ;
189+
190+ obligations. extend ( self . infcx . commit_if_ok ( |_| {
191+ self . infcx
192+ . at ( & obligation. cause , obligation. param_env )
193+ . sup ( placeholder_trait_predicate, candidate)
194+ . map ( |InferOk { obligations, .. } | obligations)
195+ . map_err ( |_| Unimplemented )
196+ } ) ?) ;
197+
198+ if let ty:: Projection ( ..) = placeholder_self_ty. kind ( ) {
199+ let predicates = tcx. predicates_of ( def_id) . instantiate_own ( tcx, substs) . predicates ;
200+ debug ! ( ?predicates, "projection predicates" ) ;
201+ for predicate in predicates {
202+ let normalized = normalize_with_depth_to (
203+ self ,
204+ obligation. param_env ,
205+ obligation. cause . clone ( ) ,
206+ obligation. recursion_depth + 1 ,
207+ predicate,
208+ & mut obligations,
209+ ) ;
210+ obligations. push ( Obligation :: with_depth (
211+ obligation. cause . clone ( ) ,
212+ obligation. recursion_depth + 1 ,
213+ obligation. param_env ,
214+ normalized,
215+ ) ) ;
218216 }
217+ }
219218
220- Ok ( obligations)
221- } )
219+ Ok ( obligations)
222220 }
223221
224222 fn confirm_param_candidate (
@@ -314,19 +312,16 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
314312 ensure_sufficient_stack ( || {
315313 let cause = obligation. derived_cause ( BuiltinDerivedObligation ) ;
316314
317- let trait_obligations: Vec < PredicateObligation < ' _ > > =
318- self . infcx . commit_unconditionally ( |_| {
319- let poly_trait_ref = obligation. predicate . to_poly_trait_ref ( ) ;
320- let trait_ref = self . infcx . replace_bound_vars_with_placeholders ( poly_trait_ref) ;
321- self . impl_or_trait_obligations (
322- & cause,
323- obligation. recursion_depth + 1 ,
324- obligation. param_env ,
325- trait_def_id,
326- & trait_ref. substs ,
327- obligation. predicate ,
328- )
329- } ) ;
315+ let poly_trait_ref = obligation. predicate . to_poly_trait_ref ( ) ;
316+ let trait_ref = self . infcx . replace_bound_vars_with_placeholders ( poly_trait_ref) ;
317+ let trait_obligations: Vec < PredicateObligation < ' _ > > = self . impl_or_trait_obligations (
318+ & cause,
319+ obligation. recursion_depth + 1 ,
320+ obligation. param_env ,
321+ trait_def_id,
322+ & trait_ref. substs ,
323+ obligation. predicate ,
324+ ) ;
330325
331326 let mut obligations = self . collect_predicates_for_types (
332327 obligation. param_env ,
@@ -355,19 +350,17 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
355350
356351 // First, create the substitutions by matching the impl again,
357352 // this time not in a probe.
358- self . infcx . commit_unconditionally ( |_| {
359- let substs = self . rematch_impl ( impl_def_id, obligation) ;
360- debug ! ( ?substs, "impl substs" ) ;
361- ensure_sufficient_stack ( || {
362- self . vtable_impl (
363- impl_def_id,
364- substs,
365- & obligation. cause ,
366- obligation. recursion_depth + 1 ,
367- obligation. param_env ,
368- obligation. predicate ,
369- )
370- } )
353+ let substs = self . rematch_impl ( impl_def_id, obligation) ;
354+ debug ! ( ?substs, "impl substs" ) ;
355+ ensure_sufficient_stack ( || {
356+ self . vtable_impl (
357+ impl_def_id,
358+ substs,
359+ & obligation. cause ,
360+ obligation. recursion_depth + 1 ,
361+ obligation. param_env ,
362+ obligation. predicate ,
363+ )
371364 } )
372365 }
373366
@@ -614,25 +607,23 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
614607 ) -> ImplSourceTraitAliasData < ' tcx , PredicateObligation < ' tcx > > {
615608 debug ! ( ?obligation, ?alias_def_id, "confirm_trait_alias_candidate" ) ;
616609
617- self . infcx . commit_unconditionally ( |_| {
618- let predicate = self . infcx ( ) . replace_bound_vars_with_placeholders ( obligation. predicate ) ;
619- let trait_ref = predicate. trait_ref ;
620- let trait_def_id = trait_ref. def_id ;
621- let substs = trait_ref. substs ;
610+ let predicate = self . infcx ( ) . replace_bound_vars_with_placeholders ( obligation. predicate ) ;
611+ let trait_ref = predicate. trait_ref ;
612+ let trait_def_id = trait_ref. def_id ;
613+ let substs = trait_ref. substs ;
622614
623- let trait_obligations = self . impl_or_trait_obligations (
624- & obligation. cause ,
625- obligation. recursion_depth ,
626- obligation. param_env ,
627- trait_def_id,
628- & substs,
629- obligation. predicate ,
630- ) ;
615+ let trait_obligations = self . impl_or_trait_obligations (
616+ & obligation. cause ,
617+ obligation. recursion_depth ,
618+ obligation. param_env ,
619+ trait_def_id,
620+ & substs,
621+ obligation. predicate ,
622+ ) ;
631623
632- debug ! ( ?trait_def_id, ?trait_obligations, "trait alias obligations" ) ;
624+ debug ! ( ?trait_def_id, ?trait_obligations, "trait alias obligations" ) ;
633625
634- ImplSourceTraitAliasData { alias_def_id, substs, nested : trait_obligations }
635- } )
626+ ImplSourceTraitAliasData { alias_def_id, substs, nested : trait_obligations }
636627 }
637628
638629 fn confirm_generator_candidate (
@@ -730,15 +721,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
730721 // Normalize the obligation and expected trait refs together, because why not
731722 let Normalized { obligations : nested, value : ( obligation_trait_ref, expected_trait_ref) } =
732723 ensure_sufficient_stack ( || {
733- self . infcx . commit_unconditionally ( |_| {
734- normalize_with_depth (
735- self ,
736- obligation. param_env ,
737- obligation. cause . clone ( ) ,
738- obligation. recursion_depth + 1 ,
739- ( obligation_trait_ref, expected_trait_ref) ,
740- )
741- } )
724+ normalize_with_depth (
725+ self ,
726+ obligation. param_env ,
727+ obligation. cause . clone ( ) ,
728+ obligation. recursion_depth + 1 ,
729+ ( obligation_trait_ref, expected_trait_ref) ,
730+ )
742731 } ) ;
743732
744733 self . infcx
@@ -1114,32 +1103,30 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
11141103 // first check it like a regular impl candidate.
11151104 // This is copied from confirm_impl_candidate but remaps the predicate to `~const Drop` beforehand.
11161105 if let Some ( impl_def_id) = impl_def_id {
1117- let obligations = self . infcx . commit_unconditionally ( |_| {
1118- let mut new_obligation = obligation. clone ( ) ;
1119- new_obligation. predicate = new_obligation. predicate . map_bound ( |mut trait_pred| {
1120- trait_pred. trait_ref . def_id = drop_trait;
1121- trait_pred
1122- } ) ;
1123- let substs = self . rematch_impl ( impl_def_id, & new_obligation) ;
1124- debug ! ( ?substs, "impl substs" ) ;
1125-
1126- let cause = obligation. derived_cause ( |derived| {
1127- ImplDerivedObligation ( Box :: new ( ImplDerivedObligationCause {
1128- derived,
1129- impl_def_id,
1130- span : obligation. cause . span ,
1131- } ) )
1132- } ) ;
1133- ensure_sufficient_stack ( || {
1134- self . vtable_impl (
1135- impl_def_id,
1136- substs,
1137- & cause,
1138- new_obligation. recursion_depth + 1 ,
1139- new_obligation. param_env ,
1140- obligation. predicate ,
1141- )
1142- } )
1106+ let mut new_obligation = obligation. clone ( ) ;
1107+ new_obligation. predicate = new_obligation. predicate . map_bound ( |mut trait_pred| {
1108+ trait_pred. trait_ref . def_id = drop_trait;
1109+ trait_pred
1110+ } ) ;
1111+ let substs = self . rematch_impl ( impl_def_id, & new_obligation) ;
1112+ debug ! ( ?substs, "impl substs" ) ;
1113+
1114+ let cause = obligation. derived_cause ( |derived| {
1115+ ImplDerivedObligation ( Box :: new ( ImplDerivedObligationCause {
1116+ derived,
1117+ impl_def_id,
1118+ span : obligation. cause . span ,
1119+ } ) )
1120+ } ) ;
1121+ let obligations = ensure_sufficient_stack ( || {
1122+ self . vtable_impl (
1123+ impl_def_id,
1124+ substs,
1125+ & cause,
1126+ new_obligation. recursion_depth + 1 ,
1127+ new_obligation. param_env ,
1128+ obligation. predicate ,
1129+ )
11431130 } ) ;
11441131 nested. extend ( obligations. nested ) ;
11451132 }
@@ -1190,34 +1177,30 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
11901177 // If we have a projection type, make sure to normalize it so we replace it
11911178 // with a fresh infer variable
11921179 ty:: Projection ( ..) => {
1193- self . infcx . commit_unconditionally ( |_| {
1194- let predicate = normalize_with_depth_to (
1195- self ,
1196- obligation. param_env ,
1197- cause. clone ( ) ,
1198- obligation. recursion_depth + 1 ,
1199- self_ty
1200- . rebind ( ty:: TraitPredicate {
1201- trait_ref : ty:: TraitRef {
1202- def_id : self
1203- . tcx ( )
1204- . require_lang_item ( LangItem :: Destruct , None ) ,
1205- substs : self . tcx ( ) . mk_substs_trait ( nested_ty, & [ ] ) ,
1206- } ,
1207- constness : ty:: BoundConstness :: ConstIfConst ,
1208- polarity : ty:: ImplPolarity :: Positive ,
1209- } )
1210- . to_predicate ( tcx) ,
1211- & mut nested,
1212- ) ;
1213-
1214- nested. push ( Obligation :: with_depth (
1215- cause. clone ( ) ,
1216- obligation. recursion_depth + 1 ,
1217- obligation. param_env ,
1218- predicate,
1219- ) ) ;
1220- } ) ;
1180+ let predicate = normalize_with_depth_to (
1181+ self ,
1182+ obligation. param_env ,
1183+ cause. clone ( ) ,
1184+ obligation. recursion_depth + 1 ,
1185+ self_ty
1186+ . rebind ( ty:: TraitPredicate {
1187+ trait_ref : ty:: TraitRef {
1188+ def_id : self . tcx ( ) . require_lang_item ( LangItem :: Destruct , None ) ,
1189+ substs : self . tcx ( ) . mk_substs_trait ( nested_ty, & [ ] ) ,
1190+ } ,
1191+ constness : ty:: BoundConstness :: ConstIfConst ,
1192+ polarity : ty:: ImplPolarity :: Positive ,
1193+ } )
1194+ . to_predicate ( tcx) ,
1195+ & mut nested,
1196+ ) ;
1197+
1198+ nested. push ( Obligation :: with_depth (
1199+ cause. clone ( ) ,
1200+ obligation. recursion_depth + 1 ,
1201+ obligation. param_env ,
1202+ predicate,
1203+ ) ) ;
12211204 }
12221205
12231206 // If we have any other type (e.g. an ADT), just register a nested obligation
0 commit comments