Skip to content

Commit 6fb65f1

Browse files
committed
some changes, ill clean this up in a hot sec
1 parent 85ba8e9 commit 6fb65f1

File tree

5 files changed

+53
-48
lines changed

5 files changed

+53
-48
lines changed

src/cargo/ops/fix.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ pub struct FixOptions<'a> {
7575
pub allow_no_vcs: bool,
7676
pub allow_staged: bool,
7777
pub broken_code: bool,
78-
pub use_clippy: bool,
7978
pub clippy_args: Option<Vec<String>>,
8079
}
8180

@@ -103,7 +102,7 @@ pub fn fix(ws: &Workspace<'_>, opts: &mut FixOptions<'_>) -> CargoResult<()> {
103102
wrapper.env(IDIOMS_ENV, "1");
104103
}
105104

106-
if opts.use_clippy {
105+
if opts.clippy_args.is_some() {
107106
if let Err(e) = util::process("clippy-driver").arg("-V").exec_with_output() {
108107
eprintln!("Warning: clippy-driver not found: {:?}", e);
109108
}
@@ -401,7 +400,6 @@ fn rustfix_and_fix(
401400

402401
let mut cmd = Command::new(rustc);
403402
cmd.arg("--error-format=json");
404-
405403
args.apply(&mut cmd);
406404
let output = cmd
407405
.output()

src/cargo/util/config.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1790,7 +1790,6 @@ impl Drop for PackageCacheLock<'_> {
17901790
/// Allows override of the path via `CARGO_CLIPPY_DRIVER` env variable
17911791
pub fn clippy_driver() -> PathBuf {
17921792
env::var("CARGO_CLIPPY_DRIVER")
1793-
.ok()
1794-
.unwrap_or_else(|| "clippy-driver".into())
1793+
.unwrap_or_else(|_| "clippy_driver".into())
17951794
.into()
17961795
}

tests/testsuite/clippy.rs

Lines changed: 3 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::support::{is_nightly, process, project};
1+
use crate::support::{clippy_is_available, is_nightly, process, project};
22

33
#[cargo_test]
44
fn clippy() {
@@ -7,9 +7,8 @@ fn clippy() {
77
eprintln!("skipping test: requires nightly");
88
return;
99
}
10-
if let Err(e) = process("clippy-driver").arg("-V").exec_with_output() {
11-
eprintln!("clippy-driver not available, skipping clippy test");
12-
eprintln!("{:?}", e);
10+
11+
if !clippy_is_available() {
1312
return;
1413
}
1514

@@ -38,42 +37,3 @@ fn clippy() {
3837
.with_stderr_contains("[..]assert!(true)[..]") // This should not be here.
3938
.run();
4039
}
41-
42-
#[cargo_test]
43-
fn fix_with_clippy() {
44-
if !is_nightly() {
45-
// fix --clippy is unstable
46-
eprintln!("skipping test: requires nightly");
47-
return;
48-
}
49-
50-
if let Err(e) = process("clippy-driver").arg("-V").exec_with_output() {
51-
eprintln!("clippy-driver not available, skipping clippy test");
52-
eprintln!("{:?}", e);
53-
return;
54-
}
55-
56-
let p = project()
57-
.file(
58-
"src/lib.rs",
59-
"
60-
pub fn foo() {
61-
let mut v = Vec::<String>::new();
62-
let _ = v.iter_mut().filter(|&ref a| a.is_empty());
63-
}
64-
",
65-
)
66-
.build();
67-
68-
let stderr = "\
69-
[CHECKING] foo v0.0.1 ([..])
70-
[FIXING] src/lib.rs (1 fix)
71-
[FINISHED] [..]
72-
";
73-
74-
p.cargo("fix -Zunstable-options --clippy --allow-no-vcs")
75-
.masquerade_as_nightly_cargo()
76-
.with_stderr(stderr)
77-
.with_stdout("")
78-
.run();
79-
}

tests/testsuite/fix.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,3 +1285,41 @@ fn fix_in_existing_repo_weird_ignore() {
12851285
.run();
12861286
p.cargo("fix").cwd("src").run();
12871287
}
1288+
1289+
#[cargo_test]
1290+
fn fix_with_clippy() {
1291+
if !is_nightly() {
1292+
// fix --clippy is unstable
1293+
eprintln!("skipping test: requires nightly");
1294+
return;
1295+
}
1296+
1297+
if !clippy_is_available() {
1298+
return;
1299+
}
1300+
1301+
let p = project()
1302+
.file(
1303+
"src/lib.rs",
1304+
"
1305+
pub fn foo() {
1306+
let mut v = Vec::<String>::new();
1307+
let _ = v.iter_mut().filter(|&ref a| a.is_empty());
1308+
}
1309+
",
1310+
)
1311+
.build();
1312+
1313+
let stderr = "\
1314+
[CHECKING] foo v0.0.1 ([..])
1315+
[FIXING] src/lib.rs (1 fix)
1316+
[FINISHED] [..]
1317+
";
1318+
1319+
p.cargo("fix -Zunstable-options --clippy --allow-no-vcs")
1320+
.masquerade_as_nightly_cargo()
1321+
.diff_lines("", "", false)
1322+
.with_stderr(stderr)
1323+
.with_stdout("")
1324+
.run();
1325+
}

tests/testsuite/support/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1753,3 +1753,13 @@ pub fn slow_cpu_multiplier(main: u64) -> Duration {
17531753
}
17541754
Duration::from_secs(*SLOW_CPU_MULTIPLIER * main)
17551755
}
1756+
1757+
pub fn clippy_is_available() -> bool {
1758+
if let Err(e) = process("clippy-driver").arg("-V").exec_with_output() {
1759+
eprintln!("clippy-driver not available, skipping clippy test");
1760+
eprintln!("{:?}", e);
1761+
false
1762+
} else {
1763+
true
1764+
}
1765+
}

0 commit comments

Comments
 (0)