Skip to content

[beta-1.87] fix(rustc): Don't panic on unknown bins #15500

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions src/cargo/ops/cargo_compile/unit_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,26 +294,21 @@ impl<'a> UnitGenerator<'a, '_> {

let unmatched_packages = match self.spec {
Packages::Default | Packages::OptOut(_) | Packages::All(_) => {
"default-run packages".to_owned()
}
Packages::Packages(packages) => {
let first = packages
.first()
.expect("The number of packages must be at least 1");
if packages.len() == 1 {
format!("`{}` package", first)
} else {
format!("`{}`, ... packages", first)
}
" in default-run packages".to_owned()
}
Packages::Packages(packages) => match packages.len() {
0 => String::new(),
1 => format!(" in `{}` package", packages[0]),
_ => format!(" in `{}`, ... packages", packages[0]),
},
};

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

let mut msg = String::new();
write!(
msg,
"no {target_desc} target {named} `{target_name}` in {unmatched_packages}{suggestion}",
"no {target_desc} target {named} `{target_name}`{unmatched_packages}{suggestion}",
)?;
if !targets_elsewhere.is_empty() {
append_targets_elsewhere(&mut msg)?;
Expand Down
1 change: 1 addition & 0 deletions tests/testsuite/build_script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5513,6 +5513,7 @@ fn test_with_dep_metadata() {
p.cargo("test --lib").run();
}

#[ignore = "1-86 beta betaport"]
#[cargo_test]
fn duplicate_script_with_extra_env() {
// Test where a build script is run twice, that emits different rustc-env
Expand Down
3 changes: 2 additions & 1 deletion tests/testsuite/cross_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1218,7 +1218,8 @@ test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; fini
.run();
}

#[cargo_test(nightly, reason = "-Zdoctest-xcompile is unstable")]
#[ignore = "1-86 beta betaport"]
#[cargo_test]
fn doctest_xcompile_linker() {
if cross_compile::disabled() {
return;
Expand Down
3 changes: 2 additions & 1 deletion tests/testsuite/custom_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ const SIMPLE_SPEC: &str = r#"
}
"#;

#[cargo_test(nightly, reason = "requires features no_core, lang_items")]
#[ignore = "1-86 beta betaport"]
#[cargo_test]
fn custom_target_minimal() {
let p = project()
.file(
Expand Down
23 changes: 23 additions & 0 deletions tests/testsuite/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,29 @@ fn fail_with_multiple_packages() {
.run();
}

#[cargo_test]
fn fail_with_bad_bin_no_package() {
let p = project()
.file(
"src/main.rs",
r#"
fn main() { println!("hello a.rs"); }
"#,
)
.build();

p.cargo("rustc --bin main")
.with_status(101)
.with_stderr_data(str![[r#"
[ERROR] no bin target named `main`
[HELP] available bin targets:
foo
...

"#]])
.run();
}

#[cargo_test]
fn fail_with_glob() {
let p = project()
Expand Down
3 changes: 2 additions & 1 deletion tests/testsuite/standard_lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,8 @@ fn check_std() {
.run();
}

#[cargo_test(build_std_mock)]
#[ignore = "1-86 beta betaport"]
#[cargo_test]
fn doctest() {
let setup = setup();

Expand Down
12 changes: 7 additions & 5 deletions tests/testsuite/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4740,9 +4740,8 @@ fn test_dep_with_dev() {
.run();
}

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

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

#[cargo_test(nightly, reason = "-Zdoctest-xcompile is unstable")]
#[ignore = "1-86 beta betaport"]
#[cargo_test]
fn cargo_test_doctest_xcompile_runner() {
if !cross_compile::can_run_on_host() {
return;
Expand Down Expand Up @@ -4931,7 +4932,8 @@ this is a runner
.run();
}

#[cargo_test(nightly, reason = "-Zdoctest-xcompile is unstable")]
#[ignore = "1-86 beta betaport"]
#[cargo_test]
fn cargo_test_doctest_xcompile_no_runner() {
if !cross_compile::can_run_on_host() {
return;
Expand Down