Skip to content

Commit ebf45a8

Browse files
committed
Forbid //@ compile-flags: -Cincremental= in tests
Tests should not try to manually enable incremental compilation with `-Cincremental`, because that typically results in stray directories being created in the repository root. Instead, use the `//@ incremental` directive, which instructs compiletest to handle the details of passing `-Cincremental` with a fresh directory.
1 parent e6429c7 commit ebf45a8

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/tools/compiletest/src/directives.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,10 +417,18 @@ impl TestProps {
417417
config.parse_name_value_directive(ln, COMPILE_FLAGS, testfile, line_number)
418418
{
419419
let flags = split_flags(&flags);
420-
for flag in &flags {
420+
for (i, flag) in flags.iter().enumerate() {
421421
if flag == "--edition" || flag.starts_with("--edition=") {
422422
panic!("you must use `//@ edition` to configure the edition");
423423
}
424+
if (flag == "-C"
425+
&& flags.get(i + 1).is_some_and(|v| v.starts_with("incremental=")))
426+
|| flag.starts_with("-Cincremental=")
427+
{
428+
panic!(
429+
"you must use `//@ incremental` to enable incremental compilation"
430+
);
431+
}
424432
}
425433
self.compile_flags.extend(flags);
426434
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//@ revisions: good bad bad-space
2+
//@ check-pass
3+
4+
//@[bad] compile-flags: -Cincremental=true
5+
//@[bad] should-fail
6+
7+
//@[bad-space] compile-flags: -C incremental=dir
8+
//@[bad-space] should-fail
9+
10+
fn main() {}
11+
12+
// Tests should not try to manually enable incremental compilation with
13+
// `-Cincremental`, because that typically results in stray directories being
14+
// created in the repository root.
15+
//
16+
// Instead, use the `//@ incremental` directive, which instructs compiletest
17+
// to handle the details of passing `-Cincremental` with a fresh directory.

0 commit comments

Comments
 (0)