Rust E0152 "found duplicate lang item" in CI
Two definitions of the same lang item (panic_impl, eh_personality, etc.) reached the build. A #![no_std] crate that also pulls in std -- or two crates both defining a lang item -- collide, and rustc rejects the duplicate.
What this error means
The build fails with error[E0152]: found duplicate lang item panic_impl``, naming both definitions. It is deterministic for the crate/feature configuration.
error[E0152]: found duplicate lang item `panic_impl`
|
= note: the lang item is first defined in crate `std`
= note: ...and is redefined in the current crateCommon causes
no_std crate also linking std
A #![no_std] crate that defines its own panic_impl/eh_personality ends up linked with std (via a dependency that pulls std in), so the lang item is defined twice.
Feature accidentally enabling std
A dependency feature turns std back on in a no_std build, dragging in std's lang items alongside the custom ones.
How to fix it
Keep the whole graph no_std
- Find the dependency pulling in std with
cargo tree -e features. - Disable its default features / enable its
no_std(oralloc) feature. - Ensure only one definition of each lang item remains.
# Cargo.toml
some-dep = { version = "1", default-features = false }How to prevent it
- Audit
cargo tree -e featuresto confirm no dependency re-enables std. - Set
default-features = falseon deps in no_std crates. - Define lang items in exactly one place across the graph.