Skip to content

Commit 9200000

Browse files
committed
Inline format-args in CLI
This makes the code a bit easier to read and smaller. Some of it was done with this command, and later fixed by hand: ``` cargo clippy --workspace --allow-dirty --fix --benches --tests --bins -- -A clippy::all -W clippy::uninlined_format_args ```
1 parent 2695e29 commit 9200000

File tree

19 files changed

+56
-69
lines changed

19 files changed

+56
-69
lines changed

regex-cli/args/flags.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@ impl std::str::FromStr for ByteSet {
5050
for &byte in Vec::unescape_bytes(s).iter() {
5151
anyhow::ensure!(
5252
!seen[usize::from(byte)],
53-
"saw duplicate byte 0x{:2X} in '{}'",
54-
byte,
55-
s,
53+
"saw duplicate byte 0x{byte:2X} in '{s}'",
5654
);
5755
seen[usize::from(byte)] = true;
5856
set.push(byte);
@@ -96,7 +94,7 @@ impl std::str::FromStr for StartKind {
9694
"both" => regex_automata::dfa::StartKind::Both,
9795
"unanchored" => regex_automata::dfa::StartKind::Unanchored,
9896
"anchored" => regex_automata::dfa::StartKind::Anchored,
99-
unk => anyhow::bail!("unrecognized start kind '{}'", unk),
97+
unk => anyhow::bail!("unrecognized start kind '{unk}'"),
10098
};
10199
Ok(StartKind { kind })
102100
}
@@ -147,7 +145,7 @@ impl std::str::FromStr for MatchKind {
147145
let kind = match s {
148146
"leftmost-first" => regex_automata::MatchKind::LeftmostFirst,
149147
"all" => regex_automata::MatchKind::All,
150-
unk => anyhow::bail!("unrecognized match kind '{}'", unk),
148+
unk => anyhow::bail!("unrecognized match kind '{unk}'"),
151149
};
152150
Ok(MatchKind { kind })
153151
}

regex-cli/args/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,11 @@ pub fn next_as_command(usage: &str, p: &mut Parser) -> anyhow::Result<String> {
143143
let usage = usage.trim();
144144
let arg = match p.next()? {
145145
Some(arg) => arg,
146-
None => anyhow::bail!("{}", usage),
146+
None => anyhow::bail!("{usage}"),
147147
};
148148
let cmd = match arg {
149149
Arg::Value(cmd) => cmd.string()?,
150-
Arg::Short('h') | Arg::Long("help") => anyhow::bail!("{}", usage),
150+
Arg::Short('h') | Arg::Long("help") => anyhow::bail!("{usage}"),
151151
arg => return Err(arg.unexpected().into()),
152152
};
153153
Ok(cmd)

regex-cli/args/syntax.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl Config {
4545
.map(|(i, p)| {
4646
let p = p.as_ref();
4747
self.ast(p).with_context(|| {
48-
format!("failed to parse pattern {} to AST: '{}'", i, p,)
48+
format!("failed to parse pattern {i} to AST: '{p}'",)
4949
})
5050
})
5151
.collect()
@@ -80,10 +80,7 @@ impl Config {
8080
.map(|(i, (pat, ast))| {
8181
let (pat, ast) = (pat.as_ref(), ast.borrow());
8282
self.hir(pat, ast).with_context(|| {
83-
format!(
84-
"failed to translate pattern {} to HIR: '{}'",
85-
i, pat,
86-
)
83+
format!("failed to translate pattern {i} to HIR: '{pat}'",)
8784
})
8885
})
8986
.collect()

regex-cli/cmd/compile_test.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,11 @@ OPTIONS:
127127
} else {
128128
write!(wtr, "regex,")?;
129129
}
130-
write!(wtr, "{},", revision)?;
130+
write!(wtr, "{revision},")?;
131131
write!(wtr, "{},", tdir.test.profile.as_str())?;
132132
write!(wtr, "{:?},", m.duration)?;
133133
write!(wtr, "{:?},", m.size)?;
134-
write!(wtr, "{:?}", relative_size)?;
134+
write!(wtr, "{relative_size:?}")?;
135135
write!(wtr, "\n")?;
136136
}
137137
Ok(())
@@ -439,7 +439,7 @@ impl Test {
439439
let features = self
440440
.features
441441
.iter()
442-
.map(|f| format!(r#""{}""#, f))
442+
.map(|f| format!(r#""{f}""#))
443443
.collect::<Vec<String>>()
444444
.join(", ");
445445
format!(
@@ -480,7 +480,7 @@ strip = "symbols"
480480
let features = self
481481
.features
482482
.iter()
483-
.map(|f| format!(r#""{}""#, f))
483+
.map(|f| format!(r#""{f}""#))
484484
.collect::<Vec<String>>()
485485
.join(", ");
486486
format!(
@@ -521,7 +521,7 @@ strip = "symbols"
521521
let features = self
522522
.features
523523
.iter()
524-
.map(|f| format!(r#""{}""#, f))
524+
.map(|f| format!(r#""{f}""#))
525525
.collect::<Vec<String>>()
526526
.join(", ");
527527
format!(
@@ -800,8 +800,7 @@ fn baseline_size(parent_dir: &Path, profile: Profile) -> anyhow::Result<u64> {
800800
.with_context(|| format!("'cargo clean' failed for baseline"))?;
801801
anyhow::ensure!(
802802
status.success(),
803-
"'cargo clean' got an error exit code of {:?} for baseline",
804-
status,
803+
"'cargo clean' got an error exit code of {status:?} for baseline",
805804
);
806805
let status = Command::new("cargo")
807806
.arg("build")
@@ -814,8 +813,7 @@ fn baseline_size(parent_dir: &Path, profile: Profile) -> anyhow::Result<u64> {
814813
.with_context(|| format!("'cargo build' failed for baseline"))?;
815814
anyhow::ensure!(
816815
status.success(),
817-
"'cargo build' got an error exit code of {:?} for baseline",
818-
status,
816+
"'cargo build' got an error exit code of {status:?} for baseline",
819817
);
820818
let bin = dir
821819
.join("target")

regex-cli/cmd/debug/dfa.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ COMMANDS:
2929
match &*cmd {
3030
"dfa" => run_dense_dfa(p),
3131
"regex" => run_dense_regex(p),
32-
unk => anyhow::bail!("unrecognized command '{}'", unk),
32+
unk => anyhow::bail!("unrecognized command '{unk}'"),
3333
}
3434
}
3535

@@ -88,7 +88,7 @@ OPTIONS:
8888
if common.table() {
8989
writeln!(stdout(), "")?;
9090
}
91-
writeln!(stdout(), "{:?}", dfa)?;
91+
writeln!(stdout(), "{dfa:?}")?;
9292
}
9393
Ok(())
9494
}
@@ -161,7 +161,7 @@ OPTIONS:
161161
if common.table() {
162162
writeln!(stdout(), "")?;
163163
}
164-
writeln!(stdout(), "{:?}", re)?;
164+
writeln!(stdout(), "{re:?}")?;
165165
}
166166
Ok(())
167167
}
@@ -188,7 +188,7 @@ COMMANDS:
188188
match &*cmd {
189189
"dfa" => run_sparse_dfa(p),
190190
"regex" => run_sparse_regex(p),
191-
unk => anyhow::bail!("unrecognized command '{}'", unk),
191+
unk => anyhow::bail!("unrecognized command '{unk}'"),
192192
}
193193
}
194194

@@ -245,7 +245,7 @@ OPTIONS:
245245
if common.table() {
246246
writeln!(stdout(), "")?;
247247
}
248-
writeln!(stdout(), "{:?}", dfa)?;
248+
writeln!(stdout(), "{dfa:?}")?;
249249
}
250250
Ok(())
251251
}
@@ -320,7 +320,7 @@ OPTIONS:
320320
if common.table() {
321321
writeln!(stdout(), "")?;
322322
}
323-
writeln!(stdout(), "{:?}", re)?;
323+
writeln!(stdout(), "{re:?}")?;
324324
}
325325
Ok(())
326326
}

regex-cli/cmd/debug/literal.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ OPTIONS:
6464
ExtractKind::Suffix => seq.optimize_for_suffix_by_preference(),
6565
unk => {
6666
anyhow::bail!(
67-
"unsupported literal extraction kind: {:?}",
68-
unk
67+
"unsupported literal extraction kind: {unk:?}"
6968
)
7069
}
7170
}
@@ -95,10 +94,10 @@ OPTIONS:
9594
writeln!(out, "")?;
9695
}
9796
match seq.literals() {
98-
None => writeln!(out, "{:?}", seq)?,
97+
None => writeln!(out, "{seq:?}")?,
9998
Some(literals) => {
10099
for lit in literals.iter() {
101-
writeln!(stdout(), "{:?}", lit)?;
100+
writeln!(stdout(), "{lit:?}")?;
102101
}
103102
}
104103
}
@@ -127,8 +126,7 @@ impl Configurable for Literal {
127126
"prefix" => ExtractKind::Prefix,
128127
"suffix" => ExtractKind::Suffix,
129128
unk => anyhow::bail!(
130-
"unknown value for --extract-kind: {}",
131-
unk
129+
"unknown value for --extract-kind: {unk}"
132130
),
133131
};
134132
self.kind = kind.clone();

regex-cli/cmd/debug/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ COMMANDS:
3939
"onepass" => run_onepass(p),
4040
"sparse" => dfa::run_sparse(p),
4141
"thompson" => run_thompson(p),
42-
unk => anyhow::bail!("unrecognized command '{}'", unk),
42+
unk => anyhow::bail!("unrecognized command '{unk}'"),
4343
}
4444
}
4545

@@ -181,7 +181,7 @@ OPTIONS:
181181
if common.table() {
182182
writeln!(stdout(), "")?;
183183
}
184-
writeln!(stdout(), "{:?}", dfa)?;
184+
writeln!(stdout(), "{dfa:?}")?;
185185
}
186186
Ok(())
187187
}
@@ -238,7 +238,7 @@ OPTIONS:
238238
if common.table() {
239239
writeln!(stdout(), "")?;
240240
}
241-
writeln!(stdout(), "{:?}", nfa)?;
241+
writeln!(stdout(), "{nfa:?}")?;
242242
}
243243
Ok(())
244244
}

regex-cli/cmd/find/capture/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ ENGINES:
4646
"onepass" => dfa::run_onepass(p),
4747
"pikevm" => nfa::run_pikevm(p),
4848
"regex" => run_regex(p),
49-
unk => anyhow::bail!("unrecognized command '{}'", unk),
49+
unk => anyhow::bail!("unrecognized command '{unk}'"),
5050
}
5151
}
5252

@@ -388,9 +388,9 @@ fn run_counts(
388388
}
389389
let count = pattern_counts[group_index];
390390
if let Some(name) = maybe_name {
391-
write!(out, "{}/{}: {}", group_index, name, count)?;
391+
write!(out, "{group_index}/{name}: {count}")?;
392392
} else {
393-
write!(out, "{}: {}", group_index, count)?;
393+
write!(out, "{group_index}: {count}")?;
394394
}
395395
}
396396
write!(out, " }}\n")?;
@@ -440,9 +440,9 @@ fn run_search(
440440
write!(out, ", ")?;
441441
}
442442
if let Some(name) = maybe_name {
443-
write!(out, "{}/{}: ", group_index, name)?;
443+
write!(out, "{group_index}/{name}: ")?;
444444
} else {
445-
write!(out, "{}: ", group_index)?;
445+
write!(out, "{group_index}: ")?;
446446
}
447447
match caps.get_group(group_index) {
448448
None => write!(out, "NONE")?,

regex-cli/cmd/find/half/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ ENGINES:
4545
"meta" => run_meta(p),
4646
"regex" => run_regex(p),
4747
"sparse" => dfa::run_sparse(p),
48-
unk => anyhow::bail!("unrecognized command '{}'", unk),
48+
unk => anyhow::bail!("unrecognized command '{unk}'"),
4949
}
5050
}
5151

regex-cli/cmd/find/match/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ ENGINES:
4444
"pikevm" => nfa::run_pikevm(p),
4545
"regex" => run_regex(p),
4646
"sparse" => dfa::run_sparse(p),
47-
unk => anyhow::bail!("unrecognized command '{}'", unk),
47+
unk => anyhow::bail!("unrecognized command '{unk}'"),
4848
}
4949
}
5050

0 commit comments

Comments
 (0)