@@ -361,15 +361,23 @@ fn impl_intersection_has_impossible_obligation<'a, 'cx, 'tcx>(
361361 let infcx = selcx. infcx ;
362362
363363 obligations. iter ( ) . find ( |obligation| {
364- if infcx. next_trait_solver ( ) {
365- infcx. evaluate_obligation ( obligation) . map_or ( false , |result| !result . may_apply ( ) )
364+ let evaluation_result = if infcx. next_trait_solver ( ) {
365+ infcx. evaluate_obligation ( obligation)
366366 } else {
367367 // We use `evaluate_root_obligation` to correctly track intercrate
368368 // ambiguity clauses. We cannot use this in the new solver.
369- selcx. evaluate_root_obligation ( obligation) . map_or (
370- false , // Overflow has occurred, and treat the obligation as possibly holding.
371- |result| !result. may_apply ( ) ,
372- )
369+ selcx. evaluate_root_obligation ( obligation)
370+ } ;
371+
372+ match evaluation_result {
373+ Ok ( result) => !result. may_apply ( ) ,
374+ // If overflow occurs, we need to conservatively treat the goal as possibly holding,
375+ // since there can be instantiations of this goal that don't overflow and result in
376+ // success. This isn't much of a problem in the old solver, since we treat overflow
377+ // fatally (this still can be encountered: <https://github.com/rust-lang/rust/issues/105231>),
378+ // but in the new solver, this is very important for correctness, since overflow
379+ // *must* be treated as ambiguity for completeness.
380+ Err ( _overflow) => false ,
373381 }
374382 } )
375383}
0 commit comments