Skip to content

Commit df7fee7

Browse files
committed
api: test for UnwindSafe
It appears that using a trait object internally implies that the containing type cannot be assumed to be UnwindSafe. This wasn't previously an explicit API guarantee, but the AhoCorasick automaton in 0.6.x was UnwindSafe and it's probably a good idea to keep that particular feature. Here, we satisfy that by requiring Prefilter to be UnwindSafe, so that all Prefilter trait objects are therefore also UnwindSafe. In particular, this introduced a regression in regex that caused a regex to not be UnwindSafe because it contained an AhoCorasick automaton. See rust-lang/regex#568 for details.
1 parent 9a1ece4 commit df7fee7

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/ahocorasick.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2016,12 +2016,17 @@ mod tests {
20162016

20172017
#[test]
20182018
fn oibits() {
2019+
use std::panic::UnwindSafe;
2020+
20192021
fn assert_send<T: Send>() {}
20202022
fn assert_sync<T: Sync>() {}
2023+
fn assert_unwind_safe<T: UnwindSafe>() {}
20212024

20222025
assert_send::<AhoCorasick>();
20232026
assert_sync::<AhoCorasick>();
2027+
assert_unwind_safe::<AhoCorasick>();
20242028
assert_send::<AhoCorasickBuilder>();
20252029
assert_sync::<AhoCorasickBuilder>();
2030+
assert_unwind_safe::<AhoCorasickBuilder>();
20262031
}
20272032
}

src/prefilter.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
use std::fmt;
2+
use std::panic::UnwindSafe;
23

34
use memchr::{memchr, memchr2, memchr3};
45

56
/// A prefilter describes the behavior of fast literal scanners for quickly
67
/// skipping past bytes in the haystack that we know cannot possibly
78
/// participate in a match.
8-
pub trait Prefilter: Send + Sync + fmt::Debug {
9+
pub trait Prefilter: Send + Sync + UnwindSafe + fmt::Debug {
910
/// Returns the next possible match candidate. This may yield false
1011
/// positives, so callers must "confirm" a match starting at the position
1112
/// returned. This, however, must never produce false negatives. That is,

0 commit comments

Comments
 (0)