Skip to content

Commit e873eef

Browse files
committed
explicitly handle errors in fulfill
1 parent afd7ea8 commit e873eef

File tree

2 files changed

+26
-25
lines changed

2 files changed

+26
-25
lines changed

src/librustc_trait_selection/traits/fulfill.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::infer::{InferCtxt, TyOrConstInferVar};
22
use rustc_data_structures::obligation_forest::ProcessResult;
33
use rustc_data_structures::obligation_forest::{DoCompleted, Error, ForestObligation};
44
use rustc_data_structures::obligation_forest::{ObligationForest, ObligationProcessor};
5+
use rustc_errors::ErrorReported;
56
use rustc_infer::traits::{TraitEngine, TraitEngineExt as _};
67
use rustc_middle::mir::interpret::ErrorHandled;
78
use rustc_middle::ty::error::ExpectedFound;
@@ -544,11 +545,9 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
544545
.filter_map(|ty| TyOrConstInferVar::maybe_from_ty(ty))
545546
.collect(),
546547
);
547-
Err(ProcessResult::Unchanged)
548-
}
549-
Err(err) => {
550-
Err(ProcessResult::Error(CodeSelectionError(ConstEvalFailure(err))))
548+
Err(ErrorHandled::TooGeneric)
551549
}
550+
Err(err) => Err(err),
552551
}
553552
} else {
554553
Ok(c)
@@ -572,15 +571,17 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
572571
}
573572
}
574573
}
575-
// FIXME(skinny121) How to report both errors if both produces errors?
576-
(Err(result @ ProcessResult::Error(_)), _)
577-
| (_, Err(result @ ProcessResult::Error(_))) => result,
578-
(Err(ProcessResult::Unchanged), _) | (_, Err(ProcessResult::Unchanged)) => {
574+
(Err(ErrorHandled::Reported(ErrorReported)), _)
575+
| (_, Err(ErrorHandled::Reported(ErrorReported))) => ProcessResult::Error(
576+
CodeSelectionError(ConstEvalFailure(ErrorHandled::Reported(ErrorReported))),
577+
),
578+
(Err(ErrorHandled::Linted), _) | (_, Err(ErrorHandled::Linted)) => span_bug!(
579+
obligation.cause.span(self.selcx.tcx()),
580+
"ConstEquate: const_eval_resolve returned an unexpected error"
581+
),
582+
(Err(ErrorHandled::TooGeneric), _) | (_, Err(ErrorHandled::TooGeneric)) => {
579583
ProcessResult::Unchanged
580584
}
581-
_ => {
582-
unreachable!("evaluate shouldn't itself return ProcessResult::Changed(..)")
583-
}
584585
}
585586
}
586587
}

src/test/ui/const-generics/lazy-normalization/lazy-normalization-feature-gate.stderr

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,40 @@
11
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
2-
--> $DIR/lazy-normalization-feature-gate-hack.rs:2:12
2+
--> $DIR/lazy-normalization-feature-gate.rs:2:12
33
|
44
LL | #![feature(const_generics)]
55
| ^^^^^^^^^^^^^^
66
|
77
= note: `#[warn(incomplete_features)]` on by default
88

9-
error[E0391]: cycle detected when const-evaluating + checking `<impl at $DIR/lazy-normalization-feature-gate-hack.rs:6:1: 6:72>::{{constant}}#0`
10-
--> $DIR/lazy-normalization-feature-gate-hack.rs:6:58
9+
error[E0391]: cycle detected when const-evaluating + checking `<impl at $DIR/lazy-normalization-feature-gate.rs:6:1: 6:72>::{{constant}}#0`
10+
--> $DIR/lazy-normalization-feature-gate.rs:6:58
1111
|
1212
LL | impl<const N: usize> Foo for [(); N] where Self: FooImpl<{ N == 0 }> {}
1313
| ^^^^^^^^^^
1414
|
15-
note: ...which requires const-evaluating + checking `<impl at $DIR/lazy-normalization-feature-gate-hack.rs:6:1: 6:72>::{{constant}}#0`...
16-
--> $DIR/lazy-normalization-feature-gate-hack.rs:6:58
15+
note: ...which requires const-evaluating + checking `<impl at $DIR/lazy-normalization-feature-gate.rs:6:1: 6:72>::{{constant}}#0`...
16+
--> $DIR/lazy-normalization-feature-gate.rs:6:58
1717
|
1818
LL | impl<const N: usize> Foo for [(); N] where Self: FooImpl<{ N == 0 }> {}
1919
| ^^^^^^^^^^
20-
note: ...which requires const-evaluating `<impl at $DIR/lazy-normalization-feature-gate-hack.rs:6:1: 6:72>::{{constant}}#0`...
21-
--> $DIR/lazy-normalization-feature-gate-hack.rs:6:58
20+
note: ...which requires const-evaluating `<impl at $DIR/lazy-normalization-feature-gate.rs:6:1: 6:72>::{{constant}}#0`...
21+
--> $DIR/lazy-normalization-feature-gate.rs:6:58
2222
|
2323
LL | impl<const N: usize> Foo for [(); N] where Self: FooImpl<{ N == 0 }> {}
2424
| ^^^^^^^^^^
25-
note: ...which requires type-checking `<impl at $DIR/lazy-normalization-feature-gate-hack.rs:6:1: 6:72>::{{constant}}#0`...
26-
--> $DIR/lazy-normalization-feature-gate-hack.rs:6:58
25+
note: ...which requires type-checking `<impl at $DIR/lazy-normalization-feature-gate.rs:6:1: 6:72>::{{constant}}#0`...
26+
--> $DIR/lazy-normalization-feature-gate.rs:6:58
2727
|
2828
LL | impl<const N: usize> Foo for [(); N] where Self: FooImpl<{ N == 0 }> {}
2929
| ^^^^^^^^^^
30-
note: ...which requires processing `<impl at $DIR/lazy-normalization-feature-gate-hack.rs:6:1: 6:72>::{{constant}}#0`...
31-
--> $DIR/lazy-normalization-feature-gate-hack.rs:6:58
30+
note: ...which requires processing `<impl at $DIR/lazy-normalization-feature-gate.rs:6:1: 6:72>::{{constant}}#0`...
31+
--> $DIR/lazy-normalization-feature-gate.rs:6:58
3232
|
3333
LL | impl<const N: usize> Foo for [(); N] where Self: FooImpl<{ N == 0 }> {}
3434
| ^^^^^^^^^^
35-
= 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
36-
note: cycle used when processing `<impl at $DIR/lazy-normalization-feature-gate-hack.rs:6:1: 6:72>`
37-
--> $DIR/lazy-normalization-feature-gate-hack.rs:6:1
35+
= note: ...which again requires const-evaluating + checking `<impl at $DIR/lazy-normalization-feature-gate.rs:6:1: 6:72>::{{constant}}#0`, completing the cycle
36+
note: cycle used when processing `<impl at $DIR/lazy-normalization-feature-gate.rs:6:1: 6:72>`
37+
--> $DIR/lazy-normalization-feature-gate.rs:6:1
3838
|
3939
LL | impl<const N: usize> Foo for [(); N] where Self: FooImpl<{ N == 0 }> {}
4040
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)