Skip to content

Combination of panic="abort" and -Zbuild-std causes build failure #144840

@AngelicosPhosphoros

Description

@AngelicosPhosphoros

I have tried this on ubuntu and alpine docker containers.

Steps:

  1. Install dependencies
    ubuntu: apt update && apt install curl clang
    alpine: apk add curl clang musl-dev

  2. Try to build project:

curl --proto '=https' --tlsv1.3 -sSf https://sh.rustup.rs | sh
export PATH="$HOME/.cargo/bin:$PATH"
rustup override set nightly
rustup component add rust-src
cargo new test_build_std --vcs none
cd test_build_std
echo '[profile.release]' >> Cargo.toml
echo 'panic = "abort"' >> Cargo.toml
cargo build --release -Zbuild-std

I expected to see this happen: project successfully compiles

Instead, this happened: build failed with the following error

Alpine:

error[E0152]: duplicate lang item in crate `core`: `sized`
  |
  = note: the lang item is first defined in crate `core` (which `std` depends on)
  = note: first definition in `core` loaded from /test_build_std/target/x86_64-unknown-linux-musl/release/deps/libcore-ea86b8bdb00db001.rlib, /test_build_std/target/x86_64-unknown-linux-musl/release/deps/libcore-ea86b8bdb00db001.rmeta
  = note: second definition in `core` loaded from /root/.rustup/toolchains/nightly-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libcore-8c023576fd012662.rlib

For more information about this error, try `rustc --explain E0152`.
error: could not compile `test_build_std` (bin "test_build_std") due to 1 previous error

Ubuntu:

error[E0152]: duplicate lang item in crate `core`: `sized`
  |
  = note: the lang item is first defined in crate `core` (which `std` depends on)
  = note: first definition in `core` loaded from /test_build_std/target/release/deps/libcore-521f42810889a0fe.rlib, /test_build_std/target/release/deps/libcore-521f42810889a0fe.rmeta
  = note: second definition in `core` loaded from /root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-62c8dfa7db58d93c.rlib

For more information about this error, try `rustc --explain E0152`.
error: could not compile `test_build_std` (bin "test_build_std") due to 1 previous error

Meta

rustc --version --verbose:

rustc 1.90.0-nightly (4b55fe199 2025-08-01)
binary: rustc
commit-hash: 4b55fe199cfe9c710555a5af7f2a49491ad38254
commit-date: 2025-08-01
host: x86_64-unknown-linux-gnu
release: 1.90.0-nightly
LLVM version: 20.1.8

rustc 1.90.0-nightly (4b55fe199 2025-08-01)
binary: rustc
commit-hash: 4b55fe199cfe9c710555a5af7f2a49491ad38254
commit-date: 2025-08-01
host: x86_64-unknown-linux-musl
release: 1.90.0-nightly
LLVM version: 20.1.8

As I understand, the main problem is panic="abort", if I don't use that, build finishes successfully.

Metadata

Metadata

Assignees

No one assigned

    Labels

    -Zbuild-stdUnstable Cargo option: Compile the standard library yourself.A-panicArea: Panicking machineryC-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions