]> git.lizzy.rs Git - rust.git/commitdiff
Remove the stored obligation in OverflowError to simplify things
authorAravind Gollakota <aravindprasant@gmail.com>
Thu, 19 Apr 2018 07:49:21 +0000 (02:49 -0500)
committerAravind Gollakota <aravindprasant@gmail.com>
Fri, 27 Apr 2018 01:28:30 +0000 (20:28 -0500)
We will shortly refactor things so that it is no longer needed

src/librustc/traits/error_reporting.rs
src/librustc/traits/mod.rs
src/librustc/traits/select.rs
src/librustc/traits/structural_impls.rs
src/librustc_traits/evaluate_obligation.rs

index 98684825d91f7f0ac71790ea54227b2837c8be5a..285d530a38a69cab5e6eda57c2f29f9f5470d651 100644 (file)
@@ -831,7 +831,7 @@ pub fn report_selection_error(&self,
                 err.struct_error(self.tcx, span, "constant expression")
             }
 
-            Overflow(_) => {
+            Overflow => {
                 bug!("overflow should be handled before the `report_selection_error` path");
             }
         };
index 6a8a000b58a1093b4d596e6d5c0ef2181381f30e..dd5208e908e19e117243b7a13280b27abeff8a7f 100644 (file)
@@ -362,8 +362,7 @@ pub enum SelectionError<'tcx> {
                                 ty::error::TypeError<'tcx>),
     TraitNotObjectSafe(DefId),
     ConstEvalFailure(ConstEvalErr<'tcx>),
-    // upon overflow, stores the obligation that hit the recursion limit
-    Overflow(TraitObligation<'tcx>),
+    Overflow,
 }
 
 pub struct FulfillmentError<'tcx> {
index 342b163b2f72b1bd7a97c93b4cd9d556f0b3dbba..fdf6dcf4bf37d9096f05b11a687138fe1f33b21a 100644 (file)
@@ -421,14 +421,13 @@ fn is_stack_dependent(self) -> bool {
     EvaluatedToErr
 });
 
-#[derive(Clone, Debug, PartialEq, Eq)]
-/// Indicates that trait evaluation caused overflow. Stores the obligation
-/// that hit the recursion limit.
-pub struct OverflowError<'tcx>(pub TraitObligation<'tcx>);
+#[derive(Copy, Clone, Debug, PartialEq, Eq)]
+/// Indicates that trait evaluation caused overflow.
+pub struct OverflowError;
 
-impl<'tcx> From<OverflowError<'tcx>> for SelectionError<'tcx> {
-    fn from(OverflowError(o): OverflowError<'tcx>) -> SelectionError<'tcx> {
-        SelectionError::Overflow(o)
+impl<'tcx> From<OverflowError> for SelectionError<'tcx> {
+    fn from(OverflowError: OverflowError) -> SelectionError<'tcx> {
+        SelectionError::Overflow
     }
 }
 
@@ -573,7 +572,7 @@ pub fn select(&mut self, obligation: &TraitObligation<'tcx>)
         assert!(self.query_mode == TraitQueryMode::Standard);
 
         let candidate = match self.candidate_from_obligation(&stack) {
-            Err(SelectionError::Overflow(_)) =>
+            Err(SelectionError::Overflow) =>
                 bug!("Overflow should be caught earlier in standard query mode"),
             Err(e) => { return Err(e); },
             Ok(None) => { return Ok(None); },
@@ -581,7 +580,7 @@ pub fn select(&mut self, obligation: &TraitObligation<'tcx>)
         };
 
         match self.confirm_candidate(obligation, candidate) {
-            Err(SelectionError::Overflow(_)) =>
+            Err(SelectionError::Overflow) =>
                 bug!("Overflow should be caught earlier in standard query mode"),
             Err(e) => Err(e),
             Ok(candidate) => Ok(Some(candidate))
@@ -619,7 +618,7 @@ pub fn predicate_may_hold_fatal(&mut self,
     /// an `EvaluationResult`.
     pub fn evaluate_obligation_recursively(&mut self,
                                            obligation: &PredicateObligation<'tcx>)
-                                           -> Result<EvaluationResult, OverflowError<'tcx>>
+                                           -> Result<EvaluationResult, OverflowError>
     {
         self.probe(|this, _| {
             this.evaluate_predicate_recursively(TraitObligationStackList::empty(), obligation)
@@ -632,7 +631,7 @@ pub fn evaluate_obligation_recursively(&mut self,
     fn evaluate_predicates_recursively<'a,'o,I>(&mut self,
                                                 stack: TraitObligationStackList<'o, 'tcx>,
                                                 predicates: I)
-                                                -> Result<EvaluationResult, OverflowError<'tcx>>
+                                                -> Result<EvaluationResult, OverflowError>
         where I : IntoIterator<Item=&'a PredicateObligation<'tcx>>, 'tcx:'a
     {
         let mut result = EvaluatedToOk;
@@ -654,7 +653,7 @@ fn evaluate_predicates_recursively<'a,'o,I>(&mut self,
     fn evaluate_predicate_recursively<'o>(&mut self,
                                           previous_stack: TraitObligationStackList<'o, 'tcx>,
                                           obligation: &PredicateObligation<'tcx>)
-                                           -> Result<EvaluationResult, OverflowError<'tcx>>
+                                           -> Result<EvaluationResult, OverflowError>
     {
         debug!("evaluate_predicate_recursively({:?})",
                obligation);
@@ -775,7 +774,7 @@ fn evaluate_predicate_recursively<'o>(&mut self,
     fn evaluate_trait_predicate_recursively<'o>(&mut self,
                                                 previous_stack: TraitObligationStackList<'o, 'tcx>,
                                                 mut obligation: TraitObligation<'tcx>)
-                                                -> Result<EvaluationResult, OverflowError<'tcx>>
+                                                -> Result<EvaluationResult, OverflowError>
     {
         debug!("evaluate_trait_predicate_recursively({:?})",
                obligation);
@@ -810,7 +809,7 @@ fn evaluate_trait_predicate_recursively<'o>(&mut self,
 
     fn evaluate_stack<'o>(&mut self,
                           stack: &TraitObligationStack<'o, 'tcx>)
-                          -> Result<EvaluationResult, OverflowError<'tcx>>
+                          -> Result<EvaluationResult, OverflowError>
     {
         // In intercrate mode, whenever any of the types are unbound,
         // there can always be an impl. Even if there are no impls in
@@ -921,7 +920,7 @@ fn evaluate_stack<'o>(&mut self,
         match self.candidate_from_obligation(stack) {
             Ok(Some(c)) => self.evaluate_candidate(stack, &c),
             Ok(None) => Ok(EvaluatedToAmbig),
-            Err(Overflow(o)) => Err(OverflowError(o)),
+            Err(Overflow) => Err(OverflowError),
             Err(..) => Ok(EvaluatedToErr)
         }
     }
@@ -960,7 +959,7 @@ fn coinductive_predicate(&self, predicate: ty::Predicate<'tcx>) -> bool {
     fn evaluate_candidate<'o>(&mut self,
                               stack: &TraitObligationStack<'o, 'tcx>,
                               candidate: &SelectionCandidate<'tcx>)
-                              -> Result<EvaluationResult, OverflowError<'tcx>>
+                              -> Result<EvaluationResult, OverflowError>
     {
         debug!("evaluate_candidate: depth={} candidate={:?}",
                stack.obligation.recursion_depth, candidate);
@@ -1056,7 +1055,7 @@ fn candidate_from_obligation<'o>(&mut self,
                     self.infcx().report_overflow_error(&stack.obligation, true);
                 },
                 TraitQueryMode::Canonical => {
-                    return Err(Overflow(stack.obligation.clone()));
+                    return Err(Overflow);
                 },
             }
         }
@@ -1144,7 +1143,7 @@ fn candidate_from_obligation_no_cache<'o>(&mut self,
                             .vec
                             .iter()
                             .map(|c| self.evaluate_candidate(stack, &c))
-                            .collect::<Result<Vec<_>, OverflowError<'_>>>()?
+                            .collect::<Result<Vec<_>, OverflowError>>()?
                             .iter()
                             .all(|r| !r.may_apply());
                         if !candidate_set.ambiguous && no_candidates_apply {
@@ -1224,7 +1223,7 @@ fn candidate_from_obligation_no_cache<'o>(&mut self,
                     evaluation: eval,
                 })),
                 Ok(_) => Ok(None),
-                Err(OverflowError(o)) => Err(Overflow(o)),
+                Err(OverflowError) => Err(Overflow),
             })
             .collect();
 
@@ -1621,7 +1620,7 @@ fn assemble_candidates_from_caller_bounds<'o>(&mut self,
     fn evaluate_where_clause<'o>(&mut self,
                                  stack: &TraitObligationStack<'o, 'tcx>,
                                  where_clause_trait_ref: ty::PolyTraitRef<'tcx>)
-                                 -> Result<EvaluationResult, OverflowError<'tcx>>
+                                 -> Result<EvaluationResult, OverflowError>
     {
         self.probe(move |this, _| {
             match this.match_where_clause_trait_ref(stack.obligation, where_clause_trait_ref) {
index c124cd7942a68ccc6efd78f1e2cc90b94cfcadcc..d7e42655bbb5be35eca4e6b14c757a7778c0a167 100644 (file)
@@ -177,7 +177,7 @@ fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lif
             super::ConstEvalFailure(ref err) => {
                 tcx.lift(err).map(super::ConstEvalFailure)
             }
-            super::Overflow(_) => bug!() // FIXME: ape ConstEvalFailure?
+            super::Overflow => bug!() // FIXME: ape ConstEvalFailure?
         }
     }
 }
index a9cf35c4d70d43e2f5f3c9dc494f9ddb4b480810..f346bb8dc996b2a1021ce0a69d76ac9d1f4969c3 100644 (file)
@@ -32,8 +32,8 @@
 
         match selcx.evaluate_obligation_recursively(&obligation) {
             Ok(result) => result,
-            Err(OverflowError(o)) => {
-                infcx.report_overflow_error(&o, true)
+            Err(OverflowError) => {
+                infcx.report_overflow_error(&obligation, true)
             }
         }
     })