Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/doc/rustc-dev-guide/src/tests/compiletest.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ then runs the compiler for each revision, reusing the incremental results from p

The revisions should start with:

* `cfail` — the test should fail to compile
* `cpass` — the test should compile successully
* `bfail` — the test should fail to compile
* `bpass` — the test should compile successully
* `rpass` — the test should compile and run successfully
Comment thread
jieyouxu marked this conversation as resolved.

To make the revisions unique, you should add a suffix like `rpass1` and `rpass2`.
Expand All @@ -185,7 +185,7 @@ fn foo() {
fn main() { foo(); }
```

`cfail` tests support the `forbid-output` directive to specify that a certain
Incremental tests support the `forbid-output` directive to specify that a certain
substring must not appear anywhere in the compiler output.
This can be useful to ensure certain errors do not appear, but this can be fragile as error messages
change over time, and a test may no longer be checking the right thing but will still pass.
Expand Down
5 changes: 2 additions & 3 deletions src/doc/rustc-dev-guide/src/tests/directives.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ comparison](ui.md#output-comparison) and [Rustfix tests](ui.md#rustfix-tests) fo
| `exec-env` | Env var to set when executing a test | `ui`, `crashes` | `<KEY>=<VALUE>` |
| `unset-exec-env` | Env var to unset when executing a test | `ui`, `crashes` | Any env var name |
| `stderr-per-bitwidth` | Generate a stderr snapshot for each bitwidth | `ui` | N/A |
| `forbid-output` | A pattern which must not appear in stderr/`cfail` output | `ui`, `incremental` | Regex pattern |
| `forbid-output` | Check that compile/run output does not contain a specific string | `ui`, `incremental` | String |
| `run-flags` | Flags passed to the test executable | `ui` | Arbitrary flags |
| `known-bug` | No error annotation needed due to known bug | `ui`, `crashes`, `incremental` | Issue number `#123456` |
| `compare-output-by-lines` | Compare the output by lines, rather than as a single string | All | N/A |
Expand Down Expand Up @@ -315,8 +315,7 @@ See [Pretty-printer](compiletest.md#pretty-printer-tests).

- `no-auto-check-cfg` — disable auto check-cfg (only for `--check-cfg` tests)
- [`revisions`](compiletest.md#revisions) — compile multiple times
-[`forbid-output`](compiletest.md#incremental-tests) — incremental cfail rejects
output pattern
- [`forbid-output`](compiletest.md#incremental-tests) — check that output does not contain a specified string
- [`reference`] — an annotation linking to a rule in the reference
- `disable-gdb-pretty-printers` — disable gdb pretty printers for debuginfo tests

Expand Down
6 changes: 3 additions & 3 deletions src/tools/compiletest/src/directives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ pub(crate) struct TestProps {
pub(crate) pretty_mode: String,
// Only compare pretty output and don't try compiling
pub(crate) pretty_compare_only: bool,
// Patterns which must not appear in the output of a cfail test.
/// Strings that must not appear in compile/run output.
pub(crate) forbid_output: Vec<String>,
// Revisions to test for incremental compilation.
pub(crate) revisions: Vec<String>,
Expand Down Expand Up @@ -442,8 +442,8 @@ impl TestProps {
(TestMode::Incremental, _) => {
// FIXME(Zalathar): This only detects forbidden directives that are
// declared _after_ the incompatible `//@ revisions:` directive(s).
if self.revisions.iter().any(|r| !r.starts_with("cfail")) {
panic!("`{s}` directive is only supported in `cfail` incremental tests")
if self.revisions.iter().any(|r| !r.starts_with("bfail")) {
panic!("`{s}` directive is only supported in `bfail` incremental tests")
}
}
(mode, _) => panic!("`{s}` directive is not supported in `{mode}` tests"),
Expand Down
6 changes: 3 additions & 3 deletions src/tools/compiletest/src/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,12 +327,12 @@ impl<'test> TestCx<'test> {
TestMode::Incremental => {
let revision =
self.revision.expect("incremental tests require a list of revisions");
if revision.starts_with("cpass") || revision.starts_with("rpass") {
if revision.starts_with("bpass") || revision.starts_with("rpass") {
true
} else if revision.starts_with("cfail") {
} else if revision.starts_with("bfail") {
pm.is_some()
} else {
panic!("revision name must begin with `cfail`, `cpass`, or `rpass`");
panic!("revision name must begin with `bfail`, `bpass`, or `rpass`");
}
}
mode => panic!("unimplemented for mode {:?}", mode),
Expand Down
28 changes: 14 additions & 14 deletions src/tools/compiletest/src/runtest/incremental.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ use super::{FailMode, ProcRes, TestCx, WillExecute};
impl TestCx<'_> {
pub(super) fn run_incremental_test(&self) {
// Basic plan for a test incremental/foo/bar.rs:
// - load list of revisions rpass1, cfail2, rpass3
// - each should begin with `cfail`, `cpass`, or `rpass`
// - if `cpass`, expect compilation to succeed, don't execute
// - load list of revisions rpass1, bfail2, rpass3
// - each should begin with `bfail`, `bpass`, or `rpass`
// - if `bfail`, expect compilation to fail
// - if `bpass`, expect compilation to succeed, don't execute
// - if `rpass`, expect compilation and execution to succeed
// - if `cfail`, expect compilation to fail
// - create a directory build/foo/bar.incremental
// - compile foo/bar.rs with -C incremental=.../foo/bar.incremental and -C rpass1
// - because name of revision starts with "rpass", expect success
// - compile foo/bar.rs with -C incremental=.../foo/bar.incremental and -C cfail2
// - because name of revision starts with "cfail", expect an error
// - load expected errors as usual, but filter for those with `[cfail2]`
// - compile foo/bar.rs with -C incremental=.../foo/bar.incremental and -C bfail2
// - because name of revision starts with "bfail", expect an error
// - load expected errors as usual, but filter for those with `[bfail2]`
// - compile foo/bar.rs with -C incremental=.../foo/bar.incremental and -C rpass3
// - because name of revision starts with "rpass", expect success
// - execute build/foo/bar.exe and save output
Expand All @@ -31,18 +31,18 @@ impl TestCx<'_> {
write!(self.stdout, "revision={:?} props={:#?}", revision, self.props);
}

if revision.starts_with("cpass") {
self.run_cpass_test();
if revision.starts_with("bpass") {
self.run_bpass_test();
} else if revision.starts_with("rpass") {
self.run_rpass_test();
} else if revision.starts_with("cfail") {
self.run_cfail_test();
} else if revision.starts_with("bfail") {
self.run_bfail_test();
} else {
self.fatal("revision name must begin with `cfail`, `cpass`, or `rpass`");
self.fatal("revision name must begin with `bfail`, `bpass`, or `rpass`");
}
}

fn run_cpass_test(&self) {
fn run_bpass_test(&self) {
let emit_metadata = self.should_emit_metadata(self.pass_mode());
let proc_res = self.compile_test(WillExecute::No, emit_metadata);

Expand Down Expand Up @@ -74,7 +74,7 @@ impl TestCx<'_> {
}
}

fn run_cfail_test(&self) {
fn run_bfail_test(&self) {
let pm = self.pass_mode();
let proc_res = self.compile_test(WillExecute::No, self.should_emit_metadata(pm));
self.check_if_test_should_compile(Some(FailMode::Build), pm, &proc_res);
Expand Down
22 changes: 11 additions & 11 deletions tests/incremental/add_private_fn_at_krate_root_cc/struct_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// crate. This should not cause anything we use to be invalidated.
// Regression test for #36168.

//@ revisions:cfail1 cfail2
//@ revisions: bfail1 bfail2
//@ compile-flags: -Z query-dep-graph
//@ aux-build:point.rs
//@ build-pass
Expand All @@ -12,19 +12,19 @@
#![allow(dead_code)]
#![crate_type = "rlib"]

#![rustc_partition_reused(module="struct_point-fn_calls_methods_in_same_impl", cfg="cfail2")]
#![rustc_partition_reused(module="struct_point-fn_calls_free_fn", cfg="cfail2")]
#![rustc_partition_reused(module="struct_point-fn_read_field", cfg="cfail2")]
#![rustc_partition_reused(module="struct_point-fn_write_field", cfg="cfail2")]
#![rustc_partition_reused(module="struct_point-fn_make_struct", cfg="cfail2")]
#![rustc_partition_reused(module="struct_point-fn_calls_methods_in_same_impl", cfg="bfail2")]
#![rustc_partition_reused(module="struct_point-fn_calls_free_fn", cfg="bfail2")]
#![rustc_partition_reused(module="struct_point-fn_read_field", cfg="bfail2")]
#![rustc_partition_reused(module="struct_point-fn_write_field", cfg="bfail2")]
#![rustc_partition_reused(module="struct_point-fn_make_struct", cfg="bfail2")]

extern crate point;

/// A fn item that calls (public) methods on `Point` from the same impl
pub mod fn_calls_methods_in_same_impl {
use point::Point;

#[rustc_clean(cfg="cfail2")]
#[rustc_clean(cfg="bfail2")]
pub fn check() {
let x = Point { x: 2.0, y: 2.0 };
x.distance_from_origin();
Expand All @@ -35,7 +35,7 @@ pub mod fn_calls_methods_in_same_impl {
pub mod fn_calls_free_fn {
use point::{self, Point};

#[rustc_clean(cfg="cfail2")]
#[rustc_clean(cfg="bfail2")]
pub fn check() {
let x = Point { x: 2.0, y: 2.0 };
point::distance_squared(&x);
Expand All @@ -46,7 +46,7 @@ pub mod fn_calls_free_fn {
pub mod fn_make_struct {
use point::Point;

#[rustc_clean(cfg="cfail2")]
#[rustc_clean(cfg="bfail2")]
pub fn make_origin() -> Point {
Point { x: 2.0, y: 2.0 }
}
Expand All @@ -56,7 +56,7 @@ pub mod fn_make_struct {
pub mod fn_read_field {
use point::Point;

#[rustc_clean(cfg="cfail2")]
#[rustc_clean(cfg="bfail2")]
pub fn get_x(p: Point) -> f32 {
p.x
}
Expand All @@ -66,7 +66,7 @@ pub mod fn_read_field {
pub mod fn_write_field {
use point::Point;

#[rustc_clean(cfg="cfail2")]
#[rustc_clean(cfg="bfail2")]
pub fn inc_x(p: &mut Point) {
p.x += 1.0;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/incremental/auxiliary/incremental_proc_macro_aux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ extern crate proc_macro;
use proc_macro::TokenStream;

// Add a function to shift DefIndex of registrar function
#[cfg(cfail2)]
#[cfg(bfail2)]
fn foo() {}

#[proc_macro_derive(IncrementalMacro)]
pub fn derive(input: TokenStream) -> TokenStream {
#[cfg(cfail2)]
#[cfg(bfail2)]
{
foo();
}
Expand Down
2 changes: 1 addition & 1 deletion tests/incremental/cache-lint-expectation.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Regression test for #154878
//@ revisions: cpass1 cpass2
//@ revisions: bpass1 bpass2

pub fn main() {
let x = 42.0;
Expand Down
44 changes: 22 additions & 22 deletions tests/incremental/change_add_field/struct_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Fns with that type used only in their body are also recompiled, but
// their callers are not.

//@ revisions:cfail1 cfail2
//@ revisions: bfail1 bfail2
//@ compile-flags: -Z query-dep-graph
//@ build-pass
//@ ignore-backends: gcc
Expand All @@ -13,24 +13,24 @@
#![crate_type = "rlib"]

// These are expected to require codegen.
#![rustc_partition_codegened(module="struct_point-point", cfg="cfail2")]
#![rustc_partition_codegened(module="struct_point-fn_with_type_in_sig", cfg="cfail2")]
#![rustc_partition_codegened(module="struct_point-call_fn_with_type_in_sig", cfg="cfail2")]
#![rustc_partition_codegened(module="struct_point-fn_with_type_in_body", cfg="cfail2")]
#![rustc_partition_codegened(module="struct_point-fn_make_struct", cfg="cfail2")]
#![rustc_partition_codegened(module="struct_point-fn_read_field", cfg="cfail2")]
#![rustc_partition_codegened(module="struct_point-fn_write_field", cfg="cfail2")]
#![rustc_partition_codegened(module="struct_point-point", cfg="bfail2")]
#![rustc_partition_codegened(module="struct_point-fn_with_type_in_sig", cfg="bfail2")]
#![rustc_partition_codegened(module="struct_point-call_fn_with_type_in_sig", cfg="bfail2")]
#![rustc_partition_codegened(module="struct_point-fn_with_type_in_body", cfg="bfail2")]
#![rustc_partition_codegened(module="struct_point-fn_make_struct", cfg="bfail2")]
#![rustc_partition_codegened(module="struct_point-fn_read_field", cfg="bfail2")]
#![rustc_partition_codegened(module="struct_point-fn_write_field", cfg="bfail2")]

#![rustc_partition_reused(module="struct_point-call_fn_with_type_in_body", cfg="cfail2")]
#![rustc_partition_reused(module="struct_point-call_fn_with_type_in_body", cfg="bfail2")]

pub mod point {
#[cfg(cfail1)]
#[cfg(bfail1)]
pub struct Point {
pub x: f32,
pub y: f32,
}

#[cfg(cfail2)]
#[cfg(bfail2)]
pub struct Point {
pub x: f32,
pub y: f32,
Expand All @@ -39,18 +39,18 @@ pub mod point {

impl Point {
pub fn origin() -> Point {
#[cfg(cfail1)]
#[cfg(bfail1)]
return Point { x: 0.0, y: 0.0 };

#[cfg(cfail2)]
#[cfg(bfail2)]
return Point { x: 0.0, y: 0.0, z: 0.0 };
}

pub fn total(&self) -> f32 {
#[cfg(cfail1)]
#[cfg(bfail1)]
return self.x + self.y;

#[cfg(cfail2)]
#[cfg(bfail2)]
return self.x + self.y + self.z;
}

Expand All @@ -70,7 +70,7 @@ pub mod point {
pub mod fn_with_type_in_sig {
use point::Point;

#[rustc_clean(except="typeck_root,fn_sig,optimized_mir", cfg="cfail2")]
#[rustc_clean(except="typeck_root,fn_sig,optimized_mir", cfg="bfail2")]
pub fn boop(p: Option<&Point>) -> f32 {
p.map(|p| p.total()).unwrap_or(0.0)
}
Expand All @@ -86,7 +86,7 @@ pub mod fn_with_type_in_sig {
pub mod call_fn_with_type_in_sig {
use fn_with_type_in_sig;

#[rustc_clean(except="typeck_root,optimized_mir", cfg="cfail2")]
#[rustc_clean(except="typeck_root,optimized_mir", cfg="bfail2")]
pub fn bip() -> f32 {
fn_with_type_in_sig::boop(None)
}
Expand All @@ -102,7 +102,7 @@ pub mod call_fn_with_type_in_sig {
pub mod fn_with_type_in_body {
use point::Point;

#[rustc_clean(except="typeck_root,optimized_mir", cfg="cfail2")]
#[rustc_clean(except="typeck_root,optimized_mir", cfg="bfail2")]
pub fn boop() -> f32 {
Point::origin().total()
}
Expand All @@ -115,7 +115,7 @@ pub mod fn_with_type_in_body {
pub mod call_fn_with_type_in_body {
use fn_with_type_in_body;

#[rustc_clean(cfg="cfail2")]
#[rustc_clean(cfg="bfail2")]
pub fn bip() -> f32 {
fn_with_type_in_body::boop()
}
Expand All @@ -125,7 +125,7 @@ pub mod call_fn_with_type_in_body {
pub mod fn_make_struct {
use point::Point;

#[rustc_clean(except="typeck_root,fn_sig,optimized_mir", cfg="cfail2")]
#[rustc_clean(except="typeck_root,fn_sig,optimized_mir", cfg="bfail2")]
pub fn make_origin(p: Point) -> Point {
Point { ..p }
}
Expand All @@ -135,7 +135,7 @@ pub mod fn_make_struct {
pub mod fn_read_field {
use point::Point;

#[rustc_clean(except="typeck_root,fn_sig,optimized_mir", cfg="cfail2")]
#[rustc_clean(except="typeck_root,fn_sig,optimized_mir", cfg="bfail2")]
pub fn get_x(p: Point) -> f32 {
p.x
}
Expand All @@ -145,7 +145,7 @@ pub mod fn_read_field {
pub mod fn_write_field {
use point::Point;

#[rustc_clean(except="typeck_root,fn_sig,optimized_mir", cfg="cfail2")]
#[rustc_clean(except="typeck_root,fn_sig,optimized_mir", cfg="bfail2")]
pub fn inc_x(p: &mut Point) {
p.x += 1.0;
}
Expand Down
6 changes: 3 additions & 3 deletions tests/incremental/change_crate_dep_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
// detected then -Zincremental-verify-ich will trigger an assertion.

//@ needs-unwind
//@ revisions:cfail1 cfail2
//@ revisions: bfail1 bfail2
//@ compile-flags: -Z query-dep-graph -Cpanic=unwind
//@ needs-unwind
//@ build-pass (FIXME(62277): could be check-pass?)
//@ ignore-backends: gcc

#![cfg_attr(cfail1, feature(panic_unwind))]
#![cfg_attr(bfail1, feature(panic_unwind))]

// Turn the panic_unwind crate from an explicit into an implicit query:
#[cfg(cfail1)]
#[cfg(bfail1)]
extern crate panic_unwind;

fn main() {}
Loading
Loading