Skip to content

Commit 0a6455d

Browse files
committed
Allow configuring rustfix::Filter independently of the mode
1 parent a18ef37 commit 0a6455d

File tree

5 files changed

+30
-13
lines changed

5 files changed

+30
-13
lines changed

src/config.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use regex::bytes::Regex;
22

3-
use crate::{dependencies::build_dependencies, CommandBuilder, Filter, Match, Mode};
3+
use crate::{dependencies::build_dependencies, CommandBuilder, Filter, Match, Mode, RustfixMode};
44
pub use color_eyre;
55
use color_eyre::eyre::Result;
66
use std::{
@@ -72,7 +72,7 @@ impl Config {
7272
root_dir: root_dir.into(),
7373
mode: Mode::Fail {
7474
require_patterns: true,
75-
rustfix: true,
75+
rustfix: RustfixMode::MachineApplicable,
7676
},
7777
program: CommandBuilder::rustc(),
7878
cfgs: CommandBuilder::cfgs(),
@@ -101,7 +101,7 @@ impl Config {
101101
edition: None,
102102
mode: Mode::Fail {
103103
require_patterns: true,
104-
rustfix: false,
104+
rustfix: RustfixMode::Disabled,
105105
},
106106
..Self::rustc(root_dir)
107107
}

src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -731,11 +731,11 @@ fn run_rustfix(
731731
comments.find_one_for_revision(revision, "`no-rustfix` annotations", |r| r.no_rustfix)?;
732732

733733
let global_rustfix = match mode {
734-
Mode::Pass | Mode::Run { .. } | Mode::Panic => false,
734+
Mode::Pass | Mode::Run { .. } | Mode::Panic => RustfixMode::Disabled,
735735
Mode::Fail { rustfix, .. } | Mode::Yolo { rustfix } => rustfix,
736736
};
737737

738-
let fixed_code = (no_run_rustfix.is_none() && global_rustfix)
738+
let fixed_code = (no_run_rustfix.is_none() && global_rustfix.enabled())
739739
.then_some(())
740740
.and_then(|()| {
741741
let suggestions = std::str::from_utf8(stderr)
@@ -748,7 +748,7 @@ fn run_rustfix(
748748
rustfix::get_suggestions_from_json(
749749
line,
750750
&HashSet::new(),
751-
if let Mode::Yolo { .. } = config.mode {
751+
if global_rustfix == RustfixMode::Everything {
752752
rustfix::Filter::Everything
753753
} else {
754754
rustfix::Filter::MachineApplicableOnly

src/mode.rs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,23 @@ use crate::Errored;
55
use std::fmt::Display;
66
use std::process::ExitStatus;
77

8+
/// When to run rustfix on tests
9+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
10+
pub enum RustfixMode {
11+
/// Do not run rustfix on the test
12+
Disabled,
13+
/// Apply only `MachineApplicable` suggestions emitted by the test
14+
MachineApplicable,
15+
/// Apply all suggestions emitted by the test
16+
Everything,
17+
}
18+
19+
impl RustfixMode {
20+
pub(crate) fn enabled(self) -> bool {
21+
self != RustfixMode::Disabled
22+
}
23+
}
24+
825
#[derive(Copy, Clone, Debug)]
926
/// Decides what is expected of each test's exit status.
1027
pub enum Mode {
@@ -21,13 +38,13 @@ pub enum Mode {
2138
Fail {
2239
/// Whether failing tests must have error patterns. Set to false if you just care about .stderr output.
2340
require_patterns: bool,
24-
/// Whether to run rustfix on the test if it has machine applicable suggestions.
25-
rustfix: bool,
41+
/// When to run rustfix on the test
42+
rustfix: RustfixMode,
2643
},
2744
/// Run the tests, but always pass them as long as all annotations are satisfied and stderr files match.
2845
Yolo {
29-
/// Whether to run
30-
rustfix: bool,
46+
/// When to run rustfix on the test
47+
rustfix: RustfixMode,
3148
},
3249
}
3350

tests/integrations/basic-fail-mode/tests/ui_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ fn main() -> ui_test::color_eyre::Result<()> {
66
dependencies_crate_manifest_path: Some("Cargo.toml".into()),
77
mode: Mode::Fail {
88
require_patterns: true,
9-
rustfix: true,
9+
rustfix: RustfixMode::MachineApplicable,
1010
},
1111
..Config::rustc("tests/actual_tests")
1212
};

tests/integrations/basic-fail/tests/ui_tests_bless.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ fn main() -> ui_test::color_eyre::Result<()> {
44
for mode in [
55
Mode::Fail {
66
require_patterns: true,
7-
rustfix: true,
7+
rustfix: RustfixMode::MachineApplicable,
88
},
9-
Mode::Yolo { rustfix: true },
9+
Mode::Yolo { rustfix: RustfixMode::Everything },
1010
] {
1111
let path = "../../../target";
1212

0 commit comments

Comments
 (0)