Skip to content

VSCode: limit std suggestions outside tests when #![no_std] is conditional on #[cfg(test)] #12035

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Crzyrndm opened this issue Apr 19, 2022 · 0 comments · Fixed by #12041
Closed
Labels
A-assists C-bug Category: bug S-actionable Someone could pick this issue up and work on it right now

Comments

@Crzyrndm
Copy link

Crzyrndm commented Apr 19, 2022

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 is no_std
image

Example with unconditional #![no_std]. Imports are now from core / alloc (would be nice if outside test code the conditional version matched this)
image

  • I was expecting this to remove all std suggestions? Str isn't exactly text I'm normally getting suggestions for when writing for no_std so this was a bit of a surprise too

PS Ignore the poorly chosen struct name, this is not inside #[cfg(test)]

@lnicola lnicola added S-actionable Someone could pick this issue up and work on it right now A-assists C-bug Category: bug labels Apr 20, 2022
@bors bors closed this as completed in 3bda70a Apr 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-assists C-bug Category: bug S-actionable Someone could pick this issue up and work on it right now
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants