@@ -3064,7 +3064,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
30643064 return None ;
30653065 } ;
30663066
3067- self . commit_if_ok ( |_| {
3067+ self . commit_if_ok ( |snapshot| {
3068+ let outer_universe = self . universe ( ) ;
3069+
30683070 let ocx = ObligationCtxt :: new ( self ) ;
30693071 let impl_args = self . fresh_args_for_item ( base_expr. span , impl_def_id) ;
30703072 let impl_trait_ref =
@@ -3074,7 +3076,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
30743076 // Match the impl self type against the base ty. If this fails,
30753077 // we just skip this impl, since it's not particularly useful.
30763078 let impl_trait_ref = ocx. normalize ( & cause, self . param_env , impl_trait_ref) ;
3077- ocx. eq ( & cause, self . param_env , impl_trait_ref. self_ty ( ) , base_ty ) ?;
3079+ ocx. eq ( & cause, self . param_env , base_ty , impl_trait_ref. self_ty ( ) ) ?;
30783080
30793081 // Register the impl's predicates. One of these predicates
30803082 // must be unsatisfied, or else we wouldn't have gotten here
@@ -3110,11 +3112,23 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
31103112 Ty :: new_projection ( self . tcx , index_trait_output_def_id, impl_trait_ref. args ) ,
31113113 ) ;
31123114
3113- let errors = ocx. select_where_possible ( ) ;
3115+ let true_errors = ocx. select_where_possible ( ) ;
3116+
3117+ // Do a leak check -- we can't really report report a useful error here,
3118+ // but it at least avoids an ICE when the error has to do with higher-ranked
3119+ // lifetimes.
3120+ self . leak_check ( outer_universe, Some ( snapshot) ) ?;
3121+
3122+ // Bail if we have ambiguity errors, which we can't report in a useful way.
3123+ let ambiguity_errors = ocx. select_all_or_error ( ) ;
3124+ if true_errors. is_empty ( ) && !ambiguity_errors. is_empty ( ) {
3125+ return Err ( NoSolution ) ;
3126+ }
3127+
31143128 // There should be at least one error reported. If not, we
31153129 // will still delay a span bug in `report_fulfillment_errors`.
31163130 Ok :: < _ , NoSolution > ( (
3117- self . err_ctxt ( ) . report_fulfillment_errors ( errors ) ,
3131+ self . err_ctxt ( ) . report_fulfillment_errors ( true_errors ) ,
31183132 impl_trait_ref. args . type_at ( 1 ) ,
31193133 element_ty,
31203134 ) )
0 commit comments