Skip to content

Commit 98f57ac

Browse files
Use captured identifiers in format strings for tests
This is only used in test files, so I don't have to bump the MSRV. This feature was only stabilized in 1.58.
1 parent a4a780b commit 98f57ac

File tree

3 files changed

+13
-33
lines changed

3 files changed

+13
-33
lines changed

src/float/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ fn non_standard_suffixes() {
175175

176176
let lit = match Literal::parse(input) {
177177
Ok(Literal::Float(f)) => f,
178-
other => panic!("Expected float literal, but got {:?} for '{}'", other, input),
178+
other => panic!("Expected float literal, but got {other:?} for '{input}'"),
179179
};
180180
assert_eq!(lit.integer_part(), integer_part);
181181
assert_eq!(lit.fractional_part(), fractional_part);

src/integer/tests.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,8 @@ fn check<T: FromIntegerLiteral + PartialEq + Debug + Display>(
3636
.value::<T>()
3737
.unwrap_or_else(|| panic!("unexpected overflow in `IntegerLit::value` for `{}`", input));
3838
if actual_value != value {
39-
panic!(
40-
"Parsing int literal `{}` should give value `{}`, but actually resulted in `{}`",
41-
input,
42-
value,
43-
actual_value,
44-
);
39+
panic!("Parsing int literal `{input}` should give value `{value}`, \
40+
but actually resulted in `{actual_value}`");
4541
}
4642
}
4743

src/test_util.rs

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,17 @@ pub(crate) fn assert_parse_ok_eq<T: PartialEq + Debug + Display>(
1313
match result {
1414
Ok(actual) if actual == expected => {
1515
if actual.to_string() != input {
16-
panic!(
17-
"formatting does not yield original input `{}`: {:?}",
18-
input,
19-
actual,
20-
);
16+
panic!("formatting does not yield original input `{input}`: {actual:?}");
2117
}
2218
}
2319
Ok(actual) => {
24-
panic!(
25-
"unexpected parsing result (with `{}`) for `{}`:\nactual: {:?}\nexpected: {:?}",
26-
parse_method,
27-
input,
28-
actual,
29-
expected,
30-
);
20+
panic!("unexpected parsing result (with `{parse_method}`) for `{input}`:\n\
21+
actual: {actual:?}\n\
22+
expected: {expected:?}");
3123
}
3224
Err(e) => {
33-
panic!(
34-
"expected `{}` to be parsed (with `{}`) successfully, but it failed: {:?}",
35-
input,
36-
parse_method,
37-
e,
38-
);
25+
panic!("expected `{input}` to be parsed (with `{parse_method}`) successfully, \
26+
but it failed: {e:?}");
3927
}
4028
}
4129
}
@@ -71,17 +59,13 @@ where
7159

7260
match T::try_from(pm_lit) {
7361
Err(e) => {
74-
panic!("Trying to convert proc_macro2::Literal to {} results in error: {}", t_name, e);
62+
panic!("Trying to convert proc_macro2::Literal to {t_name} results in error: {e}");
7563
}
7664
Ok(res) => {
7765
if res != ours {
78-
panic!(
79-
"Converting proc_macro2::Literal to {} has unexpected result:\
80-
\nactual: {:?}\nexpected: {:?}",
81-
t_name,
82-
res,
83-
ours,
84-
);
66+
panic!("Converting proc_macro2::Literal to {t_name} has unexpected result:\n\
67+
actual: {res:?}\n\
68+
expected: {ours:?}");
8569
}
8670
}
8771
}

0 commit comments

Comments
 (0)