How to enable CFGs in rust-analyzer?

Hi. I want to set a cfg in VSCode so RA will check code under a cfg check. The cfg is histogram_readback . I see in the user manual for rust-analyzer User Manual there is rust-analyzer.cargo.cfgs which can be set to turn specific CFGs on or off. I have found that in my settings.json file.

The problem is that "rust-analyzer.cargo.cfgs" takes a JSON object, and I have no idea what the format is supposed to be.

"rust-analyzer.cargo.cfgs": {

doesn't work as you can't have a key without a value in JSON.

"rust-analyzer.cargo.cfgs": {
    "histogram_readback": true

doesn't work either.

Did you try using an empty string as the value?

You could also use RUSTFLAGS to set the cfg if that doesn't work

1 Like