rust-lang / rust-lang/rust-analyzer

How to set features for different crates in a workspace?

Open
#15,988 2 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-support
Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

I have a workspace with 2 crates.

  1. A library that has various features like std which I can turn off for no_std, and also by default a rand feature that includes the rand crate.
  2. A WASM binary that targets wasm32-unknown-unknown. This depends on crate 1 with default-features = false (to allow no_std)

The WASM binary replaces the #[panic_handler] and cargo check and cargo build throw no errors.

However, rust-analyzer gives me an error on the panic handler:

found duplicate lang item `panic_impl`
the lang item is first defined in crate `std` (which `test` depends on)
first definition in `std` loaded from /home/jonathan/.rustup/toolchains/1.74.0-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/libstd-3354d2cb1f357486.rlib
second definition in the local crate

Here's the repo: https://github.com/bitcoinjs/tiny-secp256k1/tree/wip/modular (note: the wip/modular branch)
(I've committed the .cargo folder and .vscode folder)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Check out the linked wip/modular branch and inspect its .cargo and .vscode configuration alongside the two-crate workspace. First compare rust-analyzer's duplicate panic_impl diagnostic with the successful cargo check and cargo build results for wasm32-unknown-unknown. Done means rust-analyzer resolves the workspace features consistently and no longer reports the false duplicate panic handler.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.