External Publication
Visit Post

Pre-feature request: suppress unused variable warning for unit-type arguments

Rust Internals [Unofficial] March 11, 2026
Source

RalfJung:

I don't see noise here.

Warnings should be precise is a general statement about warnings. If the compiler can be taught a special case for a warning that eliminates a whole class of false positives then (other factors aside) it should be taught that special case. Ideally when I see a warning I am expecting an issue with my code, not expecting to allow it.

The case in the OP is noise : the warning needs to be allow'd or otherwise disabled. I don't think there is an easy way for the compiler to be taught that some ZST's are tokens and some are ignorable. Perhaps an annotation on the struct, but then I wonder: if the code were then changed to add a parameter to that empty struct, I would probably remove the annotation and trigger the warning everywhere (and then either use my new parameter or silence it with let _ =). So having N places where the warning is disabled (via prefix _) doesn't seem that big a deal.

Discussion in the ATmosphere

Loading comments...