From 31e0bf7891ca688bd550753f749e1f03db597675 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 13 Apr 2022 14:37:36 +0000 Subject: [PATCH] trait selection errors should poison the typeck results, too, so that const eval can avoid running at all --- .../src/traits/error_reporting/mod.rs | 1 + src/test/ui/consts/issue-91434.rs | 1 - src/test/ui/consts/issue-91434.stderr | 10 +--------- src/test/ui/consts/nested_erroneous_ctfe.rs | 4 ++++ src/test/ui/consts/nested_erroneous_ctfe.stderr | 12 ++++++++++++ 5 files changed, 18 insertions(+), 10 deletions(-) create mode 100644 src/test/ui/consts/nested_erroneous_ctfe.rs create mode 100644 src/test/ui/consts/nested_erroneous_ctfe.stderr diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs index 266fcc777ef..0cefa802c85 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs @@ -273,6 +273,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { error: &SelectionError<'tcx>, fallback_has_occurred: bool, ) { + self.set_tainted_by_errors(); let tcx = self.tcx; let mut span = obligation.cause.span; diff --git a/src/test/ui/consts/issue-91434.rs b/src/test/ui/consts/issue-91434.rs index fc7731291b3..001dc708f89 100644 --- a/src/test/ui/consts/issue-91434.rs +++ b/src/test/ui/consts/issue-91434.rs @@ -2,5 +2,4 @@ fn main() { [9; [[9E; h]]]; //~^ ERROR: expected at least one digit in exponent //~| ERROR: cannot find value `h` in this scope [E0425] - //~| ERROR: constant expression depends on a generic parameter } diff --git a/src/test/ui/consts/issue-91434.stderr b/src/test/ui/consts/issue-91434.stderr index 9d3fe5f2016..08d3ad77053 100644 --- a/src/test/ui/consts/issue-91434.stderr +++ b/src/test/ui/consts/issue-91434.stderr @@ -10,14 +10,6 @@ error[E0425]: cannot find value `h` in this scope LL | [9; [[9E; h]]]; | ^ not found in this scope -error: constant expression depends on a generic parameter - --> $DIR/issue-91434.rs:2:9 - | -LL | [9; [[9E; h]]]; - | ^^^^^^^^^ - | - = note: this may fail depending on what value the parameter takes - -error: aborting due to 3 previous errors +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0425`. diff --git a/src/test/ui/consts/nested_erroneous_ctfe.rs b/src/test/ui/consts/nested_erroneous_ctfe.rs new file mode 100644 index 00000000000..1ec271401fb --- /dev/null +++ b/src/test/ui/consts/nested_erroneous_ctfe.rs @@ -0,0 +1,4 @@ +fn main() { + [9; || [9; []]]; + //~^ ERROR: mismatched types +} diff --git a/src/test/ui/consts/nested_erroneous_ctfe.stderr b/src/test/ui/consts/nested_erroneous_ctfe.stderr new file mode 100644 index 00000000000..d579a54e983 --- /dev/null +++ b/src/test/ui/consts/nested_erroneous_ctfe.stderr @@ -0,0 +1,12 @@ +error[E0308]: mismatched types + --> $DIR/nested_erroneous_ctfe.rs:2:16 + | +LL | [9; || [9; []]]; + | ^^ expected `usize`, found array of 0 elements + | + = note: expected type `usize` + found array `[_; 0]` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`.