Skip to content

Fix Clippy warnings: variables can be used directly in the format! string #639

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 16, 2025
Merged
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
2 changes: 1 addition & 1 deletion googletest/src/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub mod internal {
impl<T: ?Sized> FormatNonDebugFallback for FormatWrapper<'_, T> {
#[track_caller]
fn __googletest_write_expr_value(&self, output: &mut dyn Write, expr_label: &str) {
write!(output, "\n {} does not implement Debug,", expr_label)
write!(output, "\n {expr_label} does not implement Debug,")
.expect("Formatting to String should never fail");
}
}
Expand Down
2 changes: 1 addition & 1 deletion googletest/src/internal/description_renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ impl List {
match self.1 {
Decoration::None => "".into(),
Decoration::Bullet => "* ".into(),
Decoration::Enumerate => format!("{:>enumeration_padding$}. ", index).into(),
Decoration::Enumerate => format!("{index:>enumeration_padding$}. ").into(),
}
}

Expand Down
8 changes: 4 additions & 4 deletions googletest/src/internal/test_outcome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ enum Location {
impl Display for Location {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Location::Real(l) => write!(f, "{}", l),
Location::Fake { file, line, column } => write!(f, "{}:{}:{}", file, line, column),
Location::Real(l) => write!(f, "{l}"),
Location::Fake { file, line, column } => write!(f, "{file}:{line}:{column}"),
}
}
}
Expand Down Expand Up @@ -210,15 +210,15 @@ impl TestAssertionFailure {

pub(crate) fn log(&self) {
TestOutcome::fail_current_test();
println!("{}", self);
println!("{self}");
}
}

impl Display for TestAssertionFailure {
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
writeln!(f, "{}", self.description)?;
if let Some(custom_message) = &self.custom_message {
writeln!(f, "{}", custom_message)?;
writeln!(f, "{custom_message}")?;
}
writeln!(f, " at {}", self.location)
}
Expand Down
14 changes: 7 additions & 7 deletions googletest/src/matcher_support/match_matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,17 @@ pub mod internal {
) -> Option<Description> {
let actual_size = count_elements(actual);
match self {
Requirements::PerfectMatch if actual_size != expected_size => Some(
format!("which has size {} (expected {})", actual_size, expected_size).into(),
),
Requirements::PerfectMatch if actual_size != expected_size => {
Some(format!("which has size {actual_size} (expected {expected_size})").into())
}

Requirements::Superset if actual_size < expected_size => Some(
format!("which has size {} (expected at least {})", actual_size, expected_size)
format!("which has size {actual_size} (expected at least {expected_size})")
.into(),
),

Requirements::Subset if actual_size > expected_size => Some(
format!("which has size {} (expected at most {})", actual_size, expected_size)
format!("which has size {actual_size} (expected at most {expected_size})")
.into(),
),

Expand Down Expand Up @@ -342,13 +342,13 @@ pub mod internal {
let unmatchable_actual = self.unmatchable_actual();
let actual_idx = unmatchable_actual
.iter()
.map(|idx| format!("#{}", idx))
.map(|idx| format!("#{idx}"))
.collect::<Vec<_>>()
.join(", ");
let unmatchable_expected = self.unmatchable_expected();
let expected_idx = unmatchable_expected
.iter()
.map(|idx| format!("#{}", idx))
.map(|idx| format!("#{idx}"))
.collect::<Vec<_>>()
.join(", ");
match (unmatchable_actual.len(), unmatchable_expected.len()) {
Expand Down
2 changes: 1 addition & 1 deletion googletest/src/matcher_support/summarize_diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ mod tests {
write!(&mut text, "{}", collection.next().expect("Provided collection without elements"))
.unwrap();
for item in collection {
write!(&mut text, "\n{}", item).unwrap();
write!(&mut text, "\n{item}").unwrap();
}
text
}
Expand Down
2 changes: 1 addition & 1 deletion googletest/src/matchers/container_eq_matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ where
.nested(
self.expected
.into_iter()
.map(|element| format!("{:?}", element))
.map(|element| format!("{element:?}"))
.collect::<Description>()
.bullet_list(),
)
Expand Down
2 changes: 1 addition & 1 deletion googletest/src/matchers/contains_matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ where
fn explain_match(&self, actual: ContainerT) -> Description {
let count = self.count_matches(actual);
match (count, &self.count) {
(_, Some(_)) => format!("which contains {} matching elements", count).into(),
(_, Some(_)) => format!("which contains {count} matching elements").into(),
(0, None) => "which does not contain a matching element".into(),
(_, None) => "which contains a matching element".into(),
}
Expand Down
2 changes: 1 addition & 1 deletion googletest/src/matchers/display_matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ mod tests {
}
impl Display for Struct {
fn fmt(&self, f: &mut Formatter<'_>) -> std::result::Result<(), Error> {
write!(f, "{:?}", self)
write!(f, "{self:?}")
}
}
verify_that!(Struct { a: 123, b: 321 }, displays_as(eq("Struct { a: 123, b: 321 }")))?;
Expand Down
2 changes: 1 addition & 1 deletion googletest/src/matchers/eq_matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl<T: Debug, A: Debug + Copy + PartialEq<T>> Matcher<A> for EqMatcher<T> {

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

let diff = if is_multiline_string_debug(&actual_debug)
Expand Down
2 changes: 1 addition & 1 deletion googletest/tests/colorized_diff_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn build_text<T: Display>(mut collection: impl Iterator<Item = T>) -> String {
write!(&mut text, "{}", collection.next().expect("Provided collection without elements"))
.unwrap();
for item in collection {
write!(&mut text, "\n{}", item).unwrap();
write!(&mut text, "\n{item}").unwrap();
}
text
}
Expand Down
2 changes: 1 addition & 1 deletion googletest/tests/no_color_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn build_text<T: Display>(mut collection: impl Iterator<Item = T>) -> String {
write!(&mut text, "{}", collection.next().expect("Provided collection without elements"))
.unwrap();
for item in collection {
write!(&mut text, "\n{}", item).unwrap();
write!(&mut text, "\n{item}").unwrap();
}
text
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ mod tests {

impl std::fmt::Display for FakeError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", self)
write!(f, "{self:?}")
}
}
impl std::error::Error for FakeError {}
Expand Down