Skip to content

Commit 7a5192f

Browse files
authored
fix(check): Fix suggested command for bin package (#16127)
fixes #15982 This PR fixes the suggested command for a bin package and fixes a comment while in the area.
2 parents 9d63ae2 + dc0eefb commit 7a5192f

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

src/cargo/core/compiler/job_queue/mod.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,15 +1085,8 @@ impl<'gctx> DrainState<'gctx> {
10851085
Some(wrapper) if wrapper == clippy => "cargo clippy --fix",
10861086
_ => "cargo fix",
10871087
};
1088-
let mut args = {
1089-
let named = unit.target.description_named();
1090-
// if its a lib we need to add the package to fix
1091-
if unit.target.is_lib() {
1092-
format!("{} -p {}", named, unit.pkg.name())
1093-
} else {
1094-
named
1095-
}
1096-
};
1088+
let mut args =
1089+
format!("{} -p {}", unit.target.description_named(), unit.pkg.name());
10971090
if unit.mode.is_rustc_test()
10981091
&& !(unit.target.is_test() || unit.target.is_bench())
10991092
{

tests/testsuite/check.rs

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,27 @@ fn check_virtual_manifest_one_project() {
515515
.run();
516516
}
517517

518+
#[cargo_test]
519+
fn check_virtual_manifest_one_bin_project_not_in_default_members() {
520+
let p = project()
521+
.file(
522+
"Cargo.toml",
523+
r#"
524+
[workspace]
525+
members = ["bar"]
526+
default-members = []
527+
resolver = "3"
528+
"#,
529+
)
530+
.file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0"))
531+
.file("bar/src/main.rs", "fn main() { let _ = (1); }")
532+
.build();
533+
534+
p.cargo("check -p bar")
535+
.with_stderr_contains("[..]run `cargo fix --bin \"bar\" -p bar` to apply[..]")
536+
.run();
537+
}
538+
518539
#[cargo_test]
519540
fn check_virtual_manifest_glob() {
520541
let p = project()
@@ -1400,7 +1421,7 @@ fn check_fixable_example() {
14001421
p.cargo("check --all-targets")
14011422
.with_stderr_data(str![[r#"
14021423
...
1403-
[WARNING] `foo` (example "ex1") generated 1 warning (run `cargo fix --example "ex1"` to apply 1 suggestion)
1424+
[WARNING] `foo` (example "ex1") generated 1 warning (run `cargo fix --example "ex1" -p foo` to apply 1 suggestion)
14041425
...
14051426
"#]])
14061427
.run();
@@ -1446,7 +1467,7 @@ fn check_fixable_bench() {
14461467
p.cargo("check --all-targets")
14471468
.with_stderr_data(str![[r#"
14481469
...
1449-
[WARNING] `foo` (bench "bench") generated 1 warning (run `cargo fix --bench "bench"` to apply 1 suggestion)
1470+
[WARNING] `foo` (bench "bench") generated 1 warning (run `cargo fix --bench "bench" -p foo` to apply 1 suggestion)
14501471
...
14511472
"#]])
14521473
.run();
@@ -1496,9 +1517,9 @@ fn check_fixable_mixed() {
14961517
.build();
14971518
p.cargo("check --all-targets")
14981519
.with_stderr_data(str![[r#"
1499-
[WARNING] `foo` (example "ex1") generated 1 warning (run `cargo fix --example "ex1"` to apply 1 suggestion)
1500-
[WARNING] `foo` (bench "bench") generated 1 warning (run `cargo fix --bench "bench"` to apply 1 suggestion)
1501-
[WARNING] `foo` (bin "foo" test) generated 2 warnings (run `cargo fix --bin "foo" --tests` to apply 2 suggestions)
1520+
[WARNING] `foo` (example "ex1") generated 1 warning (run `cargo fix --example "ex1" -p foo` to apply 1 suggestion)
1521+
[WARNING] `foo` (bench "bench") generated 1 warning (run `cargo fix --bench "bench" -p foo` to apply 1 suggestion)
1522+
[WARNING] `foo` (bin "foo" test) generated 2 warnings (run `cargo fix --bin "foo" -p foo --tests` to apply 2 suggestions)
15021523
...
15031524
"#]].unordered())
15041525
.run();

0 commit comments

Comments
 (0)