Skip to content

Commit e02c885

Browse files
authored
Move format_push_string and format_collect to pedantic (rust-lang#13894)
Closes rust-lang#11434 by moving `format_push_string` and `format_collect` to pedantic. changelog: Move `format_push_string` and `format_collect` to pedantic
2 parents 6a209cd + 87f7e21 commit e02c885

File tree

4 files changed

+21
-16
lines changed

4 files changed

+21
-16
lines changed

clippy_dev/src/new_lint.rs

+16-12
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,9 @@ fn get_lint_file_contents(lint: &LintData<'_>, enable_msrv: bool) -> String {
255255
let name_camel = to_camel_case(lint.name);
256256
let name_upper = lint_name.to_uppercase();
257257

258-
result.push_str(&if enable_msrv {
259-
formatdoc!(
258+
if enable_msrv {
259+
let _: fmt::Result = writedoc!(
260+
result,
260261
r"
261262
use clippy_utils::msrvs::{{self, Msrv}};
262263
use clippy_config::Conf;
@@ -265,22 +266,24 @@ fn get_lint_file_contents(lint: &LintData<'_>, enable_msrv: bool) -> String {
265266
use rustc_session::impl_lint_pass;
266267
267268
"
268-
)
269+
);
269270
} else {
270-
formatdoc!(
271+
let _: fmt::Result = writedoc!(
272+
result,
271273
r"
272274
{pass_import}
273275
use rustc_lint::{{{context_import}, {pass_type}}};
274276
use rustc_session::declare_lint_pass;
275277
276278
"
277-
)
278-
});
279+
);
280+
}
279281

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

282-
result.push_str(&if enable_msrv {
283-
formatdoc!(
284+
if enable_msrv {
285+
let _: fmt::Result = writedoc!(
286+
result,
284287
r"
285288
pub struct {name_camel} {{
286289
msrv: Msrv,
@@ -301,16 +304,17 @@ fn get_lint_file_contents(lint: &LintData<'_>, enable_msrv: bool) -> String {
301304
// TODO: Add MSRV level to `clippy_config/src/msrvs.rs` if needed.
302305
// TODO: Update msrv config comment in `clippy_config/src/conf.rs`
303306
"
304-
)
307+
);
305308
} else {
306-
formatdoc!(
309+
let _: fmt::Result = writedoc!(
310+
result,
307311
r"
308312
declare_lint_pass!({name_camel} => [{name_upper}]);
309313
310314
impl {pass_type}{pass_lifetimes} for {name_camel} {{}}
311315
"
312-
)
313-
});
316+
);
317+
}
314318

315319
result
316320
}

clippy_lints/src/endian_bytes.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use rustc_middle::lint::in_external_macro;
77
use rustc_middle::ty::Ty;
88
use rustc_session::declare_lint_pass;
99
use rustc_span::Symbol;
10+
use std::fmt::Write;
1011

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

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

189190
if i != len && !only_one {
190191
help_str.push_str("or ");

clippy_lints/src/format_push_string.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ declare_clippy_lint! {
1111
/// Detects cases where the result of a `format!` call is
1212
/// appended to an existing `String`.
1313
///
14-
/// ### Why restrict this?
14+
/// ### Why is this bad?
1515
/// Introduces an extra, avoidable heap allocation.
1616
///
1717
/// ### Known problems
@@ -35,7 +35,7 @@ declare_clippy_lint! {
3535
/// ```
3636
#[clippy::version = "1.62.0"]
3737
pub FORMAT_PUSH_STRING,
38-
restriction,
38+
pedantic,
3939
"`format!(..)` appended to existing `String`"
4040
}
4141
declare_lint_pass!(FormatPushString => [FORMAT_PUSH_STRING]);

clippy_lints/src/methods/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3518,7 +3518,7 @@ declare_clippy_lint! {
35183518
/// ```
35193519
#[clippy::version = "1.73.0"]
35203520
pub FORMAT_COLLECT,
3521-
perf,
3521+
pedantic,
35223522
"`format!`ing every element in a collection, then collecting the strings into a new `String`"
35233523
}
35243524

0 commit comments

Comments
 (0)