@@ -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///
@@ -614,6 +613,14 @@ pub fn register_lints(store: &mut rustc_lint::LintStore, conf: &'static Conf) {
614613 }
615614 }
616615
616+ let format_args_storage = FormatArgsStorage :: default ( ) ;
617+ let format_args = format_args_storage. clone ( ) ;
618+ store. register_early_pass ( move || {
619+ Box :: new ( utils:: format_args_collector:: FormatArgsCollector :: new (
620+ format_args. clone ( ) ,
621+ ) )
622+ } ) ;
623+
617624 // all the internal lints
618625 #[ cfg( feature = "internal" ) ]
619626 {
@@ -654,7 +661,6 @@ pub fn register_lints(store: &mut rustc_lint::LintStore, conf: &'static Conf) {
654661 . collect ( ) ,
655662 ) )
656663 } ) ;
657- store. register_early_pass ( || Box :: < utils:: format_args_collector:: FormatArgsCollector > :: default ( ) ) ;
658664 store. register_late_pass ( |_| Box :: new ( utils:: dump_hir:: DumpHir ) ) ;
659665 store. register_late_pass ( |_| Box :: new ( utils:: author:: Author ) ) ;
660666 store. register_late_pass ( move |_| {
@@ -696,13 +702,15 @@ pub fn register_lints(store: &mut rustc_lint::LintStore, conf: &'static Conf) {
696702 store. register_late_pass ( |_| Box :: new ( non_octal_unix_permissions:: NonOctalUnixPermissions ) ) ;
697703 store. register_early_pass ( || Box :: new ( unnecessary_self_imports:: UnnecessarySelfImports ) ) ;
698704 store. register_late_pass ( move |_| Box :: new ( approx_const:: ApproxConstant :: new ( msrv ( ) ) ) ) ;
705+ let format_args = format_args_storage. clone ( ) ;
699706 store. register_late_pass ( move |_| {
700707 Box :: new ( methods:: Methods :: new (
701708 avoid_breaking_exported_api,
702709 msrv ( ) ,
703710 allow_expect_in_tests,
704711 allow_unwrap_in_tests,
705712 allowed_dotfiles. clone ( ) ,
713+ format_args. clone ( ) ,
706714 ) )
707715 } ) ;
708716 store. register_late_pass ( move |_| Box :: new ( matches:: Matches :: new ( msrv ( ) ) ) ) ;
@@ -766,7 +774,8 @@ pub fn register_lints(store: &mut rustc_lint::LintStore, conf: &'static Conf) {
766774 store. register_late_pass ( |_| Box :: < regex:: Regex > :: default ( ) ) ;
767775 store. register_late_pass ( move |_| Box :: new ( copies:: CopyAndPaste :: new ( ignore_interior_mutability. clone ( ) ) ) ) ;
768776 store. register_late_pass ( |_| Box :: new ( copy_iterator:: CopyIterator ) ) ;
769- store. register_late_pass ( |_| Box :: new ( format:: UselessFormat ) ) ;
777+ let format_args = format_args_storage. clone ( ) ;
778+ store. register_late_pass ( move |_| Box :: new ( format:: UselessFormat :: new ( format_args. clone ( ) ) ) ) ;
770779 store. register_late_pass ( |_| Box :: new ( swap:: Swap ) ) ;
771780 store. register_late_pass ( |_| Box :: new ( overflow_check_conditional:: OverflowCheckConditional ) ) ;
772781 store. register_late_pass ( |_| Box :: < new_without_default:: NewWithoutDefault > :: default ( ) ) ;
@@ -790,7 +799,8 @@ pub fn register_lints(store: &mut rustc_lint::LintStore, conf: &'static Conf) {
790799 store. register_late_pass ( |_| Box :: new ( partialeq_ne_impl:: PartialEqNeImpl ) ) ;
791800 store. register_late_pass ( |_| Box :: new ( unused_io_amount:: UnusedIoAmount ) ) ;
792801 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 ) ) ;
802+ let format_args = format_args_storage. clone ( ) ;
803+ store. register_late_pass ( move |_| Box :: new ( explicit_write:: ExplicitWrite :: new ( format_args. clone ( ) ) ) ) ;
794804 store. register_late_pass ( |_| Box :: new ( needless_pass_by_value:: NeedlessPassByValue ) ) ;
795805 store. register_late_pass ( move |tcx| {
796806 Box :: new ( pass_by_ref_or_value:: PassByRefOrValue :: new (
@@ -832,7 +842,8 @@ pub fn register_lints(store: &mut rustc_lint::LintStore, conf: &'static Conf) {
832842 store. register_late_pass ( move |_| Box :: new ( mut_key:: MutableKeyType :: new ( ignore_interior_mutability. clone ( ) ) ) ) ;
833843 store. register_early_pass ( || Box :: new ( reference:: DerefAddrOf ) ) ;
834844 store. register_early_pass ( || Box :: new ( double_parens:: DoubleParens ) ) ;
835- store. register_late_pass ( |_| Box :: new ( format_impl:: FormatImpl :: new ( ) ) ) ;
845+ let format_args = format_args_storage. clone ( ) ;
846+ store. register_late_pass ( move |_| Box :: new ( format_impl:: FormatImpl :: new ( format_args. clone ( ) ) ) ) ;
836847 store. register_early_pass ( || Box :: new ( unsafe_removed_from_name:: UnsafeNameRemoval ) ) ;
837848 store. register_early_pass ( || Box :: new ( else_if_without_else:: ElseIfWithoutElse ) ) ;
838849 store. register_early_pass ( || Box :: new ( int_plus_one:: IntPlusOne ) ) ;
@@ -958,8 +969,14 @@ pub fn register_lints(store: &mut rustc_lint::LintStore, conf: &'static Conf) {
958969 accept_comment_above_attributes,
959970 ) )
960971 } ) ;
961- store
962- . register_late_pass ( move |_| Box :: new ( format_args:: FormatArgs :: new ( msrv ( ) , allow_mixed_uninlined_format_args) ) ) ;
972+ let format_args = format_args_storage. clone ( ) ;
973+ store. register_late_pass ( move |_| {
974+ Box :: new ( format_args:: FormatArgs :: new (
975+ format_args. clone ( ) ,
976+ msrv ( ) ,
977+ allow_mixed_uninlined_format_args,
978+ ) )
979+ } ) ;
963980 store. register_late_pass ( |_| Box :: new ( trailing_empty_array:: TrailingEmptyArray ) ) ;
964981 store. register_early_pass ( || Box :: new ( octal_escapes:: OctalEscapes ) ) ;
965982 store. register_late_pass ( |_| Box :: new ( needless_late_init:: NeedlessLateInit ) ) ;
@@ -970,7 +987,8 @@ pub fn register_lints(store: &mut rustc_lint::LintStore, conf: &'static Conf) {
970987 store. register_late_pass ( |_| Box :: new ( default_union_representation:: DefaultUnionRepresentation ) ) ;
971988 store. register_late_pass ( |_| Box :: < only_used_in_recursion:: OnlyUsedInRecursion > :: default ( ) ) ;
972989 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) ) ) ;
990+ let format_args = format_args_storage. clone ( ) ;
991+ store. register_late_pass ( move |_| Box :: new ( write:: Write :: new ( format_args. clone ( ) , allow_print_in_tests) ) ) ;
974992 store. register_late_pass ( move |_| {
975993 Box :: new ( cargo:: Cargo {
976994 ignore_publish : cargo_ignore_publish,
0 commit comments