fix: remove unnecessary trailing commas in format strings

This PR makes the new comma-removing lint PR less noisy, allowing it focus only on the new functionality
This commit is contained in:
Yuri Astrakhan
2026-02-07 14:02:33 -05:00
parent 15e0ce9d69
commit 236dac8d0e
19 changed files with 23 additions and 23 deletions
+2 -2
View File
@@ -167,9 +167,9 @@ fn add_lint(lint: &LintData<'_>, enable_msrv: bool) -> io::Result<()> {
let camel_name = to_camel_case(lint.name);
let new_lint = if enable_msrv {
format!("Box::new(move |{ctor_arg}| Box::new({module_name}::{camel_name}::new(conf))),\n ",)
format!("Box::new(move |{ctor_arg}| Box::new({module_name}::{camel_name}::new(conf))),\n ")
} else {
format!("Box::new(|{ctor_arg}| Box::new({module_name}::{camel_name})),\n ",)
format!("Box::new(|{ctor_arg}| Box::new({module_name}::{camel_name})),\n ")
};
lib_rs.insert_str(comment_start, &new_lint);
@@ -100,7 +100,7 @@ fn check_table(cx: &LateContext<'_>, table: &DeTable<'_>, known_groups: &FxHashS
"to have lints override the group set `{}` to a lower priority",
group.as_ref()
),
format!("{{ level = {:?}, priority = {low_priority} }}", group_config.level,),
format!("{{ level = {:?}, priority = {low_priority} }}", group_config.level),
Applicability::MaybeIncorrect,
);
},
@@ -117,7 +117,7 @@ pub(super) fn check(
return;
}
format!("casting `{cast_from}` to `{cast_to}` may truncate the value{suffix}",)
format!("casting `{cast_from}` to `{cast_to}` may truncate the value{suffix}")
},
(ty::Adt(def, _), Some(to_nbits)) if def.is_enum() => {
@@ -91,7 +91,7 @@ pub fn check(cx: &LateContext<'_>, doc: &str, range: Range<usize>, fragments: &F
diag.span_suggestion_verbose(
this_fragment.span.shrink_to_hi(),
"add footnote definition",
format!("\n\n{label}: <!-- description -->", label = &doc[start..end],),
format!("\n\n{label}: <!-- description -->", label = &doc[start..end]),
Applicability::HasPlaceholders,
);
} else {
+1 -1
View File
@@ -337,7 +337,7 @@ fn check_missing_else(cx: &EarlyContext<'_>, first: &Expr, second: &Expr) {
else_span,
format!("this looks like {looks_like} but the `else` is missing"),
None,
format!("to remove this lint, add the missing `else` or add a new line before {next_thing}",),
format!("to remove this lint, add the missing `else` or add a new line before {next_thing}"),
);
}
}
+2 -2
View File
@@ -92,7 +92,7 @@ fn suggestion(
),
(
target.span(),
format!("{}<{}, S>", target.type_name(), target.type_arguments(),),
format!("{}<{}, S>", target.type_name(), target.type_arguments()),
),
];
suggestions.extend(vis.suggestions);
@@ -352,7 +352,7 @@ fn visit_expr(&mut self, e: &'tcx Expr<'_>) {
);
self.suggestions.insert(
e.span,
format!("{container_name}::with_capacity_and_hasher({arg_snippet}, Default::default())",),
format!("{container_name}::with_capacity_and_hasher({arg_snippet}, Default::default())"),
);
},
_ => {},
+1 -1
View File
@@ -173,7 +173,7 @@ fn handle(
expr.span,
format!("this pattern reimplements `{ty_name}::unwrap_or`"),
"replace with",
format!("{suggestion}.unwrap_or({reindented_or_body})",),
format!("{suggestion}.unwrap_or({reindented_or_body})"),
app,
);
}
@@ -187,7 +187,7 @@ pub(super) fn check_match<'tcx>(
diag.span_suggestion_verbose(
e.span,
"use `matches!` directly",
format!("{}matches!({snippet}, {pat_and_guard})", if b0 { "" } else { "!" },),
format!("{}matches!({snippet}, {pat_and_guard})", if b0 { "" } else { "!" }),
applicability,
);
},
+1 -1
View File
@@ -34,7 +34,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>, recv: &'tcx E
parent.span,
format!("called `.bytes().nth().unwrap()` on a `{caller_type}`"),
"try",
format!("{receiver}.as_bytes()[{n}]",),
format!("{receiver}.as_bytes()[{n}]"),
applicability,
);
} else {
+1 -1
View File
@@ -20,7 +20,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, method_span: Spa
cx,
INTO_ITER_ON_REF,
method_span,
format!("this `.into_iter()` call is equivalent to `.{method_name}()` and will not consume the `{kind}`",),
format!("this `.into_iter()` call is equivalent to `.{method_name}()` and will not consume the `{kind}`"),
"call directly",
method_name.to_string(),
Applicability::MachineApplicable,
+1 -1
View File
@@ -47,7 +47,7 @@ pub(super) fn check<'tcx>(
fold_span,
"usage of `Iterator::fold` on a type that implements `Try`",
"use `try_fold` instead",
format!("try_fold({init_snip}, {args_snip} ...)",),
format!("try_fold({init_snip}, {args_snip} ...)"),
Applicability::HasPlaceholders,
);
}
+1 -1
View File
@@ -19,7 +19,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, recv: &'
diag.span_suggestion(
expr.span,
"remove the call to `hash` or consider using",
format!("0_u8.hash({})", snippet(cx, arg.span, ".."),),
format!("0_u8.hash({})", snippet(cx, arg.span, "..")),
Applicability::MaybeIncorrect,
);
diag.note("the implementation of `Hash` for `()` is a no-op");
@@ -364,15 +364,15 @@ fn report_indexes(cx: &LateContext<'_>, map: UnindexMap<u64, Vec<IndexEntry<'_>>
// `v.len() < 5` and `v.len() <= 5` does nothing in terms of bounds checks.
// The user probably meant `v.len() > 5`
LengthComparison::LengthLessThanInt | LengthComparison::LengthLessThanOrEqualInt => {
Some(format!("assert!({slice_str}.len() > {highest_index})",))
Some(format!("assert!({slice_str}.len() > {highest_index})"))
},
// `5 < v.len()` == `v.len() > 5`
LengthComparison::IntLessThanLength if asserted_len < highest_index => {
Some(format!("assert!({slice_str}.len() > {highest_index})",))
Some(format!("assert!({slice_str}.len() > {highest_index})"))
},
// `5 <= v.len() == `v.len() >= 5`
LengthComparison::IntLessThanOrEqualLength if asserted_len <= highest_index => {
Some(format!("assert!({slice_str}.len() > {highest_index})",))
Some(format!("assert!({slice_str}.len() > {highest_index})"))
},
// `highest_index` here is rather a length, so we need to add 1 to it
LengthComparison::LengthEqualInt if asserted_len < highest_index + 1 => match macro_call {
@@ -97,7 +97,7 @@ fn check_item(&mut self, cx: &LateContext<'_>, item: &Item<'_>) {
span_without_semi,
"this import should be renamed",
"try",
format!("{import} as {name}",),
format!("{import} as {name}"),
Applicability::MachineApplicable,
);
}
+1 -1
View File
@@ -32,7 +32,7 @@ pub(super) fn check<'tcx>(
expr.span,
"comparing with null is better expressed by the `.is_null()` method",
"try",
format!("{invert}{non_null_path_snippet}.is_null()",),
format!("{invert}{non_null_path_snippet}.is_null()"),
applicability,
);
true
+1 -1
View File
@@ -109,7 +109,7 @@ fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'_>) {
diag.span_suggestion(
stmt.span,
"try",
format!("let {name}{tyopt} = {initref};", name = snippet(cx, name.span, ".."),),
format!("let {name}{tyopt} = {initref};", name = snippet(cx, name.span, "..")),
app,
);
},
+1 -1
View File
@@ -56,7 +56,7 @@ fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
expr.span,
"constant division of `0.0` with `0.0` will always result in NaN",
None,
format!("consider using `{float_type}::NAN` if you would like a constant representing NaN",),
format!("consider using `{float_type}::NAN` if you would like a constant representing NaN"),
);
}
}
+1 -1
View File
@@ -168,7 +168,7 @@ fn assign_expr_suggestion(
let indent = snippet_indent(cx, outer_expr.span).unwrap_or_default();
let var_name = snippet(cx, assign_expr_span.source_callsite(), "..");
if needs_curly {
format!("{{\n {indent}{inner_expr};\n {indent}{var_name} = {vec_str}[] as {return_type}\n{indent}}}",)
format!("{{\n {indent}{inner_expr};\n {indent}{var_name} = {vec_str}[] as {return_type}\n{indent}}}")
} else {
format!("{inner_expr};\n{indent}{var_name} = {vec_str}[] as {return_type}")
}
+1 -1
View File
@@ -91,7 +91,7 @@ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.crate_name, self.major, self.minor, self.patch,
)?;
if let Some(ref commit_hash) = self.commit_hash {
write!(f, ", commit_hash: \"{}\"", commit_hash.trim(),)?;
write!(f, ", commit_hash: \"{}\"", commit_hash.trim())?;
}
if let Some(ref commit_date) = self.commit_date {
write!(f, ", commit_date: \"{}\"", commit_date.trim())?;