Skip to content

Commit

Permalink
Add test of ParseStream in catch_unwind
Browse files Browse the repository at this point in the history
Currently fails to build:

    error[E0277]: the type `UnsafeCell<syn::buffer::Cursor<'static>>` may contain interior mutability and a reference may not be safely transferrable across a catch_unwind boundary
       --> tests/test_parse_buffer.rs:98:49
        |
    98  |         let thread_result = panic::catch_unwind(|| input.parse());
        |                             ------------------- ^^^^^^^^^^^^^^^^ `UnsafeCell<syn::buffer::Cursor<'static>>` may contain interior mutability and a reference may not be safely transferrable across a catch_unwind boundary
        |                             |
        |                             required by a bound introduced by this call
        |
        = help: within `ParseBuffer<'_>`, the trait `RefUnwindSafe` is not implemented for `UnsafeCell<syn::buffer::Cursor<'static>>`, which is required by `{closure@tests/test_parse_buffer.rs:98:49: 98:51}: UnwindSafe`
    note: required because it appears within the type `Cell<syn::buffer::Cursor<'static>>`
       --> $RUST/library/core/src/cell.rs:293:12
        |
    293 | pub struct Cell<T: ?Sized> {
        |            ^^^^
    note: required because it appears within the type `ParseBuffer<'_>`
       --> src/parse.rs:245:12
        |
    245 | pub struct ParseBuffer<'a> {
        |            ^^^^^^^^^^^
        = note: required for `&ParseBuffer<'_>` to implement `UnwindSafe`
    note: required because it's used within this closure
       --> tests/test_parse_buffer.rs:98:49
        |
    98  |         let thread_result = panic::catch_unwind(|| input.parse());
        |                                                 ^^
    note: required by a bound in `std::panic::catch_unwind`
       --> $RUST/library/std/src/panic.rs:148:40
        |
    148 | pub fn catch_unwind<F: FnOnce() -> R + UnwindSafe, R>(f: F) -> Result<R> {
        |                                        ^^^^^^^^^^ required by this bound in `catch_unwind`

    error[E0277]: the type `UnsafeCell<Option<Rc<Cell<parse::Unexpected>>>>` may contain interior mutability and a reference may not be safely transferrable across a catch_unwind boundary
       --> tests/test_parse_buffer.rs:98:49
        |
    98  |         let thread_result = panic::catch_unwind(|| input.parse());
        |                             ------------------- ^^^^^^^^^^^^^^^^ `UnsafeCell<Option<Rc<Cell<parse::Unexpected>>>>` may contain interior mutability and a reference may not be safely transferrable across a catch_unwind boundary
        |                             |
        |                             required by a bound introduced by this call
        |
        = help: within `ParseBuffer<'_>`, the trait `RefUnwindSafe` is not implemented for `UnsafeCell<Option<Rc<Cell<parse::Unexpected>>>>`, which is required by `{closure@tests/test_parse_buffer.rs:98:49: 98:51}: UnwindSafe`
    note: required because it appears within the type `Cell<Option<Rc<Cell<parse::Unexpected>>>>`
       --> $RUST/library/core/src/cell.rs:293:12
        |
    293 | pub struct Cell<T: ?Sized> {
        |            ^^^^
    note: required because it appears within the type `ParseBuffer<'_>`
       --> src/parse.rs:245:12
        |
    245 | pub struct ParseBuffer<'a> {
        |            ^^^^^^^^^^^
        = note: required for `&ParseBuffer<'_>` to implement `UnwindSafe`
    note: required because it's used within this closure
       --> tests/test_parse_buffer.rs:98:49
        |
    98  |         let thread_result = panic::catch_unwind(|| input.parse());
        |                                                 ^^
    note: required by a bound in `std::panic::catch_unwind`
       --> $RUST/library/std/src/panic.rs:148:40
        |
    148 | pub fn catch_unwind<F: FnOnce() -> R + UnwindSafe, R>(f: F) -> Result<R> {
        |                                        ^^^^^^^^^^ required by this bound in `catch_unwind`
  • Loading branch information
dtolnay committed May 11, 2024
1 parent 8bcd277 commit d29bf8e
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion tests/test_parse_buffer.rs
@@ -1,6 +1,7 @@
#![allow(clippy::non_ascii_literal)]

use proc_macro2::{Delimiter, Group, Punct, Spacing, TokenStream, TokenTree};
use proc_macro2::{Delimiter, Group, Ident, Punct, Spacing, TokenStream, TokenTree};
use std::panic;
use syn::parse::discouraged::Speculative as _;
use syn::parse::{Parse, ParseStream, Parser, Result};
use syn::{parenthesized, Token};
Expand Down Expand Up @@ -90,3 +91,13 @@ fn trailing_empty_none_group() {

parse.parse2(tokens).unwrap();
}

#[test]
fn test_unwind_safe() {
fn parse(input: ParseStream) -> Result<Ident> {
let thread_result = panic::catch_unwind(|| input.parse());
thread_result.unwrap()
}

parse.parse_str("throw").unwrap();
}

0 comments on commit d29bf8e

Please sign in to comment.