From 2f6cf73d5109cbccc4dcbd9ccfc03fb4d4b85bfc Mon Sep 17 00:00:00 2001 From: overlookmotel Date: Fri, 9 Feb 2024 12:55:12 +0000 Subject: [PATCH] fix(parser): remove erroneous debug assertion (#2356) This was a bit of a whoopsie in last batch of PRs. This assertion shouldn't be there, because all reads are now via `source.position().read()`, so this assertion says "you can only read some byte values". Only reason it didn't blow up conformance tests is that they run in release mode. Sorry. Please merge soon as you can and cover my shame! --- crates/oxc_parser/src/lexer/source.rs | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/crates/oxc_parser/src/lexer/source.rs b/crates/oxc_parser/src/lexer/source.rs index fe1b2c9dd..5beb3ab0c 100644 --- a/crates/oxc_parser/src/lexer/source.rs +++ b/crates/oxc_parser/src/lexer/source.rs @@ -162,22 +162,7 @@ impl<'a> Source<'a> { pub(super) fn position(&self) -> SourcePosition<'a> { // SAFETY: Creating a `SourcePosition` from current position of `Source` is always valid, // if caller has upheld safety conditions of other unsafe methods of this type. - let pos = unsafe { SourcePosition::new(self.ptr) }; - - // SAFETY: `pos.read()`'s contract is upheld by: - // * The preceding checks that `pos.ptr` >= `self.start` and < `self.end`. - // * `Source`'s invariants guarantee that `self.start` - `self.end` contains allocated memory. - // * `Source::new` takes an immutable ref `&str`, guaranteeing that the memory `pos.ptr` - // addresses cannot be aliased by a `&mut` ref as long as `Source` exists. - // * `SourcePosition` can only live as long as the `&str` underlying `Source`. - debug_assert!( - pos.ptr >= self.start - && pos.ptr <= self.end - // SAFETY: See above - && (pos.ptr == self.end || !is_utf8_cont_byte(unsafe { pos.read() })) - ); - - pos + unsafe { SourcePosition::new(self.ptr) } } /// Move current position.