Skip to content

Commit 51f8076

Browse files
committed
Add --fix support to x.py clippy
1 parent b3246e0 commit 51f8076

File tree

3 files changed

+24
-14
lines changed

3 files changed

+24
-14
lines changed

src/bootstrap/builder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ impl<'a> Builder<'a> {
371371
tool::CargoMiri,
372372
native::Lld
373373
),
374-
Kind::Check | Kind::Clippy | Kind::Fix | Kind::Format => describe!(
374+
Kind::Check | Kind::Clippy { .. } | Kind::Fix | Kind::Format => describe!(
375375
check::Std,
376376
check::Rustc,
377377
check::Rustdoc,
@@ -540,7 +540,7 @@ impl<'a> Builder<'a> {
540540
let (kind, paths) = match build.config.cmd {
541541
Subcommand::Build { ref paths } => (Kind::Build, &paths[..]),
542542
Subcommand::Check { ref paths, all_targets: _ } => (Kind::Check, &paths[..]),
543-
Subcommand::Clippy { ref paths } => (Kind::Clippy, &paths[..]),
543+
Subcommand::Clippy { ref paths, .. } => (Kind::Clippy, &paths[..]),
544544
Subcommand::Fix { ref paths } => (Kind::Fix, &paths[..]),
545545
Subcommand::Doc { ref paths, .. } => (Kind::Doc, &paths[..]),
546546
Subcommand::Test { ref paths, .. } => (Kind::Test, &paths[..]),

src/bootstrap/check.rs

+17-11
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,26 @@ use crate::tool::{prepare_tool_cargo, SourceType};
77
use crate::INTERNER;
88
use crate::{
99
builder::{Builder, Kind, RunConfig, ShouldRun, Step},
10-
Subcommand,
1110
};
12-
use crate::{Compiler, Mode};
11+
use crate::{Compiler, Mode, Subcommand};
1312
use std::path::PathBuf;
1413

1514
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1615
pub struct Std {
1716
pub target: TargetSelection,
1817
}
1918

20-
fn args(kind: Kind) -> Vec<String> {
21-
match kind {
22-
Kind::Clippy => vec!["--".to_owned(), "--cap-lints".to_owned(), "warn".to_owned()],
23-
_ => Vec::new(),
19+
/// Returns args for the subcommand itself (not for cargo)
20+
fn args(builder: &Builder<'_>) -> Vec<String> {
21+
if let Subcommand::Clippy { fix, .. } = builder.config.cmd {
22+
let mut args = vec!["--".to_owned(), "--cap-lints".to_owned(), "warn".to_owned()];
23+
if fix {
24+
args.insert(0, "--fix".to_owned());
25+
args.insert(0, "-Zunstable-options".to_owned());
26+
}
27+
args
28+
} else {
29+
vec![]
2430
}
2531
}
2632

@@ -62,7 +68,7 @@ impl Step for Std {
6268
run_cargo(
6369
builder,
6470
cargo,
65-
args(builder.kind),
71+
args(builder),
6672
&libstd_stamp(builder, compiler, target),
6773
vec![],
6874
true,
@@ -104,7 +110,7 @@ impl Step for Std {
104110
run_cargo(
105111
builder,
106112
cargo,
107-
args(builder.kind),
113+
args(builder),
108114
&libstd_test_stamp(builder, compiler, target),
109115
vec![],
110116
true,
@@ -165,7 +171,7 @@ impl Step for Rustc {
165171
run_cargo(
166172
builder,
167173
cargo,
168-
args(builder.kind),
174+
args(builder),
169175
&librustc_stamp(builder, compiler, target),
170176
vec![],
171177
true,
@@ -220,7 +226,7 @@ impl Step for CodegenBackend {
220226
run_cargo(
221227
builder,
222228
cargo,
223-
args(builder.kind),
229+
args(builder),
224230
&codegen_backend_stamp(builder, compiler, target, backend),
225231
vec![],
226232
true,
@@ -278,7 +284,7 @@ macro_rules! tool_check_step {
278284
run_cargo(
279285
builder,
280286
cargo,
281-
args(builder.kind),
287+
args(builder),
282288
&stamp(builder, compiler, target),
283289
vec![],
284290
true,

src/bootstrap/flags.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ pub enum Subcommand {
5555
paths: Vec<PathBuf>,
5656
},
5757
Clippy {
58+
fix: bool,
5859
paths: Vec<PathBuf>,
5960
},
6061
Fix {
@@ -273,6 +274,9 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`",
273274
"bench" => {
274275
opts.optmulti("", "test-args", "extra arguments", "ARGS");
275276
}
277+
"clippy" => {
278+
opts.optflag("", "fix", "automatically apply lint suggestions");
279+
}
276280
"doc" => {
277281
opts.optflag("", "open", "open the docs in a browser");
278282
}
@@ -513,7 +517,7 @@ Arguments:
513517
"check" | "c" => {
514518
Subcommand::Check { paths, all_targets: matches.opt_present("all-targets") }
515519
}
516-
"clippy" => Subcommand::Clippy { paths },
520+
"clippy" => Subcommand::Clippy { paths, fix: matches.opt_present("fix") },
517521
"fix" => Subcommand::Fix { paths },
518522
"test" | "t" => Subcommand::Test {
519523
paths,

0 commit comments

Comments
 (0)