1
Fork 0

explicitly handle errors in fulfill

This commit is contained in:
Bastian Kauschke 2020-05-07 10:26:12 +02:00
parent afd7ea88fb
commit e873eef1e3
2 changed files with 26 additions and 25 deletions

View file

@ -2,6 +2,7 @@ use crate::infer::{InferCtxt, TyOrConstInferVar};
use rustc_data_structures::obligation_forest::ProcessResult; use rustc_data_structures::obligation_forest::ProcessResult;
use rustc_data_structures::obligation_forest::{DoCompleted, Error, ForestObligation}; use rustc_data_structures::obligation_forest::{DoCompleted, Error, ForestObligation};
use rustc_data_structures::obligation_forest::{ObligationForest, ObligationProcessor}; use rustc_data_structures::obligation_forest::{ObligationForest, ObligationProcessor};
use rustc_errors::ErrorReported;
use rustc_infer::traits::{TraitEngine, TraitEngineExt as _}; use rustc_infer::traits::{TraitEngine, TraitEngineExt as _};
use rustc_middle::mir::interpret::ErrorHandled; use rustc_middle::mir::interpret::ErrorHandled;
use rustc_middle::ty::error::ExpectedFound; use rustc_middle::ty::error::ExpectedFound;
@ -544,11 +545,9 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
.filter_map(|ty| TyOrConstInferVar::maybe_from_ty(ty)) .filter_map(|ty| TyOrConstInferVar::maybe_from_ty(ty))
.collect(), .collect(),
); );
Err(ProcessResult::Unchanged) Err(ErrorHandled::TooGeneric)
}
Err(err) => {
Err(ProcessResult::Error(CodeSelectionError(ConstEvalFailure(err))))
} }
Err(err) => Err(err),
} }
} else { } else {
Ok(c) Ok(c)
@ -572,15 +571,17 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
} }
} }
} }
// FIXME(skinny121) How to report both errors if both produces errors? (Err(ErrorHandled::Reported(ErrorReported)), _)
(Err(result @ ProcessResult::Error(_)), _) | (_, Err(ErrorHandled::Reported(ErrorReported))) => ProcessResult::Error(
| (_, Err(result @ ProcessResult::Error(_))) => result, CodeSelectionError(ConstEvalFailure(ErrorHandled::Reported(ErrorReported))),
(Err(ProcessResult::Unchanged), _) | (_, Err(ProcessResult::Unchanged)) => { ),
(Err(ErrorHandled::Linted), _) | (_, Err(ErrorHandled::Linted)) => span_bug!(
obligation.cause.span(self.selcx.tcx()),
"ConstEquate: const_eval_resolve returned an unexpected error"
),
(Err(ErrorHandled::TooGeneric), _) | (_, Err(ErrorHandled::TooGeneric)) => {
ProcessResult::Unchanged ProcessResult::Unchanged
} }
_ => {
unreachable!("evaluate shouldn't itself return ProcessResult::Changed(..)")
}
} }
} }
} }

View file

