Skip to content

pre-fallout: Apply uninlined_format-args lint #9525

New issue

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

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

Already on GitHub? # to your account

Merged
merged 3 commits into from
Sep 23, 2022
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 clippy_dev/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fn main() {
matches.contains_id("msrv"),
) {
Ok(_) => update_lints::update(update_lints::UpdateMode::Change),
Err(e) => eprintln!("Unable to create lint: {}", e),
Err(e) => eprintln!("Unable to create lint: {e}"),
}
},
Some(("setup", sub_command)) => match sub_command.subcommand() {
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/approx_const.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl ApproxConstant {
cx,
APPROX_CONSTANT,
e.span,
&format!("approximate value of `{}::consts::{}` found", module, &name),
&format!("approximate value of `{module}::consts::{}` found", &name),
None,
"consider using the constant directly",
);
Expand Down Expand Up @@ -126,7 +126,7 @@ fn is_approx_const(constant: f64, value: &str, min_digits: usize) -> bool {
// The value is a truncated constant
true
} else {
let round_const = format!("{:.*}", value.len() - 2, constant);
let round_const = format!("{constant:.*}", value.len() - 2);
value == round_const
}
}
2 changes: 1 addition & 1 deletion clippy_lints/src/asm_syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fn check_expr_asm_syntax(lint: &'static Lint, cx: &EarlyContext<'_>, expr: &Expr
cx,
lint,
expr.span,
&format!("{} x86 assembly syntax used", style),
&format!("{style} x86 assembly syntax used"),
None,
&format!("use {} x86 assembly syntax", !style),
);
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/assertions_on_constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ impl<'tcx> LateLintPass<'tcx> for AssertionsOnConstants {
cx,
ASSERTIONS_ON_CONSTANTS,
macro_call.span,
&format!("`assert!(false{})` should probably be replaced", assert_arg),
&format!("`assert!(false{assert_arg})` should probably be replaced"),
None,
&format!("use `panic!({})` or `unreachable!({0})`", panic_arg),
&format!("use `panic!({panic_arg})` or `unreachable!({panic_arg})`"),
);
}
}
Expand Down
10 changes: 4 additions & 6 deletions clippy_lints/src/assertions_on_result_states.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,8 @@ impl<'tcx> LateLintPass<'tcx> for AssertionsOnResultStates {
"called `assert!` with `Result::is_ok`",
"replace with",
format!(
"{}.unwrap(){}",
snippet_with_context(cx, recv.span, condition.span.ctxt(), "..", &mut app).0,
semicolon
"{}.unwrap(){semicolon}",
snippet_with_context(cx, recv.span, condition.span.ctxt(), "..", &mut app).0
),
app,
);
Expand All @@ -84,9 +83,8 @@ impl<'tcx> LateLintPass<'tcx> for AssertionsOnResultStates {
"called `assert!` with `Result::is_err`",
"replace with",
format!(
"{}.unwrap_err(){}",
snippet_with_context(cx, recv.span, condition.span.ctxt(), "..", &mut app).0,
semicolon
"{}.unwrap_err(){semicolon}",
snippet_with_context(cx, recv.span, condition.span.ctxt(), "..", &mut app).0
),
app,
);
Expand Down
7 changes: 2 additions & 5 deletions clippy_lints/src/attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -541,10 +541,7 @@ fn check_attrs(cx: &LateContext<'_>, span: Span, name: Symbol, attrs: &[Attribut
cx,
INLINE_ALWAYS,
attr.span,
&format!(
"you have declared `#[inline(always)]` on `{}`. This is usually a bad idea",
name
),
&format!("you have declared `#[inline(always)]` on `{name}`. This is usually a bad idea"),
);
}
}
Expand Down Expand Up @@ -720,7 +717,7 @@ fn check_mismatched_target_os(cx: &EarlyContext<'_>, attr: &Attribute) {
let mut unix_suggested = false;

for (os, span) in mismatched {
let sugg = format!("target_os = \"{}\"", os);
let sugg = format!("target_os = \"{os}\"");
diag.span_suggestion(span, "try", sugg, Applicability::MaybeIncorrect);

if !unix_suggested && is_unix(os) {
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/bool_assert_comparison.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ impl<'tcx> LateLintPass<'tcx> for BoolAssertComparison {
cx,
BOOL_ASSERT_COMPARISON,
macro_call.span,
&format!("used `{}!` with a literal bool", macro_name),
&format!("used `{macro_name}!` with a literal bool"),
"replace it with",
format!("{}!(..)", non_eq_mac),
format!("{non_eq_mac}!(..)"),
Applicability::MaybeIncorrect,
);
}
Expand Down
5 changes: 2 additions & 3 deletions clippy_lints/src/booleans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,8 @@ fn simplify_not(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option<String> {
}
.and_then(|op| {
Some(format!(
"{}{}{}",
"{}{op}{}",
snippet_opt(cx, lhs.span)?,
op,
snippet_opt(cx, rhs.span)?
))
})
Expand All @@ -285,7 +284,7 @@ fn simplify_not(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option<String> {
let path: &str = path.ident.name.as_str();
a == path
})
.and_then(|(_, neg_method)| Some(format!("{}.{}()", snippet_opt(cx, receiver.span)?, neg_method)))
.and_then(|(_, neg_method)| Some(format!("{}.{neg_method}()", snippet_opt(cx, receiver.span)?)))
},
_ => None,
}
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/cargo/common_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub(super) fn check(cx: &LateContext<'_>, metadata: &Metadata, ignore_publish: b
}

fn missing_warning(cx: &LateContext<'_>, package: &cargo_metadata::Package, field: &str) {
let message = format!("package `{}` is missing `{}` metadata", package.name, field);
let message = format!("package `{}` is missing `{field}` metadata", package.name);
span_lint(cx, CARGO_COMMON_METADATA, DUMMY_SP, &message);
}

Expand Down
4 changes: 1 addition & 3 deletions clippy_lints/src/cargo/feature_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,8 @@ fn lint(cx: &LateContext<'_>, feature: &str, substring: &str, is_prefix: bool) {
},
DUMMY_SP,
&format!(
"the \"{}\" {} in the feature name \"{}\" is {}",
substring,
"the \"{substring}\" {} in the feature name \"{feature}\" is {}",
if is_prefix { "prefix" } else { "suffix" },
feature,
if is_negative { "negative" } else { "redundant" }
),
None,
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/cargo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ impl LateLintPass<'_> for Cargo {
},
Err(e) => {
for lint in NO_DEPS_LINTS {
span_lint(cx, lint, DUMMY_SP, &format!("could not read cargo metadata: {}", e));
span_lint(cx, lint, DUMMY_SP, &format!("could not read cargo metadata: {e}"));
}
},
}
Expand All @@ -212,7 +212,7 @@ impl LateLintPass<'_> for Cargo {
},
Err(e) => {
for lint in WITH_DEPS_LINTS {
span_lint(cx, lint, DUMMY_SP, &format!("could not read cargo metadata: {}", e));
span_lint(cx, lint, DUMMY_SP, &format!("could not read cargo metadata: {e}"));
}
},
}
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/cargo/multiple_crate_versions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub(super) fn check(cx: &LateContext<'_>, metadata: &Metadata) {
cx,
MULTIPLE_CRATE_VERSIONS,
DUMMY_SP,
&format!("multiple versions for dependency `{}`: {}", name, versions),
&format!("multiple versions for dependency `{name}`: {versions}"),
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/casts/borrow_as_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub(super) fn check<'tcx>(
expr.span,
"borrow as raw pointer",
"try",
format!("{}::ptr::{}!({})", core_or_std, macro_name, snip),
format!("{core_or_std}::ptr::{macro_name}!({snip})"),
Applicability::MachineApplicable,
);
}
Expand Down
12 changes: 3 additions & 9 deletions clippy_lints/src/casts/cast_lossless.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,9 @@ pub(super) fn check(
);

