rust-lang / rust-lang/rust-analyzer

Disabling `cfg(test)` through VSCode settings triggers `--lib` to be added to `cargo check`/`cargo clippy` commands

Open
#20,551 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

This issue is reproducible quite easily (tested it with a stock vscode configuration, with only the RA extension):

  1. cargo new repro
  2. cd repro
  3. set .vscode/settings.json to
{
  "rust-analyzer.cfg.setTest": false
}
  1. you will get this error (or similar):
2025-08-27T20:07:25.089019+02:00 ERROR Flycheck failed to run the following command: CommandHandle { program: "/Users/olle/.cargo/bin/cargo", arguments: ["check", "--workspace", "--message-format=json-diagnostic-rendered-ansi", "--manifest-path", "/Users/olle/Dev/repro/Cargo.toml", "--keep-going", "--lib", "--bins", "--examples"], current_dir: Some("/Users/olle/Dev/repro") }, error=Cargo watcher failed, the command produced no valid metadata (exit code: ExitStatus(unix_wait_status(25856))):
error: no library targets found in package `repro`

rust-analyzer version: (eg. output of "rust-analyzer: Show RA Version" command, accessible in VSCode via Ctrl/⌘+Shift+P)
rust-analyzer version: 0.3.2593-standalone (6b2e677795 2025-08-25)
rustc version: (eg. output of rustc -V)
rustc 1.91.0-nightly (160e7623e 2025-08-26
editor or extension: (eg. VSCode, Vim, Emacs, etc. For VSCode users, specify your extension version; for users of other editors, provide the distribution if applicable)
VSCode 0.3.2593

relevant settings: (eg. client settings, or environment variables like CARGO, RUSTC, RUSTUP_HOME or CARGO_HOME)

Issue happens with this settings.json:

{
"rust-analyzer.cfg.setTest": false
}

repository link (if public, optional): (eg. rust-analyzer)
Not applicable
code snippet to reproduce:

// no code needed, issue stops cargo check from running

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

Reproduce the issue with a stock VSCode setup, a cargo new repro package, and .vscode/settings.json setting rust-analyzer.cfg.setTest to false. Start by tracing how rust-analyzer constructs cargo check and cargo clippy commands for flycheck. Done means packages without library targets no longer receive --lib, and the commands complete successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust, vscode
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.