Easily switch between hiding and showing unused_code warnings?


#[allow(unused)] works for a single function but…

Is there a way to enable this for all of a single project inline to the code itself (without env variables)?

Specifically I’m using VSCode with RLS support which uses rustc to check for errors(for which I can’t easily change environment variables) and when first prototyping dead code warnings can be both pervasive and can hide actual bugs, but when I’m ready to clean up the dead wood I want to be able to switch out by just deleting one or two lines of code


Attributes can also be written like #![allow(unused)] to affect their outer scope, rather than the following item. You can use this at the top of your crate to disable the warning for the whole crate.


That works, thanks!

I’m now looking for a way to do the same with RUST_BACKTRACE=1, are these documented anywhere? I’ve done some searches but google doesn’t seem to index the characters #![]


I’m not aware of any attribute for RUST_BACKTRACE, only the environment variable. Have you checked if VSCode has a setting for this?


I haven’t looked deep into it yet. I just keep seeing mentions on various rust forums that seem to indicate there’s some way to set environment variables with something in #[] or #![] and wondered if I was interpreting this correctly, sounds like maybe not