Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5070f75

Browse files
nyurikBurntSushi
authored andcommitted
syntax: inline format arguments
Closes #1288
1 parent 91a92a9 commit 5070f75

File tree

9 files changed

+30
-36
lines changed

9 files changed

+30
-36
lines changed

‎regex-syntax/src/ast/mod.rs‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1801,9 +1801,7 @@ mod tests {
18011801
let size = core::mem::size_of::<Ast>();
18021802
assert!(
18031803
size <= max,
1804-
"Ast size of {} bytes is bigger than suggested max {}",
1805-
size,
1806-
max
1804+
"Ast size of {size} bytes is bigger than suggested max {max}",
18071805
);
18081806
}
18091807
}

‎regex-syntax/src/ast/parse.rs‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ impl<'s, P: Borrow<Parser>> ParserI<'s, P> {
484484
self.pattern()[i..]
485485
.chars()
486486
.next()
487-
.unwrap_or_else(|| panic!("expected char at offset {}", i))
487+
.unwrap_or_else(|| panic!("expected char at offset {i}"))
488488
}
489489

490490
/// Bump the parser to the next Unicode scalar value.
@@ -2254,7 +2254,7 @@ impl<'s, P: Borrow<Parser>> ParserI<'s, P> {
22542254
'S' => (true, ast::ClassPerlKind::Space),
22552255
'w' => (false, ast::ClassPerlKind::Word),
22562256
'W' => (true, ast::ClassPerlKind::Word),
2257-
c => panic!("expected valid Perl class but got '{}'", c),
2257+
c => panic!("expected valid Perl class but got '{c}'"),
22582258
};
22592259
ast::ClassPerl { span, kind, negated }
22602260
}
@@ -4598,7 +4598,7 @@ bar
45984598

