Skip to content

Commit

Permalink
Move format_push_string and format_collect to pedantic (#13894)
Browse files Browse the repository at this point in the history
Closes #11434 by moving `format_push_string` and `format_collect` to
pedantic.

changelog: Move `format_push_string` and `format_collect` to pedantic
  • Loading branch information
Centri3 authored Jan 28, 2025
2 parents 6a209cd + 87f7e21 commit e02c885
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
28 changes: 16 additions & 12 deletions clippy_dev/src/new_lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,9 @@ fn get_lint_file_contents(lint: &LintData<'_>, enable_msrv: bool) -> String {
let name_camel = to_camel_case(lint.name);
let name_upper = lint_name.to_uppercase();

result.push_str(&if enable_msrv {
formatdoc!(
if enable_msrv {
let _: fmt::Result = writedoc!(
result,
r"
use clippy_utils::msrvs::{{self, Msrv}};
use clippy_config::Conf;
Expand All @@ -265,22 +266,24 @@ fn get_lint_file_contents(lint: &LintData<'_>, enable_msrv: bool) -> String {
use rustc_session::impl_lint_pass;
"
)
);
} else {
formatdoc!(
let _: fmt::Result = writedoc!(
result,
r"
{pass_import}
use rustc_lint::{{{context_import}, {pass_type}}};
use rustc_session::declare_lint_pass;
"
)
});
);
}

let _: fmt::Result = writeln!(result, "{}", get_lint_declaration(&name_upper, category));

result.push_str(&if enable_msrv {
formatdoc!(
if enable_msrv {
let _: fmt::Result = writedoc!(
result,
r"
pub struct {name_camel} {{
msrv: Msrv,
Expand All @@ -301,16 +304,17 @@ fn get_lint_file_contents(lint: &LintData<'_>, enable_msrv: bool) -> String {
// TODO: Add MSRV level to `clippy_config/src/msrvs.rs` if needed.
// TODO: Update msrv config comment in `clippy_config/src/conf.rs`
"
)
);
} else {
formatdoc!(
let _: fmt::Result = writedoc!(
result,
r"
declare_lint_pass!({name_camel} => [{name_upper}]);
impl {pass_type}{pass_lifetimes} for {name_camel} {{}}
"
)
});
);
}

result
}
Expand Down
3 changes: 2 additions & 1 deletion clippy_lints/src/endian_bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use rustc_middle::lint::in_external_macro;
use rustc_middle::ty::Ty;
use rustc_session::declare_lint_pass;
use rustc_span::Symbol;
use std::fmt::Write;

declare_clippy_lint! {
/// ### What it does
Expand Down Expand Up @@ -184,7 +185,7 @@ fn maybe_lint_endian_bytes(cx: &LateContext<'_>, expr: &Expr<'_>, prefix: Prefix
help_str.push_str("either of ");
}

help_str.push_str(&format!("`{ty}::{}` ", lint.as_name(prefix)));
write!(help_str, "`{ty}::{}` ", lint.as_name(prefix)).unwrap();

if i != len && !only_one {
help_str.push_str("or ");
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/format_push_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ declare_clippy_lint! {
/// Detects cases where the result of a `format!` call is
/// appended to an existing `String`.
///
/// ### Why restrict this?
/// ### Why is this bad?
/// Introduces an extra, avoidable heap allocation.
///
/// ### Known problems
Expand All @@ -35,7 +35,7 @@ declare_clippy_lint! {
/// ```
#[clippy::version = "1.62.0"]
pub FORMAT_PUSH_STRING,
restriction,
pedantic,
"`format!(..)` appended to existing `String`"
}
declare_lint_pass!(FormatPushString => [FORMAT_PUSH_STRING]);
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/methods/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3518,7 +3518,7 @@ declare_clippy_lint! {
/// ```
#[clippy::version = "1.73.0"]
pub FORMAT_COLLECT,
perf,
pedantic,
"`format!`ing every element in a collection, then collecting the strings into a new `String`"
}

Expand Down

0 comments on commit e02c885

Please sign in to comment.