]> git.lizzy.rs Git - rust.git/blobdiff - compiler/rustc_trait_selection/src/traits/select/mod.rs
Rollup merge of #89726 - jkugelman:must-use-alloc-constructors, r=joshtriplett
[rust.git] / compiler / rustc_trait_selection / src / traits / select / mod.rs
index e191654210a43531236dd057fdd41657ac67267c..85502a399dedac0bbc74781160255accebbba09d 100644 (file)
@@ -20,8 +20,8 @@
 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 @@ fn evaluate_stack<'o>(
         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::Canonical),
+            Err(ErrorReporting) => Err(OverflowError::ErrorReporting),
             Err(..) => Ok(EvaluatedToErr),
         }
     }
@@ -1057,10 +1058,13 @@ fn check_recursion_depth<T: Display + TypeFoldable<'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::Canonical);
                 }
             }
         }