VSCode editor with rust analyzer and conditional compilation

The rust analyzer has a wonderful feature for the VSCode editor when using conditional compilation; it shows code that won't be included in the compilation fainter than code that will be included.

I'd like to change the features so that different blocks of code are fainter, but I can't figure out what to change. I tried changing rust-analyzer.cargo.features in my settings.json, but that resulted in no code being fainter. I assume that's because the change conflicts with another setting.

My current rust analyzer settings are

    "rust-analyzer.cargo.features": ["bar"],
    "rust.actionOnSave": "check",
    "rust-analyzer.checkOnSave.command": "cargo check",
    "rust-analyzer.checkOnSave.features": ["bar"],
    "rust-analyzer.checkOnSave.enable": true,
    "rust-analyzer.checkOnSave.allTargets": false,
    "rust-analyzer.checkOnSave.target": "foo",
    "rust-analyzer.checkOnSave.overrideCommand": [
        "--bin", "foo", 
        "--features", "bar",

I'd like the editor to show me the code when features=qux.

1 Like
  1. do you have code that is conditionally compiled (gated on the qux feature)?
  2. have you tried with "rust-analyzer.cargo.features": ["qux"]?
1 Like

I do, and I did. Apparently, one of the recent releases of the rust analyzer fixed the problem.