@@ -432,6 +432,9 @@ pub fn impossible_predicates<'tcx>(
432432 debug ! ( "impossible_predicates(predicates={:?})" , predicates) ;
433433
434434 let result = tcx. infer_ctxt ( ) . enter ( |infcx| {
435+ // HACK: Set tainted by errors to gracefully exit in case of overflow.
436+ infcx. set_tainted_by_errors ( ) ;
437+
435438 let param_env = ty:: ParamEnv :: reveal_all ( ) ;
436439 let mut selcx = SelectionContext :: new ( & infcx) ;
437440 let mut fulfill_cx = FulfillmentContext :: new ( ) ;
@@ -448,6 +451,9 @@ pub fn impossible_predicates<'tcx>(
448451
449452 let errors = fulfill_cx. select_all_or_error ( & infcx) ;
450453
454+ // Clean up after ourselves
455+ let _ = infcx. inner . borrow_mut ( ) . opaque_type_storage . take_opaque_types ( ) ;
456+
451457 !errors. is_empty ( )
452458 } ) ;
453459 debug ! ( "impossible_predicates = {:?}" , result) ;
@@ -461,6 +467,14 @@ fn subst_and_check_impossible_predicates<'tcx>(
461467 debug ! ( "subst_and_check_impossible_predicates(key={:?})" , key) ;
462468
463469 let mut predicates = tcx. predicates_of ( key. 0 ) . instantiate ( tcx, key. 1 ) . predicates ;
470+
471+ // Specifically check trait fulfillment to avoid an error when trying to resolve
472+ // associated items.
473+ if let Some ( trait_def_id) = tcx. trait_of_item ( key. 0 ) {
474+ let trait_ref = ty:: TraitRef :: from_method ( tcx, trait_def_id, key. 1 ) ;
475+ predicates. push ( ty:: Binder :: dummy ( trait_ref) . to_poly_trait_predicate ( ) . to_predicate ( tcx) ) ;
476+ }
477+
464478 predicates. retain ( |predicate| !predicate. needs_subst ( ) ) ;
465479 let result = impossible_predicates ( tcx, predicates) ;
466480
0 commit comments