Skip to content

Commit 479491e

Browse files
committed
Auto merge of #13130 - nyurik:ref-lints, r=Centri3
Avoid ref when using format! Clean up a few minor refs in `format!` macro, as it has a performance cost. Apparently the compiler is unable to inline `format!("{}", &variable)`, and does a run-time double-reference instead (format macro already does one level referencing). Inlining format args prevents accidental `&` misuse. See also rust-lang/rust#112156 changelog: none
2 parents 3504145 + 266abf3 commit 479491e

File tree

6 files changed

+8
-8
lines changed

6 files changed

+8
-8
lines changed

clippy_lints/src/approx_const.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ impl ApproxConstant {
9797
cx,
9898
APPROX_CONSTANT,
9999
e.span,
100-
format!("approximate value of `{module}::consts::{}` found", &name),
100+
format!("approximate value of `{module}::consts::{name}` found"),
101101
None,
102102
"consider using the constant directly",
103103
);

clippy_lints/src/default.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ impl<'tcx> LateLintPass<'tcx> for Default {
221221
.map(ToString::to_string)
222222
.collect::<Vec<_>>()
223223
.join(", ");
224-
format!("{adt_def_ty_name}::<{}>", &tys_str)
224+
format!("{adt_def_ty_name}::<{tys_str}>")
225225
} else {
226226
binding_type.to_string()
227227
};

clippy_lints/src/methods/open_options.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ fn check_open_options(cx: &LateContext<'_>, settings: &[(OpenOption, Argument, S
151151
cx,
152152
NONSENSICAL_OPEN_OPTIONS,
153153
prev_span,
154-
format!("the method `{}` is called more than once", &option),
154+
format!("the method `{option}` is called more than once"),
155155
);
156156
}
157157
}

clippy_lints/src/methods/wrong_self_convention.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ pub(super) fn check<'tcx>(
127127
.collect::<Vec<_>>()
128128
.join(" and ");
129129

130-
format!("methods with the following characteristics: ({})", &s)
130+
format!("methods with the following characteristics: ({s})")
131131
} else {
132132
format!("methods called {}", &conventions[0])
133133
}

clippy_lints/src/no_effect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ fn check_unnecessary_operation(cx: &LateContext<'_>, stmt: &Stmt<'_>) {
273273
}
274274
let snippet =
275275
if let (Some(arr), Some(func)) = (snippet_opt(cx, reduced[0].span), snippet_opt(cx, reduced[1].span)) {
276-
format!("assert!({}.len() > {});", &arr, &func)
276+
format!("assert!({arr}.len() > {func});")
277277
} else {
278278
return;
279279
};

clippy_lints/src/types/borrowed_box.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@ pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, lt: &Lifetime, m
4848
let inner_snippet = snippet(cx, inner.span, "..");
4949
let suggestion = match &inner.kind {
5050
TyKind::TraitObject(bounds, lt_bound, _) if bounds.len() > 1 || !lt_bound.is_elided() => {
51-
format!("&{ltopt}({})", &inner_snippet)
51+
format!("&{ltopt}({inner_snippet})")
5252
},
5353
TyKind::Path(qpath)
5454
if get_bounds_if_impl_trait(cx, qpath, inner.hir_id)
5555
.map_or(false, |bounds| bounds.len() > 1) =>
5656
{
57-
format!("&{ltopt}({})", &inner_snippet)
57+
format!("&{ltopt}({inner_snippet})")
5858
},
59-
_ => format!("&{ltopt}{}", &inner_snippet),
59+
_ => format!("&{ltopt}{inner_snippet}"),
6060
};
6161
span_lint_and_sugg(
6262
cx,

0 commit comments

Comments
 (0)