@@ -3064,7 +3064,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
3064
3064
return None ;
3065
3065
} ;
3066
3066
3067
- self . commit_if_ok ( |_| {
3067
+ self . commit_if_ok ( |snapshot| {
3068
+ let outer_universe = self . universe ( ) ;
3069
+
3068
3070
let ocx = ObligationCtxt :: new ( self ) ;
3069
3071
let impl_args = self . fresh_args_for_item ( base_expr. span , impl_def_id) ;
3070
3072
let impl_trait_ref =
@@ -3074,7 +3076,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
3074
3076
// Match the impl self type against the base ty. If this fails,
3075
3077
// we just skip this impl, since it's not particularly useful.
3076
3078
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 ( ) ) ?;
3078
3080
3079
3081
// Register the impl's predicates. One of these predicates
3080
3082
// must be unsatisfied, or else we wouldn't have gotten here
@@ -3110,11 +3112,23 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
3110
3112
Ty :: new_projection ( self . tcx , index_trait_output_def_id, impl_trait_ref. args ) ,
3111
3113
) ;
3112
3114
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
+
3114
3128
// There should be at least one error reported. If not, we
3115
3129
// will still delay a span bug in `report_fulfillment_errors`.
3116
3130
Ok :: < _ , NoSolution > ( (
3117
- self . err_ctxt ( ) . report_fulfillment_errors ( errors ) ,
3131
+ self . err_ctxt ( ) . report_fulfillment_errors ( true_errors ) ,
3118
3132
impl_trait_ref. args . type_at ( 1 ) ,
3119
3133
element_ty,
3120
3134
) )
0 commit comments