Allow int literals for pattern types with int base types by oli-obk · Pull Request #137715 · rust-lang/rust (original) (raw)

r? @BoxyUwU

I also added an error at layout computation time for layouts that contain wrapping ranges (happens at monomorphization time). This is obviously hacky, but at least prevents such types from making it to codegen for now. It made writing the tests for int literals easier as I didn't have to think about that edge case

Basically this PR allows you to stop using transmutes for creating pattern types and instead just use literals:

let x: pattern_type!(u32 is 5..10) = 7;

works, and if the literal is out of range you get a type mismatch because it just stays at the base type and the base type can't be coerced to the pattern type.

cc @joshtriplett @scottmcm