1
1
#![ feature( rustc_private) ]
2
+ #![ feature( let_chains) ]
2
3
#![ feature( once_cell) ]
3
4
#![ cfg_attr( feature = "deny-warnings" , deny( warnings) ) ]
4
5
// 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>)
71
72
) ) ;
72
73
}
73
74
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
+
74
101
struct DefaultCallbacks ;
75
102
impl rustc_driver:: Callbacks for DefaultCallbacks { }
76
103
@@ -97,10 +124,18 @@ impl rustc_driver::Callbacks for ClippyCallbacks {
97
124
// JUSTIFICATION: necessary in clippy driver to set `mir_opt_level`
98
125
#[ allow( rustc:: bad_opt_access) ]
99
126
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
+
100
134
let previous = config. register_lints . take ( ) ;
101
135
let clippy_args_var = self . clippy_args_var . take ( ) ;
102
136
config. parse_sess_created = Some ( Box :: new ( move |parse_sess| {
103
137
track_clippy_args ( parse_sess, & clippy_args_var) ;
138
+ track_files ( parse_sess, conf_path_string) ;
104
139
} ) ) ;
105
140
config. register_lints = Some ( Box :: new ( move |sess, lint_store| {
106
141
// 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 {
109
144
( previous) ( sess, lint_store) ;
110
145
}
111
146
112
- let conf = clippy_lints:: read_conf ( sess) ;
147
+ let conf = clippy_lints:: read_conf ( sess, & conf_path ) ;
113
148
clippy_lints:: register_plugins ( lint_store, sess, & conf) ;
114
149
clippy_lints:: register_pre_expansion_lints ( lint_store, sess, & conf) ;
115
150
clippy_lints:: register_renamed ( lint_store) ;
0 commit comments