Skip to content

Commit 79f71f9

Browse files
committed
Refactor overflow handling in traits::select to propagate overflow instead of aborting eagerly
We store the obligation that caused the overflow as part of the OverflowError, and report it at the public API endpoints (rather than in the implementation internals).
1 parent 7f3444e commit 79f71f9

File tree

4 files changed

+113
-69
lines changed

4 files changed

+113
-69
lines changed

src/librustc/traits/error_reporting.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use super::{
2424
SelectionContext,
2525
SelectionError,
2626
ObjectSafetyViolation,
27+
Overflow,
2728
};
2829

2930
use errors::DiagnosticBuilder;
@@ -830,6 +831,10 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
830831
}
831832
err.struct_error(self.tcx, span, "constant expression")
832833
}
834+
835+
Overflow(_) => {
836+
bug!("overflow should be handled before the `report_selection_error` path");
837+
}
833838
};
834839
self.note_obligation_cause(&mut err, obligation);
835840
err.emit();

src/librustc/traits/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,8 @@ pub enum SelectionError<'tcx> {
349349
ty::error::TypeError<'tcx>),
350350
TraitNotObjectSafe(DefId),
351351
ConstEvalFailure(ConstEvalErr<'tcx>),
352+
// upon overflow, stores the obligation that hit the recursion limit
353+
Overflow(TraitObligation<'tcx>),
352354
}
353355

354356
pub struct FulfillmentError<'tcx> {

0 commit comments

Comments
 (0)