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": {
    "histogram_readback"
},

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.

1 Like

Did you try using an empty string as the value?

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

2 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.