let message = if cast_from.is_bool() {
format!(
"casting `{0:}` to `{1:}` is more cleanly stated with `{1:}::from(_)`",
cast_from, cast_to
)
format!("casting `{cast_from:}` to `{cast_to:}` is more cleanly stated with `{cast_to:}::from(_)`")
} else {
format!(
"casting `{}` to `{}` may become silently lossy if you later change the type",
cast_from, cast_to
)
format!("casting `{cast_from}` to `{cast_to}` may become silently lossy if you later change the type")
};

span_lint_and_sugg(
Expand All @@ -58,7 +52,7 @@ pub(super) fn check(
expr.span,
&message,
"try",
format!("{}::from({})", cast_to, sugg),
format!("{cast_to}::from({sugg})"),
applicability,
);
}
Expand Down
16 changes: 5 additions & 11 deletions clippy_lints/src/casts/cast_possible_truncation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>,
return;
}

format!(
"casting `{}` to `{}` may truncate the value{}",
cast_from, cast_to, suffix,
)
format!("casting `{cast_from}` to `{cast_to}` may truncate the value{suffix}",)
},

(ty::Adt(def, _), true) if def.is_enum() => {
Expand Down Expand Up @@ -142,20 +139,17 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>,
CAST_ENUM_TRUNCATION,
expr.span,
&format!(
"casting `{}::{}` to `{}` will truncate the value{}",
cast_from, variant.name, cast_to, suffix,
"casting `{cast_from}::{}` to `{cast_to}` will truncate the value{suffix}",
variant.name,
),
);
return;
}
format!(
"casting `{}` to `{}` may truncate the value{}",
cast_from, cast_to, suffix,
)
format!("casting `{cast_from}` to `{cast_to}` may truncate the value{suffix}",)
},

(ty::Float(_), true) => {
format!("casting `{}` to `{}` may truncate the value", cast_from, cast_to)
format!("casting `{cast_from}` to `{cast_to}` may truncate the value")
},

(ty::Float(FloatTy::F64), false) if matches!(cast_to.kind(), &ty::Float(FloatTy::F32)) => {
Expand Down
5 changes: 1 addition & 4 deletions clippy_lints/src/casts/cast_possible_wrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_from: Ty<'_>, ca
cx,
CAST_POSSIBLE_WRAP,
expr.span,
&format!(
"casting `{}` to `{}` may wrap around the value{}",
cast_from, cast_to, suffix,
),
&format!("casting `{cast_from}` to `{cast_to}` may wrap around the value{suffix}",),
);
}
}
4 changes: 1 addition & 3 deletions clippy_lints/src/casts/cast_ptr_alignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ fn lint_cast_ptr_alignment<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>, cast_f
CAST_PTR_ALIGNMENT,
expr.span,
&format!(
"casting from `{}` to a more-strictly-aligned pointer (`{}`) ({} < {} bytes)",
cast_from,
cast_to,
"casting from `{cast_from}` to a more-strictly-aligned pointer (`{cast_to}`) ({} < {} bytes)",
from_layout.align.abi.bytes(),
to_layout.align.abi.bytes(),
),
Expand Down
5 changes: 1 addition & 4 deletions clippy_lints/src/casts/cast_sign_loss.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_op: &Expr<'_>, c
cx,
CAST_SIGN_LOSS,
expr.span,
&format!(
"casting `{}` to `{}` may lose the sign of the value",
cast_from, cast_to
),
&format!("casting `{cast_from}` to `{cast_to}` may lose the sign of the value"),
);
}
}
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/casts/cast_slice_different_sizes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'tcx>, msrv: Optio
CAST_SLICE_DIFFERENT_SIZES,
expr.span,
&format!(
"casting between raw pointers to `[{}]` (element size {}) and `[{}]` (element size {}) does not adjust the count",
start_ty.ty, from_size, end_ty.ty, to_size,
"casting between raw pointers to `[{}]` (element size {from_size}) and `[{}]` (element size {to_size}) does not adjust the count",
start_ty.ty, end_ty.ty,
),
|diag| {
let ptr_snippet = source::snippet(cx, left_cast.span, "..");
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/casts/char_lit_as_u8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>) {
diag.span_suggestion(
expr.span,
"use a byte literal instead",
format!("b{}", snippet),
format!("b{snippet}"),
applicability,
);
}
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/casts/fn_to_numeric_cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>,
cx,
FN_TO_NUMERIC_CAST,
expr.span,
&format!("casting function pointer `{}` to `{}`", from_snippet, cast_to),
&format!("casting function pointer `{from_snippet}` to `{cast_to}`"),
"try",
format!("{} as usize", from_snippet),
format!("{from_snippet} as usize"),
applicability,
);
}
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/casts/fn_to_numeric_cast_any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>,
cx,
FN_TO_NUMERIC_CAST_ANY,
expr.span,
&format!("casting function pointer `{}` to `{}`", from_snippet, cast_to),
&format!("casting function pointer `{from_snippet}` to `{cast_to}`"),
"did you mean to invoke the function?",
format!("{}() as {}", from_snippet, cast_to),
format!("{from_snippet}() as {cast_to}"),
applicability,
);
},
Expand Down
7 changes: 2 additions & 5 deletions clippy_lints/src/casts/fn_to_numeric_cast_with_truncation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,9 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>,
cx,
FN_TO_NUMERIC_CAST_WITH_TRUNCATION,
expr.span,
&format!(
"casting function pointer `{}` to `{}`, which truncates the value",
from_snippet, cast_to
),
&format!("casting function pointer `{from_snippet}` to `{cast_to}`, which truncates the value"),
"try",
format!("{} as usize", from_snippet),
format!("{from_snippet} as usize"),
applicability,
);
}
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/casts/ptr_as_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, msrv: Option<RustcVer
let turbofish = match &cast_to_hir_ty.kind {
TyKind::Infer => Cow::Borrowed(""),
TyKind::Ptr(mut_ty) if matches!(mut_ty.ty.kind, TyKind::Infer) => Cow::Borrowed(""),
_ => Cow::Owned(format!("::<{}>", to_pointee_ty)),
_ => Cow::Owned(format!("::<{to_pointee_ty}>")),
};
span_lint_and_sugg(
cx,
PTR_AS_PTR,
expr.span,
"`as` casting between raw pointers without changing its mutability",
"try `pointer::cast`, a safer alternative",
format!("{}.cast{}()", cast_expr_sugg.maybe_par(), turbofish),
format!("{}.cast{turbofish}()", cast_expr_sugg.maybe_par()),
applicability,
);
}
Expand Down
9 changes: 3 additions & 6 deletions clippy_lints/src/casts/unnecessary_cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,7 @@ pub(super) fn check<'tcx>(
cx,
UNNECESSARY_CAST,
expr.span,
&format!(
"casting to the same type is unnecessary (`{}` -> `{}`)",
cast_from, cast_to
),
&format!("casting to the same type is unnecessary (`{cast_from}` -> `{cast_to}`)"),
"try",
literal_str,
Applicability::MachineApplicable,
Expand All @@ -101,9 +98,9 @@ fn lint_unnecessary_cast(cx: &LateContext<'_>, expr: &Expr<'_>, literal_str: &st
cx,
UNNECESSARY_CAST,
expr.span,
&format!("casting {} literal to `{}` is unnecessary", literal_kind_name, cast_to),
&format!("casting {literal_kind_name} literal to `{cast_to}` is unnecessary"),
"try",
format!("{}_{}", matchless.trim_end_matches('.'), cast_to),
format!("{}_{cast_to}", matchless.trim_end_matches('.')),
Applicability::MachineApplicable,
);
}
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/checked_conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl<'tcx> LateLintPass<'tcx> for CheckedConversions {
item.span,
"checked cast can be simplified",
"try",
format!("{}::try_from({}).is_ok()", to_type, snippet),
format!("{to_type}::try_from({snippet}).is_ok()"),
applicability,
);
}
Expand Down
Loading