diff --git a/tests/compile_fail/boxed_local.rs b/tests/compile_fail/boxed_local.rs new file mode 100644 index 00000000..2e9e36f2 --- /dev/null +++ b/tests/compile_fail/boxed_local.rs @@ -0,0 +1,18 @@ +// Copyright 2019-2020 the Deno authors. All rights reserved. MIT license. +use rusty_v8 as v8; + +pub fn main() { + let mut isolate = v8::Isolate::new(mock()); + let mut root_hs = v8::HandleScope::new(&mut isolate); + let root_hs = root_hs.enter(); + + let _boxed = { + let mut hs = v8::HandleScope::new(root_hs); + let hs = hs.enter(); + Box::new(v8::Integer::new(hs, 123)) + }; +} + +fn mock() -> T { + unimplemented!() +} diff --git a/tests/compile_fail/boxed_local.stderr b/tests/compile_fail/boxed_local.stderr new file mode 100644 index 00000000..7b0795d7 --- /dev/null +++ b/tests/compile_fail/boxed_local.stderr @@ -0,0 +1,11 @@ +error[E0597]: `hs` does not live long enough + --> $DIR/boxed_local.rs:11:14 + | +9 | let _boxed = { + | ------ borrow later stored here +10 | let mut hs = v8::HandleScope::new(root_hs); +11 | let hs = hs.enter(); + | ^^ borrowed value does not live long enough +12 | Box::new(v8::Integer::new(hs, 123)) +13 | }; + | - `hs` dropped here while still borrowed diff --git a/tests/test_ui.rs b/tests/test_ui.rs index f3c838ce..9b7ec2ba 100644 --- a/tests/test_ui.rs +++ b/tests/test_ui.rs @@ -8,6 +8,7 @@ fn ui() { env::set_var("DENO_TRYBUILD", "1"); let t = trybuild::TestCases::new(); + t.compile_fail("tests/compile_fail/boxed_local.rs"); t.compile_fail("tests/compile_fail/handle_scope_escape_lifetime.rs"); t.compile_fail("tests/compile_fail/handle_scope_lifetimes.rs"); t.compile_fail("tests/compile_fail/try_catch_lifetimes.rs");