Skip to content
Open
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
7 changes: 3 additions & 4 deletions regex-lite/src/hir/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -593,8 +593,7 @@ impl<'a> Parser<'a> {
'u' => 4,
'U' => 8,
unk => unreachable!(
"invalid start of fixed length hexadecimal number {}",
unk
"invalid start of fixed length hexadecimal number {unk}"
),
};
if !self.bump_and_bump_space() {
Expand Down Expand Up @@ -720,7 +719,7 @@ impl<'a> Parser<'a> {
'?' => (0, Some(1)),
'*' => (0, None),
'+' => (1, None),
unk => unreachable!("unrecognized repetition operator '{}'", unk),
unk => unreachable!("unrecognized repetition operator '{unk}'"),
};
let mut greedy = true;
if self.bump() && self.char() == '?' {
Expand Down Expand Up @@ -1216,7 +1215,7 @@ impl<'a> Parser<'a> {
'd' | 'D' => posix_class("digit").unwrap(),
's' | 'S' => posix_class("space").unwrap(),
'w' | 'W' => posix_class("word").unwrap(),
unk => unreachable!("invalid Perl class \\{}", unk),
unk => unreachable!("invalid Perl class \\{unk}"),
});
if ch.is_ascii_uppercase() {
class.negate();
Expand Down
14 changes: 7 additions & 7 deletions regex-lite/src/nfa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ impl core::fmt::Debug for NFA {
writeln!(f, "NFA(")?;
writeln!(f, "pattern: {}", self.pattern)?;
for (sid, state) in self.states.iter().enumerate() {
writeln!(f, "{:07?}: {:?}", sid, state)?;
writeln!(f, "{sid:07?}: {state:?}")?;
}
writeln!(f, ")")?;
Ok(())
Expand Down Expand Up @@ -206,14 +206,14 @@ impl core::fmt::Debug for State {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match *self {
State::Char { target, ch } => {
write!(f, "{:?} => {:?}", ch, target)
write!(f, "{ch:?} => {target:?}")
}
State::Ranges { target, ref ranges } => {
for (i, &(start, end)) in ranges.iter().enumerate() {
if i > 0 {
write!(f, ", ")?;
}
write!(f, "{:?}-{:?} => {:?}", start, end, target)?;
write!(f, "{start:?}-{end:?} => {target:?}")?;
}
Ok(())
}
Expand All @@ -225,18 +225,18 @@ impl core::fmt::Debug for State {
if i > 0 {
write!(f, ", ")?;
}
write!(f, "{:?}", sid)?;
write!(f, "{sid:?}")?;
}
write!(f, ")")
}
State::Goto { target, look: None } => {
write!(f, "goto({:?})", target)
write!(f, "goto({target:?})")
}
State::Goto { target, look: Some(look) } => {
write!(f, "{:?} => {:?}", look, target)
write!(f, "{look:?} => {target:?}")
}
State::Capture { target, slot } => {
write!(f, "capture(slot={:?}) => {:?}", slot, target,)
write!(f, "capture(slot={slot:?}) => {target:?}")
}
State::Fail => write!(f, "FAIL"),
State::Match => {
Expand Down
8 changes: 4 additions & 4 deletions regex-lite/src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1798,7 +1798,7 @@ impl<'h> Captures<'h> {
.nfa()
.static_explicit_captures_len()
.expect("number of capture groups can vary in a match");
assert_eq!(N, len, "asked for {} groups, but must ask for {}", N, len);
assert_eq!(N, len, "asked for {N} groups, but must ask for {len}");
let mut matched = self.iter().flatten();
let whole_match = matched.next().expect("a match").as_str();
let group_matches = [0; N].map(|_| {
Expand Down Expand Up @@ -1965,7 +1965,7 @@ impl<'h> core::fmt::Debug for Captures<'h> {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
write!(f, "{}", self.0)?;
if let Some(name) = self.1 {
write!(f, "/{:?}", name)?;
write!(f, "/{name:?}")?;
}
Ok(())
}
Expand Down Expand Up @@ -2013,7 +2013,7 @@ impl<'h> core::ops::Index<usize> for Captures<'h> {
fn index(&self, i: usize) -> &str {
self.get(i)
.map(|m| m.as_str())
.unwrap_or_else(|| panic!("no group at index '{}'", i))
.unwrap_or_else(|| panic!("no group at index '{i}'"))
}
}

Expand All @@ -2039,7 +2039,7 @@ impl<'h, 'n> core::ops::Index<&'n str> for Captures<'h> {
fn index<'a>(&'a self, name: &'n str) -> &'a str {
self.name(name)
.map(|m| m.as_str())
.unwrap_or_else(|| panic!("no group named '{}'", name))
.unwrap_or_else(|| panic!("no group named '{name}'"))
}
}

Expand Down
5 changes: 2 additions & 3 deletions regex-lite/tests/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ fn run_test(re: &Regex, test: &RegexTest) -> TestResult {
Ok(hay) => hay,
Err(err) => {
return TestResult::fail(&format!(
"haystack is not valid UTF-8: {}",
err
"haystack is not valid UTF-8: {err}",
));
}
};
Expand All @@ -45,7 +44,7 @@ fn run_test(re: &Regex, test: &RegexTest) -> TestResult {
.map(|caps| testify_captures(&caps));
TestResult::captures(it)
}
name => TestResult::fail(&format!("unrecognized test name: {}", name)),
name => TestResult::fail(&format!("unrecognized test name: {name}")),
}
}

Expand Down
14 changes: 7 additions & 7 deletions regex-test/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,17 +151,17 @@ impl RegexTests {
/// The given group name is assigned to all loaded tests.
pub fn load_slice(&mut self, group_name: &str, data: &[u8]) -> Result<()> {
let data = std::str::from_utf8(&data).with_context(|| {
format!("data in {} is not valid UTF-8", group_name)
format!("data in {group_name} is not valid UTF-8")
})?;
let mut index = 1;
let mut tests: RegexTests =
toml::from_str(&data).with_context(|| {
format!("error decoding TOML for '{}'", group_name)
format!("error decoding TOML for '{group_name}'")
})?;
for t in &mut tests.tests {
t.group = group_name.to_string();
if t.name.is_empty() {
t.name = format!("{}", index);
t.name = format!("{index}");
index += 1;
}
t.full_name = format!("{}/{}", t.group, t.name);
Expand Down Expand Up @@ -1101,7 +1101,7 @@ impl RegexTestFailureKind {
let mut buf = String::new();
match *self {
RegexTestFailureKind::UserFailure { ref why } => {
write!(buf, "failed by implementor because: {}", why)?;
write!(buf, "failed by implementor because: {why}")?;
}
RegexTestFailureKind::IsMatch => {
if test.is_match() {
Expand Down Expand Up @@ -1140,13 +1140,13 @@ impl RegexTestFailureKind {
write!(buf, "expected regex to NOT compile, but it did")?;
}
RegexTestFailureKind::CompileError { ref err } => {
write!(buf, "expected regex to compile, failed: {}", err)?;
write!(buf, "expected regex to compile, failed: {err}")?;
}
RegexTestFailureKind::UnexpectedPanicCompile(ref msg) => {
write!(buf, "got unexpected panic while compiling:\n{}", msg)?;
write!(buf, "got unexpected panic while compiling:\n{msg}")?;
}
RegexTestFailureKind::UnexpectedPanicSearch(ref msg) => {
write!(buf, "got unexpected panic while searching:\n{}", msg)?;
write!(buf, "got unexpected panic while searching:\n{msg}")?;
}
}
Ok(buf)
Expand Down
2 changes: 1 addition & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl core::fmt::Display for Error {
Error::Syntax(ref err) => err.fmt(f),
Error::CompiledTooBig(limit) => write!(
f,
"Compiled regex exceeds size limit of {limit} bytes."
"Compiled regex exceeds size limit of {limit} bytes.",
),
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/regex/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1992,7 +1992,7 @@ impl<'h> core::ops::Index<usize> for Captures<'h> {
fn index<'a>(&'a self, i: usize) -> &'a [u8] {
self.get(i)
.map(|m| m.as_bytes())
.unwrap_or_else(|| panic!("no group at index '{}'", i))
.unwrap_or_else(|| panic!("no group at index '{i}'"))
}
}

Expand All @@ -2018,7 +2018,7 @@ impl<'h, 'n> core::ops::Index<&'n str> for Captures<'h> {
fn index<'a>(&'a self, name: &'n str) -> &'a [u8] {
self.name(name)
.map(|m| m.as_bytes())
.unwrap_or_else(|| panic!("no group named '{}'", name))
.unwrap_or_else(|| panic!("no group named '{name}'"))
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/regex/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2000,7 +2000,7 @@ impl<'h> core::ops::Index<usize> for Captures<'h> {
fn index<'a>(&'a self, i: usize) -> &'a str {
self.get(i)
.map(|m| m.as_str())
.unwrap_or_else(|| panic!("no group at index '{}'", i))
.unwrap_or_else(|| panic!("no group at index '{i}'"))
}
}

Expand All @@ -2026,7 +2026,7 @@ impl<'h, 'n> core::ops::Index<&'n str> for Captures<'h> {
fn index<'a>(&'a self, name: &'n str) -> &'a str {
self.name(name)
.map(|m| m.as_str())
.unwrap_or_else(|| panic!("no group named '{}'", name))
.unwrap_or_else(|| panic!("no group named '{name}'"))
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/suite_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn run_test(re: &Regex, test: &RegexTest) -> TestResult {
Ok(hay) => hay,
Err(err) => {
return TestResult::fail(&format!(
"haystack is not valid UTF-8: {err}"
"haystack is not valid UTF-8: {err}",
));
}
};
Expand Down
2 changes: 1 addition & 1 deletion tests/suite_string_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn run_test(re: &RegexSet, test: &RegexTest) -> TestResult {
Ok(hay) => hay,
Err(err) => {
return TestResult::fail(&format!(
"haystack is not valid UTF-8: {err}"
"haystack is not valid UTF-8: {err}",
));
}
};
Expand Down
Loading