Skip to content

Commit 5e95cf6

Browse files
gribozavrcopybara-github
authored andcommitted
Fix Clippy warnings: variables can be used directly in the format! string
PiperOrigin-RevId: 759633816
1 parent 5bb14cc commit 5e95cf6

12 files changed

+21
-21
lines changed

googletest/src/fmt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pub mod internal {
4848
impl<T: ?Sized> FormatNonDebugFallback for FormatWrapper<'_, T> {
4949
#[track_caller]
5050
fn __googletest_write_expr_value(&self, output: &mut dyn Write, expr_label: &str) {
51-
write!(output, "\n {} does not implement Debug,", expr_label)
51+
write!(output, "\n {expr_label} does not implement Debug,")
5252
.expect("Formatting to String should never fail");
5353
}
5454
}

googletest/src/internal/description_renderer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ impl List {
130130
match self.1 {
131131
Decoration::None => "".into(),
132132
Decoration::Bullet => "* ".into(),
133-
Decoration::Enumerate => format!("{:>enumeration_padding$}. ", index).into(),
133+
Decoration::Enumerate => format!("{index:>enumeration_padding$}. ").into(),
134134
}
135135
}
136136

googletest/src/internal/test_outcome.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,8 @@ enum Location {
181181
impl Display for Location {
182182
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
183183
match self {
184-
Location::Real(l) => write!(f, "{}", l),
185-
Location::Fake { file, line, column } => write!(f, "{}:{}:{}", file, line, column),
184+
Location::Real(l) => write!(f, "{l}"),
185+
Location::Fake { file, line, column } => write!(f, "{file}:{line}:{column}"),
186186
}
187187
}
188188
}
@@ -210,15 +210,15 @@ impl TestAssertionFailure {
210210

211211
pub(crate) fn log(&self) {
212212
TestOutcome::fail_current_test();
213-
println!("{}", self);
213+
println!("{self}");
214214
}
215215
}
216216

217217
impl Display for TestAssertionFailure {
218218
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
219219
writeln!(f, "{}", self.description)?;
220220
if let Some(custom_message) = &self.custom_message {
221-
writeln!(f, "{}", custom_message)?;
221+
writeln!(f, "{custom_message}")?;
222222
}
223223
writeln!(f, " at {}", self.location)
224224
}

googletest/src/matcher_support/match_matrix.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,17 @@ pub mod internal {
4848
) -> Option<Description> {
4949
let actual_size = count_elements(actual);
5050
match self {
51-
Requirements::PerfectMatch if actual_size != expected_size => Some(
52-
format!("which has size {} (expected {})", actual_size, expected_size).into(),
53-
),
51+
Requirements::PerfectMatch if actual_size != expected_size => {
52+
Some(format!("which has size {actual_size} (expected {expected_size})").into())
53+
}
5454

5555
Requirements::Superset if actual_size < expected_size => Some(
56-
format!("which has size {} (expected at least {})", actual_size, expected_size)
56+
format!("which has size {actual_size} (expected at least {expected_size})")
5757
.into(),
5858
),
5959

6060
Requirements::Subset if actual_size > expected_size => Some(
61-
format!("which has size {} (expected at most {})", actual_size, expected_size)
61+
format!("which has size {actual_size} (expected at most {expected_size})")
6262
.into(),
6363
),
6464

@@ -342,13 +342,13 @@ pub mod internal {
342342
let unmatchable_actual = self.unmatchable_actual();
343343
let actual_idx = unmatchable_actual
344344
.iter()
345-
.map(|idx| format!("#{}", idx))
345+
.map(|idx| format!("#{idx}"))
346346
.collect::<Vec<_>>()
347347
.join(", ");
348348
let unmatchable_expected = self.unmatchable_expected();
349349
let expected_idx = unmatchable_expected
350350
.iter()
351-
.map(|idx| format!("#{}", idx))
351+
.map(|idx| format!("#{idx}"))
352352
.collect::<Vec<_>>()
353353
.join(", ");
354354
match (unmatchable_actual.len(), unmatchable_expected.len()) {

googletest/src/matcher_support/summarize_diff.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ mod tests {
444444
write!(&mut text, "{}", collection.next().expect("Provided collection without elements"))
445445
.unwrap();
446446
for item in collection {
447-
write!(&mut text, "\n{}", item).unwrap();
447+
write!(&mut text, "\n{item}").unwrap();
448448
}
449449
text
450450
}

googletest/src/matchers/container_eq_matcher.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ where
244244
.nested(
245245
self.expected
246246
.into_iter()
247-
.map(|element| format!("{:?}", element))
247+
.map(|element| format!("{element:?}"))
248248
.collect::<Description>()
249249
.bullet_list(),
250250
)

googletest/src/matchers/contains_matcher.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ where
106106
fn explain_match(&self, actual: ContainerT) -> Description {
107107
let count = self.count_matches(actual);
108108
match (count, &self.count) {
109-
(_, Some(_)) => format!("which contains {} matching elements", count).into(),
109+
(_, Some(_)) => format!("which contains {count} matching elements").into(),
110110
(0, None) => "which does not contain a matching element".into(),
111111
(_, None) => "which contains a matching element".into(),
112112
}

googletest/src/matchers/display_matcher.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ mod tests {
9595
}
9696
impl Display for Struct {
9797
fn fmt(&self, f: &mut Formatter<'_>) -> std::result::Result<(), Error> {
98-
write!(f, "{:?}", self)
98+
write!(f, "{self:?}")
9999
}
100100
}
101101
verify_that!(Struct { a: 123, b: 321 }, displays_as(eq("Struct { a: 123, b: 321 }")))?;

googletest/src/matchers/eq_matcher.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ impl<T: Debug, A: Debug + Copy + PartialEq<T>> Matcher<A> for EqMatcher<T> {
9797

9898
fn explain_match(&self, actual: A) -> Description {
9999
let expected_debug = format!("{:#?}", self.expected);
100-
let actual_debug = format!("{:#?}", actual);
100+
let actual_debug = format!("{actual:#?}");
101101
let description = Matcher::<A>::describe(self, self.matches(actual));
102102

103103
let diff = if is_multiline_string_debug(&actual_debug)

googletest/tests/colorized_diff_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ fn build_text<T: Display>(mut collection: impl Iterator<Item = T>) -> String {
2222
write!(&mut text, "{}", collection.next().expect("Provided collection without elements"))
2323
.unwrap();
2424
for item in collection {
25-
write!(&mut text, "\n{}", item).unwrap();
25+
write!(&mut text, "\n{item}").unwrap();
2626
}
2727
text
2828
}

googletest/tests/no_color_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ fn build_text<T: Display>(mut collection: impl Iterator<Item = T>) -> String {
2222
write!(&mut text, "{}", collection.next().expect("Provided collection without elements"))
2323
.unwrap();
2424
for item in collection {
25-
write!(&mut text, "\n{}", item).unwrap();
25+
write!(&mut text, "\n{item}").unwrap();
2626
}
2727
text
2828
}

integration_tests/src/failure_due_to_returned_error_with_line_numbers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ mod tests {
2424

2525
impl std::fmt::Display for FakeError {
2626
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
27-
write!(f, "{:?}", self)
27+
write!(f, "{self:?}")
2828
}
2929
}
3030
impl std::error::Error for FakeError {}

0 commit comments

Comments
 (0)