-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
debug-assertions
are implicitly disabled when running cargo test
with opt-level=3
set from rustflags
#14033
Comments
You don't need to comment out Looking at verbose output $ cargo clean && cargo test -vvv
Removed 45 files, 12.2MiB total
Compiling cargo-14033 v0.1.0 (/home/epage/src/personal/dump/cargo-14033)
Running `CARGO=/home/epage/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/cargo CARGO_BIN_NAME=cargo-1403
3 CARGO_CRATE_NAME=cargo_14033 CARGO_MANIFEST_DIR=/home/epage/src/personal/dump/cargo-14033 CARGO_PKG_AUTHORS='' CARGO
_PKG_DESCRIPTION='' CARGO_PKG_HOMEPAGE='' CARGO_PKG_LICENSE='' CARGO_PKG_LICENSE_FILE='' CARGO_PKG_NAME=cargo-14033 CA
RGO_PKG_README='' CARGO_PKG_REPOSITORY='' CARGO_PKG_RUST_VERSION='' CARGO_PKG_VERSION=0.1.0 CARGO_PKG_VERSION_MAJOR=0
CARGO_PKG_VERSION_MINOR=1 CARGO_PKG_VERSION_PATCH=0 CARGO_PKG_VERSION_PRE='' CARGO_PRIMARY_PACKAGE=1 LD_LIBRARY_PATH='
/home/epage/src/personal/dump/cargo-14033/target/debug/deps:/home/epage/.rustup/toolchains/stable-x86_64-unknown-linux
-gnu/lib' /home/epage/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/rustc --crate-name cargo_14033 --edition=
2021 src/main.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=118
--emit=dep-info,link -C opt-level=3 -C embed-bitcode=no -C debuginfo=2 -C debug-assertions=on --test -C metadata=b4ef5
f5c9b16634d -C extra-filename=-b4ef5f5c9b16634d --out-dir /home/epage/src/personal/dump/cargo-14033/target/debug/deps
-C incremental=/home/epage/src/personal/dump/cargo-14033/target/debug/incremental -L dependency=/home/epage/src/person
al/dump/cargo-14033/target/debug/deps -C opt-level=3`
Finished `test` profile [optimized + debuginfo] target(s) in 0.13s
Running `CARGO=/home/epage/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/cargo CARGO_MANIFEST_DIR=/home/
epage/src/personal/dump/cargo-14033 CARGO_PKG_AUTHORS='' CARGO_PKG_DESCRIPTION='' CARGO_PKG_HOMEPAGE='' CARGO_PKG_LICE
NSE='' CARGO_PKG_LICENSE_FILE='' CARGO_PKG_NAME=cargo-14033 CARGO_PKG_README='' CARGO_PKG_REPOSITORY='' CARGO_PKG_RUST
_VERSION='' CARGO_PKG_VERSION=0.1.0 CARGO_PKG_VERSION_MAJOR=0 CARGO_PKG_VERSION_MINOR=1 CARGO_PKG_VERSION_PATCH=0 CARG
O_PKG_VERSION_PRE='' LD_LIBRARY_PATH='/home/epage/src/personal/dump/cargo-14033/target/debug/deps:/home/epage/src/pers
onal/dump/cargo-14033/target/debug:/home/epage/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-u
nknown-linux-gnu/lib:/home/epage/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib' /home/epage/src/personal/dump
/cargo-14033/target/debug/deps/cargo_14033-b4ef5f5c9b16634d`
running 1 test
test debug_assert_false ... FAILED
failures:
---- debug_assert_false stdout ----
thread 'debug_assert_false' panicked at src/main.rs:7:5:
assertion failed: false
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
failures:
debug_assert_false
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
error: test failed, to rerun pass `--bin cargo-14033` $ cargo clean && cargo test -vvv
Removed 24 files, 6.1MiB total
Compiling cargo-14033 v0.1.0 (/home/epage/src/personal/dump/cargo-14033)
Running `CARGO=/home/epage/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/cargo CARGO_BIN_NAME=cargo-1403
3 CARGO_CRATE_NAME=cargo_14033 CARGO_MANIFEST_DIR=/home/epage/src/personal/dump/cargo-14033 CARGO_PKG_AUTHORS='' CARGO
_PKG_DESCRIPTION='' CARGO_PKG_HOMEPAGE='' CARGO_PKG_LICENSE='' CARGO_PKG_LICENSE_FILE='' CARGO_PKG_NAME=cargo-14033 CA
RGO_PKG_README='' CARGO_PKG_REPOSITORY='' CARGO_PKG_RUST_VERSION='' CARGO_PKG_VERSION=0.1.0 CARGO_PKG_VERSION_MAJOR=0
CARGO_PKG_VERSION_MINOR=1 CARGO_PKG_VERSION_PATCH=0 CARGO_PKG_VERSION_PRE='' CARGO_PRIMARY_PACKAGE=1 LD_LIBRARY_PATH='
/home/epage/src/personal/dump/cargo-14033/target/debug/deps:/home/epage/.rustup/toolchains/stable-x86_64-unknown-linux
-gnu/lib' /home/epage/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/rustc --crate-name cargo_14033 --edition=
2021 src/main.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=118
--emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 --test -C metadata=1ab2997d3cc74d9b -C extra-filename=-1ab2997
d3cc74d9b --out-dir /home/epage/src/personal/dump/cargo-14033/target/debug/deps -C incremental=/home/epage/src/persona
l/dump/cargo-14033/target/debug/incremental -L dependency=/home/epage/src/personal/dump/cargo-14033/target/debug/deps
-C opt-level=3`
Finished `test` profile [unoptimized + debuginfo] target(s) in 0.13s
Running `CARGO=/home/epage/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/cargo CARGO_MANIFEST_DIR=/home/
epage/src/personal/dump/cargo-14033 CARGO_PKG_AUTHORS='' CARGO_PKG_DESCRIPTION='' CARGO_PKG_HOMEPAGE='' CARGO_PKG_LICE
NSE='' CARGO_PKG_LICENSE_FILE='' CARGO_PKG_NAME=cargo-14033 CARGO_PKG_README='' CARGO_PKG_REPOSITORY='' CARGO_PKG_RUST
_VERSION='' CARGO_PKG_VERSION=0.1.0 CARGO_PKG_VERSION_MAJOR=0 CARGO_PKG_VERSION_MINOR=1 CARGO_PKG_VERSION_PATCH=0 CARG
O_PKG_VERSION_PRE='' LD_LIBRARY_PATH='/home/epage/src/personal/dump/cargo-14033/target/debug/deps:/home/epage/src/pers
onal/dump/cargo-14033/target/debug:/home/epage/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-u
nknown-linux-gnu/lib:/home/epage/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib' /home/epage/src/personal/dump
/cargo-14033/target/debug/deps/cargo_14033-1ab2997d3cc74d9b`
running 1 test
test debug_assert_false ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s The difference is The code for us setting that is: cargo/src/cargo/core/compiler/mod.rs Lines 1089 to 1108 in e52e0de
We seem to be going out of our way to rely on the default value
Not too sure why we are doing this (except to reduce noise?). However, RUSTFLAGS is considered a lower level mechanism that bypasses Cargo and can break Cargo's behavior, so I'm a bit unsure if this is something we'd deem need "fixing". |
Hi, thanks for the quick reply.
Given that changing I think that what bugged me the most here was not the behavior itself (the assertions being implicitly disabled) but rather the inconsistency between the two ways to set the But then again, if you say that RUSTFLAGS is considered a mechanism that can break stuff, I guess that should be expected. |
While we don't intend to use this as an excuse to break stuff, the expectation is documented:
There are other rustflags like |
Problem
As the title states, it looks like having
rustflags = ["-C", "opt-level=3"]
in yourconfig.toml
implicitly disables debug assertions, even when runningcargo test
, which should have them enabled by default.Some background:
I am currently working on a project where I had a
config.toml
looking something like this:My task was to create a lightweight profile without optimizations to enjoy faster compilation times. However, I had to ensure that tests were still compiled with
opt-level=3
because it heavily affected their total run time.So the first thing I did was create a
[profile.test]
entry and moveopt-level=3
fromrustflags
to it:Surprisingly, after moving it, I observed some tests failing on debug assertions. It took a while to figure out, but after some digging, I found out that the code was never compiled with debug assertions to begin with, even though
"-C debug-assertions=false"
was NOT part of therustflags
array.Since debug assertions should be enabled by default for tests, and since passing
opt-level=3
from a profile or fromrustflags
should be pretty much the same, this behavior seemed somewhat confusing to me.Please do let me know if I'm missing something.
Steps
cargo init
and editmain.rs
with:.cargo/config.toml
and edit with:cargo test
and observe the test passing..cargo/config.toml
with:cargo test
again and observe the test failing.Version
The text was updated successfully, but these errors were encountered: