-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
93 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 37 additions & 26 deletions
63
core/tests/async_compile_fail/async_nested_contexts.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,39 @@ | ||
error[E0521]: borrowed data escapes outside of closure | ||
--> tests/async_compile_fail/async_nested_contexts.rs:9:38 | ||
error[E0277]: `NonNull<JSContext>` cannot be shared between threads safely | ||
--> tests/async_compile_fail/async_nested_contexts.rs:8:9 | ||
| | ||
7 | / async_with!(ctx_1 => |ctx_1|{ | ||
8 | |/ async_with!(ctx_2 => |ctx_2|{ | ||
9 | || ctx_1.globals().set("t", ctx_2.globals()); | ||
| || ^^^^^^^^^^^^^^^ `ctx_2` escapes the closure body here | ||
10 | || }).await | ||
| ||__________- `ctx_2` is a reference that is only valid in the closure body | ||
11 | | }) | ||
| |_______- `ctx_1` declared here, outside of the closure body | ||
|
||
error[E0521]: borrowed data escapes outside of closure | ||
--> tests/async_compile_fail/async_nested_contexts.rs:9:13 | ||
8 | / async_with!(ctx_2 => |ctx_2|{ | ||
9 | | // It is disallowed to use multiple ctx object together from different with closures. | ||
10 | | // Lifetime on ctx should be unique. | ||
11 | | ctx_1.globals().set("t", ctx_2.globals()); | ||
12 | | }).await | ||
| | ^ | ||
| | | | ||
| |__________`NonNull<JSContext>` cannot be shared between threads safely | ||
| required by a bound introduced by this call | ||
| | ||
7 | / async_with!(ctx_1 => |ctx_1|{ | ||
8 | | async_with!(ctx_2 => |ctx_2|{ | ||
9 | | ctx_1.globals().set("t", ctx_2.globals()); | ||
| | ^^^^^^^^^^^^^^^ | ||
| | | | ||
| | `ctx_1` escapes the closure body here | ||
| | argument requires that `'1` must outlive `'static` | ||
10 | | }).await | ||
11 | | }) | ||
| | - | ||
| | | | ||
| |______`ctx_1` is a reference that is only valid in the closure body | ||
| has type `Ctx<'1>` | ||
= help: within `Ctx<'_>`, the trait `Sync` is not implemented for `NonNull<JSContext>` | ||
note: required because it appears within the type `Ctx<'_>` | ||
--> src/context/ctx.rs | ||
| | ||
| pub struct Ctx<'js> { | ||
| ^^^ | ||
= note: required for `&Ctx<'_>` to implement `Send` | ||
note: required because it's used within this closure | ||
--> tests/async_compile_fail/async_nested_contexts.rs:8:9 | ||
| | ||
8 | / async_with!(ctx_2 => |ctx_2|{ | ||
9 | | // It is disallowed to use multiple ctx object together from different with closures. | ||
10 | | // Lifetime on ctx should be unique. | ||
11 | | ctx_1.globals().set("t", ctx_2.globals()); | ||
12 | | }).await | ||
| |__________^ | ||
= note: required for `[closure@$DIR/src/context/async.rs:106:52: 106:58]` to implement `ParallelSend` | ||
note: required by a bound in `AsyncContext::async_with` | ||
--> src/context/async.rs | ||
| | ||
| pub async fn async_with<'a, F, R: 'a>(&'a self, f: F) -> R | ||
| ---------- required by a bound in this associated function | ||
... | ||
| + ParallelSend, | ||
| ^^^^^^^^^^^^ required by this bound in `AsyncContext::async_with` | ||
= note: this error originates in the macro `async_with` (in Nightly builds, run with -Z macro-backtrace for more info) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
use std::rc::Rc; | ||
|
||
use rquickjs::{async_with, AsyncContext, AsyncRuntime}; | ||
|
||
pub async fn test() { | ||
let rt = AsyncRuntime::new().unwrap(); | ||
let ctx = AsyncContext::full(&rt).await.unwrap(); | ||
|
||
let fut = { | ||
let mut var = Rc::new(1); | ||
let var_c = var.clone(); | ||
async_with!(ctx => |_ctx|{ | ||
// you should not be able to move non send types into the closure. | ||
assert_eq!(*var_c,1); | ||
}) | ||
}; | ||
fut.await; | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
error[E0277]: `Rc<i32>` cannot be sent between threads safely | ||
--> tests/async_parallel_compile_fail/capture_rc.rs:12:9 | ||
| | ||
12 | / async_with!(ctx => |_ctx|{ | ||
13 | | // you should not be able to move non send types into the closure. | ||
14 | | assert_eq!(*var_c,1); | ||
15 | | }) | ||
| | ^ | ||
| | | | ||
| | `Rc<i32>` cannot be sent between threads safely | ||
| |__________within this `[closure@$DIR/src/context/async.rs:106:52: 106:58]` | ||
| required by a bound introduced by this call | ||
| | ||
= help: within `[closure@$DIR/src/context/async.rs:106:52: 106:58]`, the trait `Send` is not implemented for `Rc<i32>` | ||
note: required because it's used within this closure | ||
--> tests/async_parallel_compile_fail/capture_rc.rs:12:9 | ||
| | ||
12 | / async_with!(ctx => |_ctx|{ | ||
13 | | // you should not be able to move non send types into the closure. | ||
14 | | assert_eq!(*var_c,1); | ||
15 | | }) | ||
| |__________^ | ||
= note: required for `[closure@$DIR/src/context/async.rs:106:52: 106:58]` to implement `ParallelSend` | ||
note: required by a bound in `AsyncContext::async_with` | ||
--> src/context/async.rs | ||
| | ||
| pub async fn async_with<'a, F, R: 'a>(&'a self, f: F) -> R | ||
| ---------- required by a bound in this associated function | ||
... | ||
| + ParallelSend, | ||
| ^^^^^^^^^^^^ required by this bound in `AsyncContext::async_with` | ||
= note: this error originates in the macro `async_with` (in Nightly builds, run with -Z macro-backtrace for more info) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters