mirror of
https://github.com/astral-sh/ruff.git
synced 2025-12-15 22:14:44 +00:00
Add unreachable code rule (#5384)
Co-authored-by: Thomas de Zeeuw <thomas@astral.sh> Co-authored-by: Micha Reiser <micha@reiser.io>
This commit is contained in:
parent
937de121f3
commit
0b963ddcfa
30 changed files with 4688 additions and 4 deletions
|
|
@ -36,10 +36,11 @@ pub(super) fn generate_newtype_index(item: ItemStruct) -> syn::Result<proc_macro
|
|||
#vis #struct_token #ident(std::num::NonZeroU32)#semi_token
|
||||
|
||||
impl #ident {
|
||||
const MAX: u32 = u32::MAX - 1;
|
||||
const MAX_VALUE: u32 = u32::MAX - 1;
|
||||
const MAX: Self = Self::from_u32(Self::MAX_VALUE);
|
||||
|
||||
#vis const fn from_usize(value: usize) -> Self {
|
||||
assert!(value <= Self::MAX as usize);
|
||||
assert!(value <= Self::MAX_VALUE as usize);
|
||||
|
||||
// SAFETY:
|
||||
// * The `value < u32::MAX` guarantees that the add doesn't overflow.
|
||||
|
|
@ -49,7 +50,7 @@ pub(super) fn generate_newtype_index(item: ItemStruct) -> syn::Result<proc_macro
|
|||
}
|
||||
|
||||
#vis const fn from_u32(value: u32) -> Self {
|
||||
assert!(value <= Self::MAX);
|
||||
assert!(value <= Self::MAX_VALUE);
|
||||
|
||||
// SAFETY:
|
||||
// * The `value < u32::MAX` guarantees that the add doesn't overflow.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue