@@ -60,11 +60,6 @@ extern crate clippy_utils;
6060#[ macro_use]
6161extern crate declare_clippy_lint;
6262
63- use std:: collections:: BTreeMap ;
64-
65- use rustc_data_structures:: fx:: FxHashSet ;
66- use rustc_lint:: { Lint , LintId } ;
67-
6863#[ cfg( feature = "internal" ) ]
6964pub mod deprecated_lints;
7065#[ cfg_attr( feature = "internal" , allow( clippy:: missing_clippy_version_attribute) ) ]
@@ -384,6 +379,10 @@ mod zero_sized_map_values;
384379// end lints modules, do not remove this comment, it’s used in `update_lints`
385380
386381use clippy_config:: { get_configuration_metadata, Conf } ;
382+ use clippy_utils:: macros:: FormatArgsStorage ;
383+ use rustc_data_structures:: fx:: FxHashSet ;
384+ use rustc_lint:: { Lint , LintId } ;
385+ use std:: collections:: BTreeMap ;
387386
388387/// Register all pre expansion lints
389388///
@@ -654,7 +653,13 @@ pub fn register_lints(store: &mut rustc_lint::LintStore, conf: &'static Conf) {
654653 . collect ( ) ,
655654 ) )
656655 } ) ;
657- store. register_early_pass ( || Box :: < utils:: format_args_collector:: FormatArgsCollector > :: default ( ) ) ;
656+ let format_args_storage = FormatArgsStorage :: default ( ) ;
657+ let format_args = format_args_storage. clone ( ) ;
658+ store. register_early_pass ( move || {
659+ Box :: new ( utils:: format_args_collector:: FormatArgsCollector :: new (
660+ format_args. clone ( ) ,
661+ ) )
662+ } ) ;
658663 store. register_late_pass ( |_| Box :: new ( utils:: dump_hir:: DumpHir ) ) ;
659664 store. register_late_pass ( |_| Box :: new ( utils:: author:: Author ) ) ;
660665 store. register_late_pass ( move |_| {
@@ -696,13 +701,15 @@ pub fn register_lints(store: &mut rustc_lint::LintStore, conf: &'static Conf) {
696701 store. register_late_pass ( |_| Box :: new ( non_octal_unix_permissions:: NonOctalUnixPermissions ) ) ;
697702 store. register_early_pass ( || Box :: new ( unnecessary_self_imports:: UnnecessarySelfImports ) ) ;
698703 store. register_late_pass ( move |_| Box :: new ( approx_const:: ApproxConstant :: new ( msrv ( ) ) ) ) ;
704+ let format_args = format_args_storage. clone ( ) ;
699705 store. register_late_pass ( move |_| {
700706 Box :: new ( methods:: Methods :: new (
701707 avoid_breaking_exported_api,
702708 msrv ( ) ,
703709 allow_expect_in_tests,
704710 allow_unwrap_in_tests,
705711 allowed_dotfiles. clone ( ) ,
712+ format_args. clone ( ) ,
706713 ) )
707714 } ) ;
708715 store. register_late_pass ( move |_| Box :: new ( matches:: Matches :: new ( msrv ( ) ) ) ) ;
@@ -766,7 +773,8 @@ pub fn register_lints(store: &mut rustc_lint::LintStore, conf: &'static Conf) {
766773 store. register_late_pass ( |_| Box :: < regex:: Regex > :: default ( ) ) ;
767774 store. register_late_pass ( move |_| Box :: new ( copies:: CopyAndPaste :: new ( ignore_interior_mutability. clone ( ) ) ) ) ;
768775 store. register_late_pass ( |_| Box :: new ( copy_iterator:: CopyIterator ) ) ;
769- store. register_late_pass ( |_| Box :: new ( format:: UselessFormat ) ) ;
776+ let format_args = format_args_storage. clone ( ) ;
777+ store. register_late_pass ( move |_| Box :: new ( format:: UselessFormat :: new ( format_args. clone ( ) ) ) ) ;
770778 store. register_late_pass ( |_| Box :: new ( swap:: Swap ) ) ;
771779 store. register_late_pass ( |_| Box :: new ( overflow_check_conditional:: OverflowCheckConditional ) ) ;
772780 store. register_late_pass ( |_| Box :: < new_without_default:: NewWithoutDefault > :: default ( ) ) ;
@@ -790,7 +798,8 @@ pub fn register_lints(store: &mut rustc_lint::LintStore, conf: &'static Conf) {
790798 store. register_late_pass ( |_| Box :: new ( partialeq_ne_impl:: PartialEqNeImpl ) ) ;
791799 store. register_late_pass ( |_| Box :: new ( unused_io_amount:: UnusedIoAmount ) ) ;
792800 store. register_late_pass ( move |_| Box :: new ( large_enum_variant:: LargeEnumVariant :: new ( enum_variant_size_threshold) ) ) ;
793- store. register_late_pass ( |_| Box :: new ( explicit_write:: ExplicitWrite ) ) ;
801+ let format_args = format_args_storage. clone ( ) ;
802+ store. register_late_pass ( move |_| Box :: new ( explicit_write:: ExplicitWrite :: new ( format_args. clone ( ) ) ) ) ;
794803 store. register_late_pass ( |_| Box :: new ( needless_pass_by_value:: NeedlessPassByValue ) ) ;
795804 store. register_late_pass ( move |tcx| {
796805 Box :: new ( pass_by_ref_or_value:: PassByRefOrValue :: new (
@@ -832,7 +841,8 @@ pub fn register_lints(store: &mut rustc_lint::LintStore, conf: &'static Conf) {
832841 store. register_late_pass ( move |_| Box :: new ( mut_key:: MutableKeyType :: new ( ignore_interior_mutability. clone ( ) ) ) ) ;
833842 store. register_early_pass ( || Box :: new ( reference:: DerefAddrOf ) ) ;
834843 store. register_early_pass ( || Box :: new ( double_parens:: DoubleParens ) ) ;
835- store. register_late_pass ( |_| Box :: new ( format_impl:: FormatImpl :: new ( ) ) ) ;
844+ let format_args = format_args_storage. clone ( ) ;
845+ store. register_late_pass ( move |_| Box :: new ( format_impl:: FormatImpl :: new ( format_args. clone ( ) ) ) ) ;
836846 store. register_early_pass ( || Box :: new ( unsafe_removed_from_name:: UnsafeNameRemoval ) ) ;
837847 store. register_early_pass ( || Box :: new ( else_if_without_else:: ElseIfWithoutElse ) ) ;
838848 store. register_early_pass ( || Box :: new ( int_plus_one:: IntPlusOne ) ) ;
@@ -958,8 +968,14 @@ pub fn register_lints(store: &mut rustc_lint::LintStore, conf: &'static Conf) {
958968 accept_comment_above_attributes,
959969 ) )
960970 } ) ;
961- store
962- . register_late_pass ( move |_| Box :: new ( format_args:: FormatArgs :: new ( msrv ( ) , allow_mixed_uninlined_format_args) ) ) ;
971+ let format_args = format_args_storage. clone ( ) ;
972+ store. register_late_pass ( move |_| {
973+ Box :: new ( format_args:: FormatArgs :: new (
974+ format_args. clone ( ) ,
975+ msrv ( ) ,
976+ allow_mixed_uninlined_format_args,
977+ ) )
978+ } ) ;
963979 store. register_late_pass ( |_| Box :: new ( trailing_empty_array:: TrailingEmptyArray ) ) ;
964980 store. register_early_pass ( || Box :: new ( octal_escapes:: OctalEscapes ) ) ;
965981 store. register_late_pass ( |_| Box :: new ( needless_late_init:: NeedlessLateInit ) ) ;
@@ -970,7 +986,8 @@ pub fn register_lints(store: &mut rustc_lint::LintStore, conf: &'static Conf) {
970986 store. register_late_pass ( |_| Box :: new ( default_union_representation:: DefaultUnionRepresentation ) ) ;
971987 store. register_late_pass ( |_| Box :: < only_used_in_recursion:: OnlyUsedInRecursion > :: default ( ) ) ;
972988 store. register_late_pass ( move |_| Box :: new ( dbg_macro:: DbgMacro :: new ( allow_dbg_in_tests) ) ) ;
973- store. register_late_pass ( move |_| Box :: new ( write:: Write :: new ( allow_print_in_tests) ) ) ;
989+ let format_args = format_args_storage. clone ( ) ;
990+ store. register_late_pass ( move |_| Box :: new ( write:: Write :: new ( format_args. clone ( ) , allow_print_in_tests) ) ) ;
974991 store. register_late_pass ( move |_| {
975992 Box :: new ( cargo:: Cargo {
976993 ignore_publish : cargo_ignore_publish,
0 commit comments