Closed
Description
If you combine LTO, anything that uses alloc and debug compilation mode, the compiler fails.
The minimum example to reproduce is this src/lib.rs
:
extern crate alloc;
#[cfg(test)]
mod tests {
#[test]
fn something_alloc() {
assert_eq!(Vec::<u32>::new(), Vec::<u32>::new());
}
}
With this Cargo.toml
:
[package]
name = "lto_bug"
version = "0.0.1"
edition = "2018"
[profile.dev]
lto = true
[profile.release]
lto = true
To reproduce, run (or just use +nightly
):
cargo +nightly-2023-03-26 test
You should see this error:
error: Cannot represent a difference across sections
The above error does not reproduce for other compiler versions or options, all of the below work:
cargo +nightly test --release
cargo +nightly-2023-03-25 test
cargo +stable test
I found #109730 reporting something similar, but for them --release
is throwing the error, so I opened a new issue instead.