Skip to content
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

cargo reports a warning: panic setting is ignored for bench profile. When the value it is not ignored. #13894

Open
zeroflaw opened this issue May 9, 2024 · 2 comments
Labels
C-bug Category: bug S-triage Status: This issue is waiting on initial triage.

Comments

@zeroflaw
Copy link

zeroflaw commented May 9, 2024

Problem

cargo bench fails to compile when using build-std, however including 'panic = "unwind"' in Cargo.toml '[profile.bench]' fixes the issue. This causes cargo to warn about the setting being ignored, when it's clearly doing something.

Steps

versions:

rustc 1.80.0-nightly (87293c958 2024-05-08)
cargo 1.80.0-nightly (0ca60e940 2024-05-08)

~/.cargo/config.toml

[build]
rustflags = [
  "-C", "panic=abort",
  "-Z", "panic-in-drop=abort",
  "-Z", "panic_abort_tests",
]
target = "x86_64-unknown-linux-gnu"

[unstable]
build-std = ["core,alloc,std,panic_abort"]
build-std-features = []

/project/Cargo.toml

[workspace]
resolver = "2"
members = [ 
#snip
]

[profile.bench]
lto = true
codegen-units = 1
panic = "unwind"

[profile.release]
lto = true
codegen-units = 1
panic = "abort"

bench.rs

#![feature(test)]
extern crate test;

#[bench]
fn bench_a_thing(b: &mut test::Bencher) {
//snip
}

cargo bench without 'panic = "unwind"' in Cargo.toml '[profile.bench]'

error: the `#[alloc_error_handler]` in std conflicts with allocation error handler in: std

error[E0152]: duplicate lang item in crate `std` (which `test` depends on): `panic_impl`.

cargo bench with 'panic = "unwind"' in Cargo.toml '[profile.bench]'

warning: /project/Cargo.toml: `panic` setting is ignored for `bench` profile

bench run successful.

Possible Solution(s)

suppress / remove the warning, panic setting is ignored for bench profile

Notes

No response

Version

No response

@zeroflaw zeroflaw added C-bug Category: bug S-triage Status: This issue is waiting on initial triage. labels May 9, 2024
@ehuss
Copy link
Contributor

ehuss commented May 9, 2024

Cargo is not expecting the panic setting to be overridden via RUSTFLAGS. Generally, any rustc flag that cargo needs to control (such as all of those in the profile) should not be specified in RUSTFLAGS.

@zeroflaw
Copy link
Author

zeroflaw commented May 10, 2024

~/.cargo/config.toml

[build]
rustflags = [
  "-Z", "panic-in-drop=abort",
]
target = "x86_64-unknown-linux-gnu"

[unstable]
build-std = ["core,alloc,std"]

cargo bench without 'panic = "unwind"' in Cargo.toml '[profile.bench]'

error: the `#[alloc_error_handler]` in std conflicts with allocation error handler in: std

error: the crate `panic_unwind` does not have the panic strategy `unwind`

error[E0152]: duplicate lang item in crate `std` (which `test` depends on): `panic_impl`.

cargo bench with 'panic = "unwind"' in Cargo.toml '[profile.bench]'

warning: /project/Cargo.toml: `panic` setting is ignored for `bench` profile
    Finished `bench` profile [optimized] target(s) in 0.10s

Issue still occurs when I remove "-C", "panic=abort", from RUSTFLAGS.

'panic = "unwind"' in Cargo.toml '[profile.bench]' is not being ignored because if I set it to abort I get the same error as before. If changing the value changes the behaviour, how is it ignored?

edit: If I don't have any RUSTFLAGS in ~/.cargo/config.toml I get the same error/warning

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug S-triage Status: This issue is waiting on initial triage.
Projects
None yet
Development

No branches or pull requests

2 participants