mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 12:19:15 +00:00
fix(syntax): correctly check for valid RedeclarationIds (#5759)
Previously we truncated `usize` to `u32` and *then* checked validity of the `u32`. Fix that by checking validity *before* truncating.
This commit is contained in:
parent
8ff013ada1
commit
042afa9fd6
1 changed files with 3 additions and 1 deletions
|
|
@ -36,7 +36,9 @@ pub struct RedeclarationId(NonMaxU32);
|
|||
impl Idx for RedeclarationId {
|
||||
#[allow(clippy::cast_possible_truncation)]
|
||||
fn from_usize(idx: usize) -> Self {
|
||||
Self(NonMaxU32::new(idx as u32).unwrap())
|
||||
assert!(idx < u32::MAX as usize);
|
||||
// SAFETY: We just checked `idx` is valid for `NonMaxU32`
|
||||
Self(unsafe { NonMaxU32::new_unchecked(idx as u32) })
|
||||
}
|
||||
|
||||
fn index(self) -> usize {
|
||||
|
|
|
|||
Loading…
Reference in a new issue