@@ -361,15 +361,23 @@ fn impl_intersection_has_impossible_obligation<'a, 'cx, 'tcx>(
361
361
let infcx = selcx. infcx ;
362
362
363
363
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)
366
366
} else {
367
367
// We use `evaluate_root_obligation` to correctly track intercrate
368
368
// 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 ,
373
381
}
374
382
} )
375
383
}
0 commit comments