Exhaustively handle expressions in patterns by oli-obk · Pull Request #134228 · rust-lang/rust (original) (raw)

We currently have this invariant in HIR that a PatKind::Lit or a PatKind::Range only contains

So I made PatKind::Lit and PatKind::Range stop containing Expr, and instead created a PatLit type whose kind enum only contains those variants.

The only place code got more complicated was in clippy, as it couldn't share as much anymore with Expr handling

It may be interesting on merging ExprKind::{Path,Lit,ConstBlock} in the future and using the same PatLit type (under a new name).

Then it should also be easier to eliminate any and all UnOp(Neg, Lit) | Lit matching that we have across the compiler. Some day we should fold the negation into the literal itself and just store it on the numeric literals