Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions regex-automata/src/dfa/accel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ pub(crate) fn find_fwd(
2 => memchr::memchr2(bs[0], bs[1], &haystack[at..])?,
3 => memchr::memchr3(bs[0], bs[1], bs[2], &haystack[at..])?,
0 => panic!("cannot find with empty needles"),
n => panic!("invalid needles length: {}", n),
n => panic!("invalid needles length: {n}"),
};
Some(at + i)
}
Expand All @@ -122,7 +122,7 @@ pub(crate) fn find_rev(
2 => memchr::memrchr2(bs[0], bs[1], &haystack[..at]),
3 => memchr::memrchr3(bs[0], bs[1], bs[2], &haystack[..at]),
0 => panic!("cannot find with empty needles"),
n => panic!("invalid needles length: {}", n),
n => panic!("invalid needles length: {n}"),
}
}

Expand Down Expand Up @@ -267,7 +267,7 @@ impl<A: AsRef<[AccelTy]>> Accels<A> {
#[cfg_attr(feature = "perf-inline", inline(always))]
pub fn needles(&self, i: usize) -> &[u8] {
if i >= self.len() {
panic!("invalid accelerator index {}", i);
panic!("invalid accelerator index {i}");
}
let bytes = self.as_bytes();
let offset = ACCEL_TY_SIZE + i * ACCEL_CAP;
Expand Down Expand Up @@ -313,8 +313,8 @@ impl<A: AsRef<[AccelTy]>> Accels<A> {
assert_eq!(
nwrite % ACCEL_TY_SIZE,
0,
"expected accelerator bytes written to be a multiple of {}",
ACCEL_TY_SIZE,
"expected accelerator bytes written to be a multiple \
of {ACCEL_TY_SIZE}",
);
if dst.len() < nwrite {
return Err(SerializeError::buffer_too_small("accelerators"));
Expand Down
31 changes: 15 additions & 16 deletions regex-automata/src/dfa/dense.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2837,8 +2837,8 @@ impl OwnedDFA {
}
assert!(
!matches.contains_key(&start_id),
"{:?} is both a start and a match state, which is not allowed",
start_id,
"{start_id:?} is both a start and a match state, \
which is not allowed",
);
is_start.insert(start_id);
}
Expand Down Expand Up @@ -3098,7 +3098,7 @@ impl<T: AsRef<[u32]>> fmt::Debug for DFA<T> {
} else {
self.to_index(state.id())
};
write!(f, "{:06?}: ", id)?;
write!(f, "{id:06?}: ")?;
state.fmt(f)?;
write!(f, "\n")?;
}
Expand All @@ -3114,11 +3114,11 @@ impl<T: AsRef<[u32]>> fmt::Debug for DFA<T> {
Anchored::No => writeln!(f, "START-GROUP(unanchored)")?,
Anchored::Yes => writeln!(f, "START-GROUP(anchored)")?,
Anchored::Pattern(pid) => {
writeln!(f, "START_GROUP(pattern: {:?})", pid)?
writeln!(f, "START_GROUP(pattern: {pid:?})")?
}
}
}
writeln!(f, " {:?} => {:06?}", sty, id)?;
writeln!(f, " {sty:?} => {id:06?}")?;
}
if self.pattern_len() > 1 {
writeln!(f, "")?;
Expand All @@ -3129,13 +3129,13 @@ impl<T: AsRef<[u32]>> fmt::Debug for DFA<T> {
} else {
self.to_index(id)
};
write!(f, "MATCH({:06?}): ", id)?;
write!(f, "MATCH({id:06?}): ")?;
for (i, &pid) in self.ms.pattern_id_slice(i).iter().enumerate()
{
if i > 0 {
write!(f, ", ")?;
}
write!(f, "{:?}", pid)?;
write!(f, "{pid:?}")?;
}
writeln!(f, "")?;
}
Expand Down Expand Up @@ -3525,8 +3525,8 @@ impl TransitionTable<Vec<u32>> {
///
/// Both id1 and id2 must point to valid states, otherwise this panics.
fn swap(&mut self, id1: StateID, id2: StateID) {
assert!(self.is_valid(id1), "invalid 'id1' state: {:?}", id1);
assert!(self.is_valid(id2), "invalid 'id2' state: {:?}", id2);
assert!(self.is_valid(id1), "invalid 'id1' state: {id1:?}");
assert!(self.is_valid(id2), "invalid 'id2' state: {id2:?}");
// We only need to swap the parts of the state that are used. So if the
// stride is 64, but the alphabet length is only 33, then we save a lot
// of work.
Expand Down Expand Up @@ -4277,7 +4277,7 @@ impl<T: AsMut<[u32]>> StartTable<T> {
let len = self
.pattern_len
.expect("start states for each pattern enabled");
assert!(pid < len, "invalid pattern ID {:?}", pid);
assert!(pid < len, "invalid pattern ID {pid:?}");
self.stride
.checked_mul(pid)
.unwrap()
Expand Down Expand Up @@ -4868,9 +4868,9 @@ impl<'a> fmt::Debug for State<'a> {
write!(f, ", ")?;
}
if start == end {
write!(f, "{:?} => {:?}", start, id)?;
write!(f, "{start:?} => {id:?}")?;
} else {
write!(f, "{:?}-{:?} => {:?}", start, end, id)?;
write!(f, "{start:?}-{end:?} => {id:?}")?;
}
}
Ok(())
Expand Down Expand Up @@ -5135,7 +5135,7 @@ impl core::fmt::Display for BuildError {
match self.kind() {
BuildErrorKind::NFA(_) => write!(f, "error building NFA"),
BuildErrorKind::Unsupported(ref msg) => {
write!(f, "unsupported regex feature for DFAs: {}", msg)
write!(f, "unsupported regex feature for DFAs: {msg}")
}
BuildErrorKind::TooManyStates => write!(
f,
Expand Down Expand Up @@ -5167,11 +5167,10 @@ impl core::fmt::Display for BuildError {
),
BuildErrorKind::DFAExceededSizeLimit { limit } => write!(
f,
"DFA exceeded size limit of {:?} during determinization",
limit,
"DFA exceeded size limit of {limit:?} during determinization",
),
BuildErrorKind::DeterminizeExceededSizeLimit { limit } => {
write!(f, "determinization exceeded size limit of {:?}", limit)
write!(f, "determinization exceeded size limit of {limit:?}")
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion regex-automata/src/dfa/determinize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ impl<'a> Runner<'a> {
let per_elem = size_of::<StateID>() + size_of::<Vec<PatternID>>();
let pats = total_pat_len * size_of::<PatternID>();
let mem = (matches.len() * per_elem) + pats;
log::debug!("matches map built, memory usage: {}", mem);
log::debug!("matches map built, memory usage: {mem}");
}
// At this point, we shuffle the "special" states in the final DFA.
// This permits a DFA's match loop to detect a match condition (among
Expand Down
24 changes: 11 additions & 13 deletions regex-automata/src/dfa/onepass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2408,7 +2408,7 @@ impl core::fmt::Debug for DFA {
}
write!(f, "{:06?}", sid.as_usize())?;
if !pateps.is_empty() {
write!(f, " ({:?})", pateps)?;
write!(f, " ({pateps:?})")?;
}
write!(f, ": ")?;
debug_state_transitions(f, self, sid)?;
Expand Down Expand Up @@ -2939,7 +2939,7 @@ impl core::fmt::Debug for Slots {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
write!(f, "S")?;
for slot in self.iter() {
write!(f, "-{:?}", slot)?;
write!(f, "-{slot:?}")?;
}
Ok(())
}
Expand Down Expand Up @@ -3050,23 +3050,21 @@ impl core::fmt::Display for BuildError {
Word(_) => write!(f, "NFA contains Unicode word boundary"),
TooManyStates { limit } => write!(
f,
"one-pass DFA exceeded a limit of {:?} for number of states",
limit,
"one-pass DFA exceeded a limit of {limit:?} \
for number of states",
),
TooManyPatterns { limit } => write!(
f,
"one-pass DFA exceeded a limit of {:?} for number of patterns",
limit,
"one-pass DFA exceeded a limit of {limit:?} \
for number of patterns",
),
UnsupportedLook { look } => write!(
f,
"one-pass DFA does not support the {:?} assertion",
look,
"one-pass DFA does not support the {look:?} assertion",
),
ExceededSizeLimit { limit } => write!(
f,
"one-pass DFA exceeded size limit of {:?} during building",
limit,
"one-pass DFA exceeded size limit of {limit:?} during building",
),
NotOnePass { msg } => write!(
f,
Expand All @@ -3089,7 +3087,7 @@ mod tests {
let predicate = |err: &str| err.contains("conflicting transition");

let err = DFA::new(r"a*[ab]").unwrap_err().to_string();
assert!(predicate(&err), "{}", err);
assert!(predicate(&err), "{err}");
}

#[test]
Expand All @@ -3099,7 +3097,7 @@ mod tests {
};

let err = DFA::new(r"(^|$)a").unwrap_err().to_string();
assert!(predicate(&err), "{}", err);
assert!(predicate(&err), "{err}");
}

#[test]
Expand All @@ -3109,7 +3107,7 @@ mod tests {
};

let err = DFA::new_many(&[r"^", r"$"]).unwrap_err().to_string();
assert!(predicate(&err), "{}", err);
assert!(predicate(&err), "{err}");
}

// This test is meant to build a one-pass regex with the maximum number of
Expand Down
5 changes: 2 additions & 3 deletions regex-automata/src/dfa/sparse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,7 @@ impl DFA<Vec<u8>> {
);
assert!(
transition_len <= 257,
"expected transition length {} to be <= 257",
transition_len,
"expected transition length {transition_len} to be <= 257",
);

// Fill in the transition length.
Expand Down Expand Up @@ -2158,7 +2157,7 @@ impl<T: AsMut<[u8]>> StartTable<T> {
let len = self
.pattern_len
.expect("start states for each pattern enabled");
assert!(pid < len, "invalid pattern ID {:?}", pid);
assert!(pid < len, "invalid pattern ID {pid:?}");
self.stride
.checked_mul(pid)
.unwrap()
Expand Down
9 changes: 4 additions & 5 deletions regex-automata/src/hybrid/dfa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2598,8 +2598,8 @@ impl<'i, 'c> Lazy<'i, 'c> {
unit: alphabet::Unit,
to: LazyStateID,
) {
assert!(self.as_ref().is_valid(from), "invalid 'from' id: {:?}", from);
assert!(self.as_ref().is_valid(to), "invalid 'to' id: {:?}", to);
assert!(self.as_ref().is_valid(from), "invalid 'from' id: {from:?}");
assert!(self.as_ref().is_valid(to), "invalid 'to' id: {to:?}");
let offset =
from.as_usize_untagged() + self.dfa.classes.get_by_unit(unit);
self.cache.trans[offset] = to;
Expand Down Expand Up @@ -4080,10 +4080,9 @@ impl Builder {
// and mush on.
if self.config.get_skip_cache_capacity_check() {
debug!(
"given capacity ({}) is too small, \
"given capacity ({cache_capacity}) is too small, \
since skip_cache_capacity_check is enabled, \
setting cache capacity to minimum ({})",
cache_capacity, min_cache,
setting cache capacity to minimum ({min_cache})",
);
cache_capacity = min_cache;
} else {
Expand Down
7 changes: 3 additions & 4 deletions regex-automata/src/hybrid/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,15 @@ impl core::fmt::Display for BuildError {
BuildErrorKind::InsufficientCacheCapacity { minimum, given } => {
write!(
f,
"given cache capacity ({}) is smaller than \
minimum required ({})",
given, minimum,
"given cache capacity ({given}) is smaller than \
minimum required ({minimum})",
)
}
BuildErrorKind::InsufficientStateIDCapacity { ref err } => {
err.fmt(f)
}
BuildErrorKind::Unsupported(ref msg) => {
write!(f, "unsupported regex feature for DFAs: {}", msg)
write!(f, "unsupported regex feature for DFAs: {msg}")
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion regex-automata/src/meta/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ impl From<MatchError> for RetryFailError {
// backtracker's wrapper will never hand out a backtracker engine
// when the haystack would be too long.
HaystackTooLong { .. } | UnsupportedAnchored { .. } => {
unreachable!("found impossible error in meta engine: {}", merr)
unreachable!("found impossible error in meta engine: {merr}")
}
}
}
Expand Down
12 changes: 4 additions & 8 deletions regex-automata/src/meta/limited.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,8 @@ pub(crate) fn dfa_try_search_half_rev(
at -= 1;
if at < min_start {
trace!(
"reached position {} which is before the previous literal \
"reached position {at} which is before the previous literal \
match, quitting to avoid quadratic behavior",
at,
);
return Err(RetryError::Quadratic(RetryQuadraticError::new()));
}
Expand Down Expand Up @@ -114,9 +113,8 @@ pub(crate) fn dfa_try_search_half_rev(
&& !was_dead
{
trace!(
"reached beginning of search at offset {} without hitting \
"reached beginning of search at offset {at} without hitting \
a dead state, quitting to avoid potential false positive match",
at,
);
return Err(RetryError::Quadratic(RetryQuadraticError::new()));
}
Expand Down Expand Up @@ -161,9 +159,8 @@ pub(crate) fn hybrid_try_search_half_rev(
at -= 1;
if at < min_start {
trace!(
"reached position {} which is before the previous literal \
"reached position {at} which is before the previous literal \
match, quitting to avoid quadratic behavior",
at,
);
return Err(RetryError::Quadratic(RetryQuadraticError::new()));
}
Expand All @@ -176,9 +173,8 @@ pub(crate) fn hybrid_try_search_half_rev(
&& !was_dead
{
trace!(
"reached beginning of search at offset {} without hitting \
"reached beginning of search at offset {at} without hitting \
a dead state, quitting to avoid potential false positive match",
at,
);
return Err(RetryError::Quadratic(RetryQuadraticError::new()));
}
Expand Down
4 changes: 2 additions & 2 deletions regex-automata/src/meta/literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ pub(crate) fn alternation_literals(
HirKind::Literal(Literal(ref bytes)) => {
lit.extend_from_slice(bytes);
}
_ => unreachable!("expected literal, got {:?}", e),
_ => unreachable!("expected literal, got {e:?}"),
}
}
}
_ => unreachable!("expected literal or concat, got {:?}", alt),
_ => unreachable!("expected literal or concat, got {alt:?}"),
}
lits.push(lit);
}
Expand Down
4 changes: 2 additions & 2 deletions regex-automata/src/meta/regex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3413,9 +3413,9 @@ impl Builder {
.last()
.unwrap_or(0);
if maxoff < p.len() {
debug!("{:?}: {}[... snip ...]", pid, &p[..maxoff]);
debug!("{pid:?}: {}[... snip ...]", &p[..maxoff]);
} else {
debug!("{:?}: {}", pid, p);
debug!("{pid:?}: {p}");
}
}
}
Expand Down
Loading
Loading