VSCode: limit std suggestions outside tests when #![no_std]
is conditional on #[cfg(test)]
#12035
Labels
A-assists
C-bug
Category: bug
S-actionable
Someone could pick this issue up and work on it right now
When writing
#![no_std]
libraries, it is often useful to disable this for test code (the library itself is fully no_std, but allowing e.g.Vec
to be easily used makes testing easier and clearer). This is done using a "conditional no_std" attribute (e.g.#![cfg_attr(not(test), no_std)]
)Rust Analyzer currently doesn't handle this particularly well as it globally enables std imports and suggestions, not just inside test code
Example with conditional

#![no_std]
. Imports are from std even though this location isno_std
Example with unconditional

#![no_std]
. Imports are now from core / alloc (would be nice if outside test code the conditional version matched this)Str
isn't exactly text I'm normally getting suggestions for when writing forno_std
so this was a bit of a surprise tooPS Ignore the poorly chosen struct name, this is not inside
#[cfg(test)]
The text was updated successfully, but these errors were encountered: