Description
Hello!
Right now, I believe Rust Analyzer hard codes activating test
as a feature. This works well for writing tests, but has the unfortunate side effect that it's difficult to have any cfgs in the rest of a codebase, which should only be active during test
.
In my specific usecase, I'm working on an opengl application, and i'd like to make a "HeadlessContext". I use it like this:
#[cfg(test)]
type Gl = HeadlessContext;
#[cfg(not(test))]
type Gl = Context; // the real opengl
Right now, in the above program, Rust Analyzer will infer in all code (outside of test) that I am using HeadlessContext
, not Context
, which leads to false positive errors (and false negative non-errors).
I don't think the solution to this problem is really that easy though -- if RA simply allowed me to turn off test
as a condition, then writing Unit Tests would suddenly get much harder, since i would no longer have access to the RA in such a context. A bit hacky, but a solution where cfg(test) on modules is accepted, but cfg(test) on non-modules is not would fix this usecase, but seems very shaky and perhaps confusing to users.
Thank you for all the hard work on this excellent library! What do you think of the above?