11#![ feature( rustc_private) ]
2+ #![ feature( let_chains) ]
23#![ feature( once_cell) ]
34#![ cfg_attr( feature = "deny-warnings" , deny( warnings) ) ]
45// warn on lints, that are included in `rust-lang/rust`s bootstrap
@@ -71,6 +72,32 @@ fn track_clippy_args(parse_sess: &mut ParseSess, args_env_var: &Option<String>)
7172 ) ) ;
7273}
7374
75+ /// Track files that may be accessed at runtime in `file_depinfo` so that cargo will re-run clippy
76+ /// when any of them are modified
77+ fn track_files ( parse_sess : & mut ParseSess , conf_path_string : Option < String > ) {
78+ let file_depinfo = parse_sess. file_depinfo . get_mut ( ) ;
79+
80+ // Used by `clippy::cargo` lints and to determine the MSRV. `cargo clippy` executes `clippy-driver`
81+ // with the current directory set to `CARGO_MANIFEST_DIR` so a relative path is fine
82+ if Path :: new ( "Cargo.toml" ) . exists ( ) {
83+ file_depinfo. insert ( Symbol :: intern ( "Cargo.toml" ) ) ;
84+ }
85+
86+ // `clippy.toml`
87+ if let Some ( path) = conf_path_string {
88+ file_depinfo. insert ( Symbol :: intern ( & path) ) ;
89+ }
90+
91+ // During development track the `clippy-driver` executable so that cargo will re-run clippy whenever
92+ // it is rebuilt
93+ if cfg ! ( debug_assertions)
94+ && let Ok ( current_exe) = env:: current_exe ( )
95+ && let Some ( current_exe) = current_exe. to_str ( )
96+ {
97+ file_depinfo. insert ( Symbol :: intern ( current_exe) ) ;
98+ }
99+ }
100+
74101struct DefaultCallbacks ;
75102impl rustc_driver:: Callbacks for DefaultCallbacks { }
76103
@@ -97,10 +124,18 @@ impl rustc_driver::Callbacks for ClippyCallbacks {
97124 // JUSTIFICATION: necessary in clippy driver to set `mir_opt_level`
98125 #[ allow( rustc:: bad_opt_access) ]
99126 fn config ( & mut self , config : & mut interface:: Config ) {
127+ let conf_path = clippy_lints:: lookup_conf_file ( ) ;
128+ let conf_path_string = if let Ok ( Some ( path) ) = & conf_path {
129+ path. to_str ( ) . map ( String :: from)
130+ } else {
131+ None
132+ } ;
133+
100134 let previous = config. register_lints . take ( ) ;
101135 let clippy_args_var = self . clippy_args_var . take ( ) ;
102136 config. parse_sess_created = Some ( Box :: new ( move |parse_sess| {
103137 track_clippy_args ( parse_sess, & clippy_args_var) ;
138+ track_files ( parse_sess, conf_path_string) ;
104139 } ) ) ;
105140 config. register_lints = Some ( Box :: new ( move |sess, lint_store| {
106141 // technically we're ~guaranteed that this is none but might as well call anything that
@@ -109,7 +144,7 @@ impl rustc_driver::Callbacks for ClippyCallbacks {
109144 ( previous) ( sess, lint_store) ;
110145 }
111146
112- let conf = clippy_lints:: read_conf ( sess) ;
147+ let conf = clippy_lints:: read_conf ( sess, & conf_path ) ;
113148 clippy_lints:: register_plugins ( lint_store, sess, & conf) ;
114149 clippy_lints:: register_pre_expansion_lints ( lint_store, sess, & conf) ;
115150 clippy_lints:: register_renamed ( lint_store) ;
0 commit comments