Open lcnr opened 1 year ago
could also be a clippy lint :upside_down_face:
i feel like i encounter this often enough that having it in rustc itself would be nice. That lint should be part of the unused
category, similar to the lint for unused braces.
clippy's needless_borrow
lint already does this, at least partially, e.g. https://github.com/rust-lang/rust-clippy/issues/9049 .
Generally the "this code can use new feature X" lints are included in clippy. Note that there is code out there that has really old MSRV requirements. clippy has a mechanism to handle such MSRV requirements, including cargo integration, but rustc lacks the ability to turn on lints based on MSRV support.
See also the thread of https://github.com/rust-lang/rust/pull/87512 and why it was rejected.
Note that I'm not saying that rustc should never get such lints, ever. It's just a problem that should be addressed before such a lint is added.
For example the MSRV problem could be solved by turning on lints based on the edition. So it could enable version based lints only on editions where the first rustc version of the edition already had the feature the lint is suggesting. There are mechanisms for editions already, and editions also influence how rust code should be written. clippy defaults to MSRV == latest, which is obviously way too aggressive.
Generally the "this code can use new feature X" lints are included in clippy. Note that there is code out there that has really old MSRV requirements. clippy has a mechanism to handle such MSRV requirements, including cargo integration, but rustc lacks the ability to turn on lints based on MSRV support.
My proposed lint is not a "this code can use new feature X", it is "this code either does not compile or is redundant" afaik.
If you have match ergonomics together with ref, then the code just didn't compile before match ergonomics were stable because you were missing some explicit &
somewhere: https://rust.godbolt.org/z/7q67hqbna
@rustbot claim
@rustbot release-assignment
because of match ergonomics, every binding inside of
Some
is already matched byref
implicitly, so the additional explicitref
is completely redundant. Consider the following example wherel
andr
have the exact same type.This lint should either suggest to disable match ergonomics by adding
&
and&mut
patterns in the relevant places or to remove theref
.There are a lot of places even inside of rustc which hit this pattern, so this lint feels really desirable to me.