45994599
// We also support superfluous escapes in most cases now too.
46004600
for c in ['!', '@', '%', '"', '\'', '/', ' '] {
4601-
let pat = format!(r"\{}", c);
4601+
let pat = format!(r"\{c}");
46024602
assert_eq!(
46034603
parser(&pat).parse_primitive(),
46044604
Ok(Primitive::Literal(ast::Literal {
@@ -4713,7 +4713,7 @@ bar
47134713
#[test]
47144714
fn parse_octal() {
47154715
for i in 0..511 {
4716-
let pat = format!(r"\{:o}", i);
4716+
let pat = format!(r"\{i:o}");
47174717
assert_eq!(
47184718
parser_octal(&pat).parse_escape(),
47194719
Ok(Primitive::Literal(ast::Literal {
@@ -4788,7 +4788,7 @@ bar
47884788
#[test]
47894789
fn parse_hex_two() {
47904790
for i in 0..256 {
4791-
let pat = format!(r"\x{:02x}", i);
4791+
let pat = format!(r"\x{i:02x}");
47924792
assert_eq!(
47934793
parser(&pat).parse_escape(),
47944794
Ok(Primitive::Literal(ast::Literal {
@@ -4829,7 +4829,7 @@ bar
48294829
None => continue,
48304830
Some(c) => c,
48314831
};
4832-
let pat = format!(r"\u{:04x}", i);
4832+
let pat = format!(r"\u{i:04x}");
48334833
assert_eq!(
48344834
parser(&pat).parse_escape(),
48354835
Ok(Primitive::Literal(ast::Literal {
@@ -4893,7 +4893,7 @@ bar
48934893
None => continue,
48944894
Some(c) => c,
48954895
};
4896-
let pat = format!(r"\U{:08x}", i);
4896+
let pat = format!(r"\U{i:08x}");
48974897
assert_eq!(
48984898
parser(&pat).parse_escape(),
48994899
Ok(Primitive::Literal(ast::Literal {

‎regex-syntax/src/ast/print.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,9 @@ impl<W: fmt::Write> Writer<W> {
199199
) -> fmt::Result {
200200
use crate::ast::RepetitionRange::*;
201201
match *ast {
202-
Exactly(x) => write!(self.wtr, "{{{}}}", x),
203-
AtLeast(x) => write!(self.wtr, "{{{},}}", x),
204-
Bounded(x, y) => write!(self.wtr, "{{{},{}}}", x, y),
202+
Exactly(x) => write!(self.wtr, "{{{x}}}"),
203+
AtLeast(x) => write!(self.wtr, "{{{x},}}"),
204+
Bounded(x, y) => write!(self.wtr, "{{{x},{y}}}"),
205205
}
206206
}
207207

‎regex-syntax/src/ast/visitor.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ impl<'a> core::fmt::Debug for ClassFrame<'a> {
488488
ClassFrame::BinaryLHS { .. } => "BinaryLHS",
489489
ClassFrame::BinaryRHS { .. } => "BinaryRHS",
490490
};
491-
write!(f, "{}", x)
491+
write!(f, "{x}")
492492
}
493493
}
494494

@@ -517,6 +517,6 @@ impl<'a> core::fmt::Debug for ClassInduct<'a> {
517517
}
518518
},
519519
};
520-
write!(f, "{}", x)
520+
write!(f, "{x}")
521521
}
522522
}

‎regex-syntax/src/debug.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ impl<'a> core::fmt::Debug for Bytes<'a> {
4242
let ch = match result {
4343
Ok(ch) => ch,
4444
Err(byte) => {
45-
write!(f, r"\x{:02x}", byte)?;
45+
write!(f, r"\x{byte:02x}")?;
4646
bytes = &bytes[1..];
4747
continue;
4848
}

‎regex-syntax/src/error.rs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ impl<'e, E: core::fmt::Display> core::fmt::Display for Formatter<'e, E> {
9393
let divider = repeat_char('~', 79);
9494

9595
writeln!(f, "regex parse error:")?;
96-
writeln!(f, "{}", divider)?;
96+
writeln!(f, "{divider}")?;
9797
let notated = spans.notate();
98-
write!(f, "{}", notated)?;
99-
writeln!(f, "{}", divider)?;
98+
write!(f, "{notated}")?;
99+
writeln!(f, "{divider}")?;
100100
// If we have error spans that cover multiple lines, then we just
101101
// note the line numbers.
102102
if !spans.multi_line.is_empty() {
@@ -116,7 +116,7 @@ impl<'e, E: core::fmt::Display> core::fmt::Display for Formatter<'e, E> {
116116
} else {
117117
writeln!(f, "regex parse error:")?;
118118
let notated = Spans::from_formatter(self).notate();
119-
write!(f, "{}", notated)?;
119+
write!(f, "{notated}")?;
120120
write!(f, "error: {}", self.err)?;
121121
}
122122
Ok(())

‎regex-syntax/src/hir/print.rs‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ impl<W: fmt::Write> Visitor for Writer<W> {
230230
HirKind::Capture(hir::Capture { ref name, .. }) => {
231231
self.wtr.write_str("(")?;
232232
if let Some(ref name) = *name {
233-
write!(self.wtr, "?P<{}>", name)?;
233+
write!(self.wtr, "?P<{name}>")?;
234234
}
235235
}
236236
// Why do this? Wrapping concats and alts in non-capturing groups
@@ -276,15 +276,15 @@ impl<W: fmt::Write> Visitor for Writer<W> {
276276
return Ok(());
277277
}
278278
(m, None) => {
279-
write!(self.wtr, "{{{},}}", m)?;
279+
write!(self.wtr, "{{{m},}}")?;
280280
}
281281
(m, Some(n)) if m == n => {
282-
write!(self.wtr, "{{{}}}", m)?;
282+
write!(self.wtr, "{{{m}}}")?;
283283
// a{m} and a{m}? are always exactly equivalent.
284284
return Ok(());
285285
}
286286
(m, Some(n)) => {
287-
write!(self.wtr, "{{{},{}}}", m, n)?;
287+
write!(self.wtr, "{{{m},{n}}}")?;
288288
}
289289
}
290290
if !x.greedy {
@@ -317,15 +317,15 @@ impl<W: fmt::Write> Writer<W> {
317317
if b <= 0x7F && !b.is_ascii_control() && !b.is_ascii_whitespace() {
318318
self.write_literal_char(char::try_from(b).unwrap())
319319
} else {
320-
write!(self.wtr, "(?-u:\\x{:02X})", b)
320+
write!(self.wtr, "(?-u:\\x{b:02X})")
321321
}
322322
}
323323

324324
fn write_literal_class_byte(&mut self, b: u8) -> fmt::Result {
325325
if b <= 0x7F && !b.is_ascii_control() && !b.is_ascii_whitespace() {
326326
self.write_literal_char(char::try_from(b).unwrap())
327327
} else {
328-
write!(self.wtr, "\\x{:02X}", b)
328+
write!(self.wtr, "\\x{b:02X}")
329329
}
330330
}
331331
}

‎regex-syntax/src/hir/translate.rs‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ impl HirFrame {
254254
match self {
255255
HirFrame::Expr(expr) => expr,
256256
HirFrame::Literal(lit) => Hir::literal(lit),
257-
_ => panic!("tried to unwrap expr from HirFrame, got: {:?}",self),
257+
_ => panic!("tried to unwrap expr from HirFrame, got: {self:?}"),
258258
}
259259
}
260260

@@ -291,8 +291,7 @@ impl HirFrame {
291291
HirFrame::Repetition => {}
292292
_ => {
293293
panic!(
294-
"tried to unwrap repetition from HirFrame, got: {:?}",
295-
self
294+
"tried to unwrap repetition from HirFrame, got: {self:?}"
296295
)
297296
}
298297
}
@@ -305,7 +304,7 @@ impl HirFrame {
305304
match self {
306305
HirFrame::Group { old_flags } => old_flags,
307306
_ => {
308-
panic!("tried to unwrap group from HirFrame, got: {:?}",self)
307+
panic!("tried to unwrap group from HirFrame, got: {self:?}")
309308
}
310309
}
311310
}
@@ -316,10 +315,7 @@ impl HirFrame {
316315
match self {
317316
HirFrame::AlternationBranch => {}
318317
_ => {
319-
panic!(
320-
"tried to unwrap alt pipe from HirFrame, got: {:?}",
321-
self
322-
)
318+
panic!("tried to unwrap alt pipe from HirFrame, got: {self:?}")
323319
}
324320
}
325321
}

‎regex-syntax/src/utf8.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ impl Utf8Sequence {
128128
Utf8Range::new(start[2], end[2]),
129129
Utf8Range::new(start[3], end[3]),
130130
]),
131-
n => unreachable!("invalid encoded length: {}", n),
131+
n => unreachable!("invalid encoded length: {n}"),
132132
}
133133
}
134134

@@ -203,7 +203,7 @@ impl fmt::Debug for Utf8Sequence {
203203
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
204204
use self::Utf8Sequence::*;
205205
match *self {
206-
One(ref r) => write!(f, "{:?}", r),
206+
One(ref r) => write!(f, "{r:?}"),
207207
Two(ref r) => write!(f, "{:?}{:?}", r[0], r[1]),
208208
Three(ref r) => write!(f, "{:?}{:?}{:?}", r[0], r[1], r[2]),
209209
Four(ref r) => {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /