Skip to content

Commit d6ced88

Browse files
bartlomiejuclaude
andcommitted
fix: recover scope lifetime in ValueView::new to satisfy nightly borrow checker
The nightly Rust compiler correctly rejects borrowing a by-value Local<'s, String> parameter since &*string creates a reference to the stack-local copy that is dropped at end of function. We recover the 's lifetime via pointer cast, which is safe because Local<'s, _> guarantees the V8 string is rooted in a HandleScope that lives for at least 's. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent fa63f51 commit d6ced88

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/string.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,8 +1137,11 @@ pub struct ValueView<'s>(
11371137
impl<'s> ValueView<'s> {
11381138
#[inline(always)]
11391139
pub fn new(isolate: &mut Isolate, string: Local<'s, String>) -> Self {
1140-
// SAFETY: Local<'s, String> derefs to &String; delegate to new_from_ref.
1141-
unsafe { Self::new_from_ref(isolate, &*string) }
1140+
// SAFETY: Local<'s, String> guarantees the V8 string is rooted in a
1141+
// HandleScope that lives for at least 's. Deref on Local erases the
1142+
// scope lifetime, so we recover it via pointer cast.
1143+
let string_ref: &'s String = unsafe { &*((&*string) as *const String) };
1144+
unsafe { Self::new_from_ref(isolate, string_ref) }
11421145
}
11431146

11441147
/// Constructs a `ValueView` from a raw string reference.

0 commit comments

Comments
 (0)