Skip to content
Latchkey

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.

cargo
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 crate

Common 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

  1. Find the dependency pulling in std with cargo tree -e features.
  2. Disable its default features / enable its no_std (or alloc) feature.
  3. Ensure only one definition of each lang item remains.
Cargo.toml
# Cargo.toml
some-dep = { version = "1", default-features = false }

How to prevent it

  • Audit cargo tree -e features to confirm no dependency re-enables std.
  • Set default-features = false on deps in no_std crates.
  • Define lang items in exactly one place across the graph.

Frequently asked questions

What causes ""E0152: duplicate lang item""?
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.
How do I fix "E0152: duplicate lang item"?
Keep the whole graph no_std

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card