Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions crates/oxc_parser/src/lexer/token.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Token

use std::mem;

use oxc_span::Span;

use super::kind::Kind;
Expand Down Expand Up @@ -55,9 +57,10 @@ impl Token {

#[inline]
pub fn kind(&self) -> Kind {
// SAFETY: This conversion is safe because `Kind` is `#[repr(u8)]`,
// and we ensure the value stored is a valid `Kind` variant
unsafe { std::mem::transmute(((self.0 >> KIND_SHIFT) & KIND_MASK) as u8) }
// SAFETY: `Kind` is `#[repr(u8)]`. Only `Token::set_kind` alters these bits,
// and it sets them to the `u8` value of an existing `Kind`.
// So transmuting these bits back to `Kind` must produce a valid `Kind`.
unsafe { mem::transmute::<u8, Kind>(((self.0 >> KIND_SHIFT) & KIND_MASK) as u8) }
}

#[inline]
Expand Down
Loading