Skip to content

Commit 4dd22c7

Browse files
committed
Migrate write.rs to a late pass
1 parent 32fa80d commit 4dd22c7

33 files changed

+552
-1270
lines changed

clippy_lints/src/format.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@ impl<'tcx> LateLintPass<'tcx> for UselessFormat {
7171
let value = arg.param.value;
7272
if_chain! {
7373
if format_args.format_string.parts == [kw::Empty];
74+
if arg.format.is_default();
7475
if match cx.typeck_results().expr_ty(value).peel_refs().kind() {
7576
ty::Adt(adt, _) => cx.tcx.is_diagnostic_item(sym::String, adt.did()),
7677
ty::Str => true,
7778
_ => false,
7879
};
79-
if !arg.format.has_string_formatting();
8080
then {
8181
let is_new_string = match value.kind {
8282
ExprKind::Binary(..) => true,

clippy_lints/src/format_args.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl<'tcx> LateLintPass<'tcx> for FormatArgs {
7777
if let ExpnKind::Macro(_, name) = outermost_expn_data.kind;
7878
then {
7979
for arg in &format_args.args {
80-
if arg.format.has_string_formatting() {
80+
if !arg.format.is_default() {
8181
continue;
8282
}
8383
if is_aliased(&format_args, arg.param.value.hir_id) {

clippy_lints/src/lib.register_all.rs

-1
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,6 @@ store.register_group(true, "clippy::all", Some("clippy_all"), vec![
352352
LintId::of(useless_conversion::USELESS_CONVERSION),
353353
LintId::of(vec::USELESS_VEC),
354354
LintId::of(vec_init_then_push::VEC_INIT_THEN_PUSH),
355-
LintId::of(write::POSITIONAL_NAMED_FORMAT_PARAMETERS),
356355
LintId::of(write::PRINTLN_EMPTY_STRING),
357356
LintId::of(write::PRINT_LITERAL),
358357
LintId::of(write::PRINT_WITH_NEWLINE),

clippy_lints/src/lib.register_lints.rs

-1
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,6 @@ store.register_lints(&[
595595
vec_init_then_push::VEC_INIT_THEN_PUSH,
596596
wildcard_imports::ENUM_GLOB_USE,
597597
wildcard_imports::WILDCARD_IMPORTS,
598-
write::POSITIONAL_NAMED_FORMAT_PARAMETERS,
599598
write::PRINTLN_EMPTY_STRING,
600599
write::PRINT_LITERAL,
601600
write::PRINT_STDERR,

clippy_lints/src/lib.register_suspicious.rs

-1
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,4 @@ store.register_group(true, "clippy::suspicious", Some("clippy_suspicious"), vec!
3636
LintId::of(suspicious_trait_impl::SUSPICIOUS_OP_ASSIGN_IMPL),
3737
LintId::of(swap_ptr_to_ref::SWAP_PTR_TO_REF),
3838
LintId::of(unused_peekable::UNUSED_PEEKABLE),
39-
LintId::of(write::POSITIONAL_NAMED_FORMAT_PARAMETERS),
4039
])

clippy_lints/src/lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ extern crate rustc_lint;
4040
extern crate rustc_middle;
4141
extern crate rustc_mir_dataflow;
4242
extern crate rustc_parse;
43-
extern crate rustc_parse_format;
4443
extern crate rustc_session;
4544
extern crate rustc_span;
4645
extern crate rustc_target;
@@ -425,7 +424,6 @@ pub fn register_pre_expansion_lints(store: &mut rustc_lint::LintStore, sess: &Se
425424
})
426425
});
427426

428-
store.register_pre_expansion_pass(|| Box::new(write::Write::default()));
429427
store.register_pre_expansion_pass(move || Box::new(attrs::EarlyAttributes { msrv }));
430428
}
431429

@@ -879,6 +877,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
879877
ignore_publish: cargo_ignore_publish,
880878
})
881879
});
880+
store.register_late_pass(|| Box::new(write::Write::default()));
882881
store.register_early_pass(|| Box::new(crate_in_macro_def::CrateInMacroDef));
883882
store.register_early_pass(|| Box::new(empty_structs_with_brackets::EmptyStructsWithBrackets));
884883
store.register_late_pass(|| Box::new(unnecessary_owned_empty_strings::UnnecessaryOwnedEmptyStrings));

clippy_lints/src/renamed_lints.rs

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ pub static RENAMED_LINTS: &[(&str, &str)] = &[
3636
("clippy::invalid_ref", "invalid_value"),
3737
("clippy::mem_discriminant_non_enum", "enum_intrinsics_non_enums"),
3838
("clippy::panic_params", "non_fmt_panics"),
39+
("clippy::positional_named_format_parameters", "named_arguments_used_positionally"),
3940
("clippy::temporary_cstring_as_ptr", "temporary_cstring_as_ptr"),
4041
("clippy::unknown_clippy_lints", "unknown_lints"),
4142
("clippy::unused_label", "unused_labels"),

clippy_lints/src/utils/conf.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ pub fn format_error(error: Box<dyn Error>) -> String {
476476

477477
let mut msg = String::from(prefix);
478478
for row in 0..rows {
479-
write!(msg, "\n").unwrap();
479+
writeln!(msg).unwrap();
480480
for (column, column_width) in column_widths.iter().copied().enumerate() {
481481
let index = column * rows + row;
482482
let field = fields.get(index).copied().unwrap_or_default();

0 commit comments

Comments
 (0)