Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make ParseBuffer unwindsafe #1646

Merged
merged 2 commits into from May 11, 2024
Merged

Make ParseBuffer unwindsafe #1646

merged 2 commits into from May 11, 2024

Conversation

dtolnay
Copy link
Owner

@dtolnay dtolnay commented May 11, 2024

ParseBuffer contains interior mutability, but there isn't any way to get it into some invalid state by panicking in user code.

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`
@dtolnay dtolnay merged commit 55205b6 into master May 11, 2024
29 checks passed
@dtolnay dtolnay deleted the unwindsafe branch May 11, 2024 20:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant