Why can't I get warnings to show up without a clean?


#1

I haven’t used Rust in a while and am now coming back to it. One thing that I"m noticing that I feel like wasn’t there before is that warnings are now only shown one time, and not shown again until that unit has to be recompiled.

For example, if I make a code change and cargo test I’ll see a warning. If I then close my terminal, open a new one and cargo test again I will no longer see the warning and have no idea what/if any occurred.

I have also experienced this with compile errors (though I can’t reproduce this at the moment) where a cargo run would run the old build of the application and not show me compile errors a 2nd time unless I manually run cargo clean && cargo build.

This is actually getting really frustrating, especially since in the IntelliJ app cargo test hides the console output for the nice test runner, which means it’s impossible for me to see my warnings without a cargo clean.

What’s the deal with this?


#2

This sounds like an artifact of incremental compilation; if the code compiles (with only warnings, no errors) then it won’t need to be recompiled unless something has changed, and thus the warnings won’t be repeated.

It should not happen for anything with errors that prevent a successful compilation, though. If you do manage to reproduce that, it’s a bug.

For IDE integration, the RLS will publish these warnings and update them as the code is changed.


#3

To produce warnings, the compile has to compile your code. If the build is fresh, the code isn’t recompiled; it’s already been built.


#4

#5

Sure but maybe there’s value in Cargo caching the warnings so they can be replayed if compile of that module is skipped? Surely I’m not the only one, and it looks like from the StackOverflow question that people are jumping through hoops to get this functionality.


#6

Could it be that clippy experiences the same issue? This would explain why warnings sometimes disappear.


#7

Yes.

And all of this is, why I often use #[deny(warning)] for test. Have to look up the exact syntax every time :wink: But I think you getr what I mean.