From bcb1af095ed973da0f9dfb3c5f759707f0e66113 Mon Sep 17 00:00:00 2001 From: Zalathar Date: Wed, 22 Apr 2026 14:11:19 +1000 Subject: [PATCH] Forbid `*-pass` and `*-fail` directives in tests/crashes Crash tests are always expected to crash during compilation, so there is no sensible meaning for specifying a pass/fail expectation in a crash test. --- src/doc/rustc-dev-guide/src/tests/directives.md | 16 ++++++++-------- src/tools/compiletest/src/directives.rs | 4 +--- src/tools/compiletest/src/runtest/crashes.rs | 5 ++--- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/doc/rustc-dev-guide/src/tests/directives.md b/src/doc/rustc-dev-guide/src/tests/directives.md index d536d324cb2b..38450d991d05 100644 --- a/src/doc/rustc-dev-guide/src/tests/directives.md +++ b/src/doc/rustc-dev-guide/src/tests/directives.md @@ -70,17 +70,17 @@ See [Controlling pass/fail expectations](ui.md#controlling-passfail-expectations | Directive | Explanation | Supported test suites | Possible values | |-----------------------------|---------------------------------------------|-------------------------------------------|-----------------| -| `check-pass` | Building (no codegen) should pass | `ui`, `crashes` | N/A | -| `check-fail` | Building (no codegen) should fail | `ui`, `crashes` | N/A | -| `build-pass` | Building should pass | `ui`, `crashes`, `codegen` | N/A | -| `build-fail` | Building should fail | `ui`, `crashes` | N/A | -| `run-pass` | Program must exit with code `0` | `ui`, `crashes` | N/A | -| `run-fail` | Program must exit with code `1..=127` | `ui`, `crashes` | N/A | +| `check-pass` | Building (no codegen) should pass | `ui` | N/A | +| `check-fail` | Building (no codegen) should fail | `ui` | N/A | +| `build-pass` | Building should pass | `ui` | N/A | +| `build-fail` | Building should fail | `ui` | N/A | +| `run-pass` | Program must exit with code `0` | `ui` | N/A | +| `run-fail` | Program must exit with code `1..=127` | `ui` | N/A | | `run-crash` | Program must crash | `ui` | N/A | | `run-fail-or-crash` | Program must `run-fail` or `run-crash` | `ui` | N/A | -| `ignore-pass` | Ignore `--pass` flag | `ui`, `crashes`, `codegen`, `incremental` | N/A | +| `ignore-pass` | Ignore `--pass` flag | `ui` | N/A | | `dont-check-failure-status` | Don't check exact failure status (i.e. `1`) | `ui`, `incremental` | N/A | -| `failure-status` | On failure, the compiler must exit with this status code. To expect an ICE, use `//@ failure-status: 101`. | `ui`, `crashes`, `incremental` | Any `u16` | +| `failure-status` | On failure, the compiler must exit with this status code. To expect an ICE, use `//@ failure-status: 101`. | `ui`, `incremental` | Any `u16` | | `should-fail` | Compiletest self-test | All | N/A | ### Controlling output snapshots and normalizations diff --git a/src/tools/compiletest/src/directives.rs b/src/tools/compiletest/src/directives.rs index d87cb915b07b..0575285af7a4 100644 --- a/src/tools/compiletest/src/directives.rs +++ b/src/tools/compiletest/src/directives.rs @@ -408,8 +408,7 @@ fn load_from(&mut self, testfile: &Utf8Path, test_revision: Option<&str>, config fn update_fail_mode(&mut self, ln: &DirectiveLine<'_>, config: &Config) { let check_ui = |mode: &str| { - // Mode::Crashes may need build-fail in order to trigger llvm errors or stack overflows - if config.mode != TestMode::Ui && config.mode != TestMode::Crashes { + if config.mode != TestMode::Ui { panic!("`{}-fail` directive is only supported in UI tests", mode); } }; @@ -441,7 +440,6 @@ fn update_fail_mode(&mut self, ln: &DirectiveLine<'_>, config: &Config) { fn update_pass_mode(&mut self, ln: &DirectiveLine<'_>, config: &Config) { let check_no_run = |s| match (config.mode, s) { (TestMode::Ui, _) => (), - (TestMode::Crashes, _) => (), (mode, _) => panic!("`{s}` directive is not supported in `{mode}` tests"), }; let pass_mode = if config.parse_name_directive(ln, "check-pass") { diff --git a/src/tools/compiletest/src/runtest/crashes.rs b/src/tools/compiletest/src/runtest/crashes.rs index 0aae7eaa39cd..210ab4dd05a7 100644 --- a/src/tools/compiletest/src/runtest/crashes.rs +++ b/src/tools/compiletest/src/runtest/crashes.rs @@ -1,9 +1,8 @@ -use super::{TestCx, WillExecute}; +use super::{Emit, TestCx, WillExecute}; impl TestCx<'_> { pub(super) fn run_crash_test(&self) { - let pm = self.pass_mode(); - let proc_res = self.compile_test(WillExecute::No, self.should_emit_metadata(pm)); + let proc_res = self.compile_test(WillExecute::No, Emit::None); if std::env::var("COMPILETEST_VERBOSE_CRASHES").is_ok() { writeln!(self.stderr, "{}", proc_res.status);