1
Fork 0

Issue 89275 fix and test

Issue 89275 fix and test

Fix librustdoc OverflowError usage

rust tidy run

Issue 89275 fix and test
This commit is contained in:
Tom Farmer 2021-10-05 18:53:24 +01:00
parent 25ec827385
commit 0950d5afe2
10 changed files with 82 additions and 18 deletions

View file

@ -842,6 +842,9 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
Overflow => {
bug!("overflow should be handled before the `report_selection_error` path");
}
SelectionError::ErrorReporting => {
bug!("ErrorReporting Overflow should not reach `report_selection_err` call")
}
};
self.note_obligation_cause(&mut err, &obligation);

View file

@ -83,17 +83,21 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'cx, 'tcx> {
) -> EvaluationResult {
match self.evaluate_obligation(obligation) {
Ok(result) => result,
Err(OverflowError) => {
Err(OverflowError::Cannonical) => {
let mut selcx = SelectionContext::with_query_mode(&self, TraitQueryMode::Standard);
selcx.evaluate_root_obligation(obligation).unwrap_or_else(|r| {
span_bug!(
obligation.cause.span,
"Overflow should be caught earlier in standard query mode: {:?}, {:?}",
obligation,
r,
)
selcx.evaluate_root_obligation(obligation).unwrap_or_else(|r| match r {
OverflowError::Cannonical => {
span_bug!(
obligation.cause.span,
"Overflow should be caught earlier in standard query mode: {:?}, {:?}",
obligation,
r,
)
}
OverflowError::ErrorReporting => EvaluationResult::EvaluatedToErr,
})
}
Err(OverflowError::ErrorReporting) => EvaluationResult::EvaluatedToErr,
}
}
}

View file

@ -13,7 +13,7 @@ use rustc_target::spec::abi::Abi;
use crate::traits::coherence::Conflict;
use crate::traits::{util, SelectionResult};
use crate::traits::{Overflow, Unimplemented};
use crate::traits::{ErrorReporting, Overflow, Unimplemented};
use super::BuiltinImplConditions;
use super::IntercrateAmbiguityCause;
@ -156,7 +156,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
Ok(Some(EvaluatedCandidate { candidate: c, evaluation: eval }))
}
Ok(_) => Ok(None),
Err(OverflowError) => Err(Overflow),
Err(OverflowError::Cannonical) => Err(Overflow),
Err(OverflowError::ErrorReporting) => Err(ErrorReporting),
})
.flat_map(Result::transpose)
.collect::<Result<Vec<_>, _>>()?;

View file

@ -20,8 +20,8 @@ use super::ObligationCauseCode;
use super::Selection;
use super::SelectionResult;
use super::TraitQueryMode;
use super::{ErrorReporting, Overflow, SelectionError, Unimplemented};
use super::{ObligationCause, PredicateObligation, TraitObligation};
use super::{Overflow, SelectionError, Unimplemented};
use crate::infer::{InferCtxt, InferOk, TypeFreshener};
use crate::traits::error_reporting::InferCtxtExt;
@ -900,7 +900,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
match self.candidate_from_obligation(stack) {
Ok(Some(c)) => self.evaluate_candidate(stack, &c),
Ok(None) => Ok(EvaluatedToAmbig),
Err(Overflow) => Err(OverflowError),
Err(Overflow) => Err(OverflowError::Cannonical),
Err(ErrorReporting) => Err(OverflowError::ErrorReporting),
Err(..) => Ok(EvaluatedToErr),
}
}
@ -1057,10 +1058,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
if !self.infcx.tcx.recursion_limit().value_within_limit(depth) {
match self.query_mode {
TraitQueryMode::Standard => {
if self.infcx.is_tainted_by_errors() {
return Err(OverflowError::ErrorReporting);
}
self.infcx.report_overflow_error(error_obligation, true);
}
TraitQueryMode::Canonical => {
return Err(OverflowError);
return Err(OverflowError::Cannonical);
}
}
}