Open
Description
What it does
It suggests to replace a coding pattern that isn't DRY enough when there's a cast in a const definition. This is a spinoff of issue #15163 .
Advantage
Less types to read, less code to change if needed, code more DRY.
Drawbacks
I can't think of any drawback. But perhaps there are some.
Example
In the wild (Linux) I've seen Rust code like this:
const BMCR_SPEED100: u16 = uapi::BMCR_SPEED100 as u16;
This is similar but simplified code:
#![warn(clippy::all)]
#![warn(clippy::nursery)]
#![warn(clippy::pedantic)]
fn main() {
const M: usize = 100;
const N: u16 = M as u16;
}
I think a new Clippy lint could suggest instead:
const N: u16 = M as _;