@ -1,40 +1,40 @@
warning: the feature `const_generics` is incomplete and may cause the compiler to crash warning: the feature `const_generics` is incomplete and may cause the compiler to crash
--> $DIR/lazy-normalization-feature-gate-hack.rs:2:12 --> $DIR/lazy-normalization-feature-gate.rs:2:12
| |
LL | #![feature(const_generics)] LL | #![feature(const_generics)]
| ^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^
| |
= note: `#[warn(incomplete_features)]` on by default = note: `#[warn(incomplete_features)]` on by default
error[E0391]: cycle detected when const-evaluating + checking `<impl at $DIR/lazy-normalization-feature-gate-hack.rs:6:1: 6:72>::{{constant}}#0` error[E0391]: cycle detected when const-evaluating + checking `<impl at $DIR/lazy-normalization-feature-gate.rs:6:1: 6:72>::{{constant}}#0`
--> $DIR/lazy-normalization-feature-gate-hack.rs:6:58 --> $DIR/lazy-normalization-feature-gate.rs:6:58
| |
LL | impl<const N: usize> Foo for [(); N] where Self: FooImpl<{ N == 0 }> {} LL | impl<const N: usize> Foo for [(); N] where Self: FooImpl<{ N == 0 }> {}
| ^^^^^^^^^^ | ^^^^^^^^^^
| |
note: ...which requires const-evaluating + checking `<impl at $DIR/lazy-normalization-feature-gate-hack.rs:6:1: 6:72>::{{constant}}#0`... note: ...which requires const-evaluating + checking `<impl at $DIR/lazy-normalization-feature-gate.rs:6:1: 6:72>::{{constant}}#0`...
--> $DIR/lazy-normalization-feature-gate-hack.rs:6:58 --> $DIR/lazy-normalization-feature-gate.rs:6:58
| |
LL | impl<const N: usize> Foo for [(); N] where Self: FooImpl<{ N == 0 }> {} LL | impl<const N: usize> Foo for [(); N] where Self: FooImpl<{ N == 0 }> {}
| ^^^^^^^^^^ | ^^^^^^^^^^
note: ...which requires const-evaluating `<impl at $DIR/lazy-normalization-feature-gate-hack.rs:6:1: 6:72>::{{constant}}#0`... note: ...which requires const-evaluating `<impl at $DIR/lazy-normalization-feature-gate.rs:6:1: 6:72>::{{constant}}#0`...
--> $DIR/lazy-normalization-feature-gate-hack.rs:6:58 --> $DIR/lazy-normalization-feature-gate.rs:6:58
| |
LL | impl<const N: usize> Foo for [(); N] where Self: FooImpl<{ N == 0 }> {} LL | impl<const N: usize> Foo for [(); N] where Self: FooImpl<{ N == 0 }> {}
| ^^^^^^^^^^ | ^^^^^^^^^^
note: ...which requires type-checking `<impl at $DIR/lazy-normalization-feature-gate-hack.rs:6:1: 6:72>::{{constant}}#0`... note: ...which requires type-checking `<impl at $DIR/lazy-normalization-feature-gate.rs:6:1: 6:72>::{{constant}}#0`...
--> $DIR/lazy-normalization-feature-gate-hack.rs:6:58 --> $DIR/lazy-normalization-feature-gate.rs:6:58
| |
LL | impl<const N: usize> Foo for [(); N] where Self: FooImpl<{ N == 0 }> {} LL | impl<const N: usize> Foo for [(); N] where Self: FooImpl<{ N == 0 }> {}
| ^^^^^^^^^^ | ^^^^^^^^^^
note: ...which requires processing `<impl at $DIR/lazy-normalization-feature-gate-hack.rs:6:1: 6:72>::{{constant}}#0`... note: ...which requires processing `<impl at $DIR/lazy-normalization-feature-gate.rs:6:1: 6:72>::{{constant}}#0`...
--> $DIR/lazy-normalization-feature-gate-hack.rs:6:58 --> $DIR/lazy-normalization-feature-gate.rs:6:58
| |
LL | impl<const N: usize> Foo for [(); N] where Self: FooImpl<{ N == 0 }> {} LL | impl<const N: usize> Foo for [(); N] where Self: FooImpl<{ N == 0 }> {}
| ^^^^^^^^^^ | ^^^^^^^^^^
= note: ...which again requires const-evaluating + checking `<impl at $DIR/lazy-normalization-feature-gate-hack.rs:6:1: 6:72>::{{constant}}#0`, completing the cycle = note: ...which again requires const-evaluating + checking `<impl at $DIR/lazy-normalization-feature-gate.rs:6:1: 6:72>::{{constant}}#0`, completing the cycle
note: cycle used when processing `<impl at $DIR/lazy-normalization-feature-gate-hack.rs:6:1: 6:72>` note: cycle used when processing `<impl at $DIR/lazy-normalization-feature-gate.rs:6:1: 6:72>`
--> $DIR/lazy-normalization-feature-gate-hack.rs:6:1 --> $DIR/lazy-normalization-feature-gate.rs:6:1
| |
LL | impl<const N: usize> Foo for [(); N] where Self: FooImpl<{ N == 0 }> {} LL | impl<const N: usize> Foo for [(); N] where Self: FooImpl<{ N == 0 }> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^