Skip to content

RegexSet references cannot be passed across unwind boundaries #576

Closed
@bdonlan

Description

@bdonlan

The following minimal test case fails on regex 1.1.6:

fn main() {
    let rs = regex::RegexSet::new(vec![""]).unwrap();
    let rrs = &rs;
    std::panic::catch_unwind(move || rrs.matches(""));
}

with the following error output:

error[E0277]: the type `std::cell::UnsafeCell<std::option::Option<std::boxed::Box<std::cell::RefCell<regex::exec::ProgramCacheInner>>>>` may contain interior mutability and a reference may not be safely transferrable across a catch_unwind boundary
 --> src/main.rs:4:5
  |
4 |     std::panic::catch_unwind(move || rrs.matches(""));
  |     ^^^^^^^^^^^^^^^^^^^^^^^^ `std::cell::UnsafeCell<std::option::Option<std::boxed::Box<std::cell::RefCell<regex::exec::ProgramCacheInner>>>>` may contain interior mutability and a reference may not be safely transferrable across a catch_unwind boundary
  |
  = help: within `regex::re_set::unicode::RegexSet`, the trait `std::panic::RefUnwindSafe` is not implemented for `std::cell::UnsafeCell<std::option::Option<std::boxed::Box<std::cell::RefCell<regex::exec::ProgramCacheInner>>>>`
  = note: required because it appears within the type `thread_local::CachedThreadLocal<std::cell::RefCell<regex::exec::ProgramCacheInner>>`
  = note: required because it appears within the type `regex::exec::Exec`
  = note: required because it appears within the type `regex::re_set::unicode::RegexSet`
  = note: required because of the requirements on the impl of `std::panic::UnwindSafe` for `&regex::re_set::unicode::RegexSet`
  = note: required because it appears within the type `[closure@src/main.rs:4:30: 4:53 rrs:&regex::re_set::unicode::RegexSet]`
  = note: required by `std::panic::catch_unwind`

error[E0277]: the type `std::cell::UnsafeCell<regex::exec::ProgramCacheInner>` may contain interior mutability and a reference may not be safely transferrable across a catch_unwind boundary
 --> src/main.rs:4:5
  |
4 |     std::panic::catch_unwind(move || rrs.matches(""));
  |     ^^^^^^^^^^^^^^^^^^^^^^^^ `std::cell::UnsafeCell<regex::exec::ProgramCacheInner>` may contain interior mutability and a reference may not be safely transferrable across a catch_unwind boundary
  |
  = help: within `regex::re_set::unicode::RegexSet`, the trait `std::panic::RefUnwindSafe` is not implemented for `std::cell::UnsafeCell<regex::exec::ProgramCacheInner>`
  = note: required because it appears within the type `std::cell::RefCell<regex::exec::ProgramCacheInner>`
  = note: required because it appears within the type `std::marker::PhantomData<std::cell::RefCell<regex::exec::ProgramCacheInner>>`
  = note: required because it appears within the type `thread_local::ThreadLocal<std::cell::RefCell<regex::exec::ProgramCacheInner>>`
  = note: required because it appears within the type `thread_local::CachedThreadLocal<std::cell::RefCell<regex::exec::ProgramCacheInner>>`
  = note: required because it appears within the type `regex::exec::Exec`
  = note: required because it appears within the type `regex::re_set::unicode::RegexSet`
  = note: required because of the requirements on the impl of `std::panic::UnwindSafe` for `&regex::re_set::unicode::RegexSet`
  = note: required because it appears within the type `[closure@src/main.rs:4:30: 4:53 rrs:&regex::re_set::unicode::RegexSet]`
  = note: required by `std::panic::catch_unwind`

error[E0277]: the type `std::cell::UnsafeCell<isize>` may contain interior mutability and a reference may not be safely transferrable across a catch_unwind boundary
 --> src/main.rs:4:5
  |
4 |     std::panic::catch_unwind(move || rrs.matches(""));
  |     ^^^^^^^^^^^^^^^^^^^^^^^^ `std::cell::UnsafeCell<isize>` may contain interior mutability and a reference may not be safely transferrable across a catch_unwind boundary
  |
  = help: within `regex::re_set::unicode::RegexSet`, the trait `std::panic::RefUnwindSafe` is not implemented for `std::cell::UnsafeCell<isize>`
  = note: required because it appears within the type `std::cell::Cell<isize>`
  = note: required because it appears within the type `std::cell::RefCell<regex::exec::ProgramCacheInner>`
  = note: required because it appears within the type `std::marker::PhantomData<std::cell::RefCell<regex::exec::ProgramCacheInner>>`
  = note: required because it appears within the type `thread_local::ThreadLocal<std::cell::RefCell<regex::exec::ProgramCacheInner>>`
  = note: required because it appears within the type `thread_local::CachedThreadLocal<std::cell::RefCell<regex::exec::ProgramCacheInner>>`
  = note: required because it appears within the type `regex::exec::Exec`
  = note: required because it appears within the type `regex::re_set::unicode::RegexSet`
  = note: required because of the requirements on the impl of `std::panic::UnwindSafe` for `&regex::re_set::unicode::RegexSet`
  = note: required because it appears within the type `[closure@src/main.rs:4:30: 4:53 rrs:&regex::re_set::unicode::RegexSet]`
  = note: required by `std::panic::catch_unwind`

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0277`.
error: Could not compile `testapp`.

To learn more, run the command again with --verbose.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions