Skip to content

Commit 99624be

Browse files
authored
[beta-1.87] fix(rustc): Don't panic on unknown bins (#15500)
Beta backports * #15497 In order to make CI pass, the following PRs are also cherry-picked: *
2 parents 2025158 + 02b87a7 commit 99624be

File tree

7 files changed

+44
-20
lines changed

7 files changed

+44
-20
lines changed

src/cargo/ops/cargo_compile/unit_generator.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -294,26 +294,21 @@ impl<'a> UnitGenerator<'a, '_> {
294294

295295
let unmatched_packages = match self.spec {
296296
Packages::Default | Packages::OptOut(_) | Packages::All(_) => {
297-
"default-run packages".to_owned()
298-
}
299-
Packages::Packages(packages) => {
300-
let first = packages
301-
.first()
302-
.expect("The number of packages must be at least 1");
303-
if packages.len() == 1 {
304-
format!("`{}` package", first)
305-
} else {
306-
format!("`{}`, ... packages", first)
307-
}
297+
" in default-run packages".to_owned()
308298
}
299+
Packages::Packages(packages) => match packages.len() {
300+
0 => String::new(),
301+
1 => format!(" in `{}` package", packages[0]),
302+
_ => format!(" in `{}`, ... packages", packages[0]),
303+
},
309304
};
310305

311306
let named = if is_glob { "matches pattern" } else { "named" };
312307

313308
let mut msg = String::new();
314309
write!(
315310
msg,
316-
"no {target_desc} target {named} `{target_name}` in {unmatched_packages}{suggestion}",
311+
"no {target_desc} target {named} `{target_name}`{unmatched_packages}{suggestion}",
317312
)?;
318313
if !targets_elsewhere.is_empty() {
319314
append_targets_elsewhere(&mut msg)?;

tests/testsuite/build_script.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5513,6 +5513,7 @@ fn test_with_dep_metadata() {
55135513
p.cargo("test --lib").run();
55145514
}
55155515

5516+
#[ignore = "1-86 beta betaport"]
55165517
#[cargo_test]
55175518
fn duplicate_script_with_extra_env() {
55185519
// Test where a build script is run twice, that emits different rustc-env

tests/testsuite/cross_compile.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1218,7 +1218,8 @@ test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; fini
12181218
.run();
12191219
}
12201220

1221-
#[cargo_test(nightly, reason = "-Zdoctest-xcompile is unstable")]
1221+
#[ignore = "1-86 beta betaport"]
1222+
#[cargo_test]
12221223
fn doctest_xcompile_linker() {
12231224
if cross_compile::disabled() {
12241225
return;

tests/testsuite/custom_target.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ const SIMPLE_SPEC: &str = r#"
3636
}
3737
"#;
3838

39-
#[cargo_test(nightly, reason = "requires features no_core, lang_items")]
39+
#[ignore = "1-86 beta betaport"]
40+
#[cargo_test]
4041
fn custom_target_minimal() {
4142
let p = project()
4243
.file(

tests/testsuite/rustc.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,29 @@ fn fail_with_multiple_packages() {
533533
.run();
534534
}
535535

536+
#[cargo_test]
537+
fn fail_with_bad_bin_no_package() {
538+
let p = project()
539+
.file(
540+
"src/main.rs",
541+
r#"
542+
fn main() { println!("hello a.rs"); }
543+
"#,
544+
)
545+
.build();
546+
547+
p.cargo("rustc --bin main")
548+
.with_status(101)
549+
.with_stderr_data(str![[r#"
550+
[ERROR] no bin target named `main`
551+
[HELP] available bin targets:
552+
foo
553+
...
554+
555+
"#]])
556+
.run();
557+
}
558+
536559
#[cargo_test]
537560
fn fail_with_glob() {
538561
let p = project()

tests/testsuite/standard_lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,8 @@ fn check_std() {
646646
.run();
647647
}
648648

649-
#[cargo_test(build_std_mock)]
649+
#[ignore = "1-86 beta betaport"]
650+
#[cargo_test]
650651
fn doctest() {
651652
let setup = setup();
652653

tests/testsuite/test.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4740,9 +4740,8 @@ fn test_dep_with_dev() {
47404740
.run();
47414741
}
47424742

4743-
// #[cargo_test(nightly, reason = "-Zdoctest-xcompile is unstable")]
4743+
#[ignore = "1-86 beta betaport"]
47444744
#[cargo_test]
4745-
#[ignore = "waiting for https://github.com/rust-lang/rust/pull/138877"]
47464745
fn cargo_test_doctest_xcompile_ignores() {
47474746
// -Zdoctest-xcompile also enables --enable-per-target-ignores which
47484747
// allows the ignore-TARGET syntax.
@@ -4802,7 +4801,8 @@ test result: ok. 0 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out; fini
48024801
.run();
48034802
}
48044803

4805-
#[cargo_test(nightly, reason = "-Zdoctest-xcompile is unstable")]
4804+
#[ignore = "1-86 beta betaport"]
4805+
#[cargo_test]
48064806
fn cargo_test_doctest_xcompile() {
48074807
if !cross_compile::can_run_on_host() {
48084808
return;
@@ -4844,7 +4844,8 @@ test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; fini
48444844
.run();
48454845
}
48464846

4847-
#[cargo_test(nightly, reason = "-Zdoctest-xcompile is unstable")]
4847+
#[ignore = "1-86 beta betaport"]
4848+
#[cargo_test]
48484849
fn cargo_test_doctest_xcompile_runner() {
48494850
if !cross_compile::can_run_on_host() {
48504851
return;
@@ -4931,7 +4932,8 @@ this is a runner
49314932
.run();
49324933
}
49334934

4934-
#[cargo_test(nightly, reason = "-Zdoctest-xcompile is unstable")]
4935+
#[ignore = "1-86 beta betaport"]
4936+
#[cargo_test]
49354937
fn cargo_test_doctest_xcompile_no_runner() {
49364938
if !cross_compile::can_run_on_host() {
49374939
return;

0 commit comments

Comments
 (0)