@@ -46,21 +46,39 @@ type LateLintPassFactory =
4646 Box < dyn for < ' tcx > Fn ( TyCtxt < ' tcx > ) -> LateLintPassObject < ' tcx > + sync:: DynSend + sync:: DynSync > ;
4747
4848/// Information about the registered lints.
49+ //
50+ // About the pass factories: these should only be called once, but since we
51+ // want to avoid locks or interior mutability, we don't enforce this. Lints
52+ // should, in theory, be compatible with being constructed more than once,
53+ // though not necessarily in a sane manner. This is safe though.
4954pub struct LintStore {
5055 /// Registered lints.
5156 lints : Vec < & ' static Lint > ,
5257
53- /// Constructor functions for each variety of lint pass.
58+ /// This lint pass kind is softly deprecated. It misses expanded code and has caused a few
59+ /// errors in the past. Currently, it is only used in Clippy. New implementations
60+ /// should avoid using this interface, as it might be removed in the future.
61+ ///
62+ /// * See [rust#69838](https://github.com/rust-lang/rust/pull/69838)
63+ /// * See [rust-clippy#5518](https://github.com/rust-lang/rust-clippy/pull/5518)
64+ pub ( crate ) pre_expansion_lint_passes : Vec < EarlyLintPassFactory > ,
65+
66+ /// These lint passes run on AST nodes.
67+ pub ( crate ) early_lint_passes : Vec < EarlyLintPassFactory > ,
68+
69+ /// These lint passes run on HIR nodes. Each one processes an entire crate. They don't benefit
70+ /// from incremental compilation. `late_lint_mod_passes` should be used in preference where
71+ /// possible; only use `late_lint_passes` for lints that implement `check_crate` and/or
72+ /// `check_crate_post` and accumulate cross-module state.
5473 ///
55- /// These should only be called once, but since we want to avoid locks or
56- /// interior mutability, we don't enforce this (and lints should, in theory,
57- /// be compatible with being constructed more than once, though not
58- /// necessarily in a sane manner. This is safe though.)
59- pub pre_expansion_passes : Vec < EarlyLintPassFactory > ,
60- pub early_passes : Vec < EarlyLintPassFactory > ,
61- pub late_passes : Vec < LateLintPassFactory > ,
62- /// This is unique in that we construct them per-module, so not once.
63- pub late_module_passes : Vec < LateLintPassFactory > ,
74+ /// The exception is Clippy, which uses `late_lint_passes` for all late lint passes. It needs
75+ /// `check_crate`/`check_crate_post` for some of its lints and uses late lint passes throughout
76+ /// for consistency. This is ok because Clippy isn't wired for incremental compilation.
77+ pub ( crate ) late_lint_passes : Vec < LateLintPassFactory > ,
78+
79+ /// These lint passes run on HIR nodes, and are constructed per-module (i.e. multiple times).
80+ /// They benefit from incremental compilation.
81+ pub ( crate ) late_lint_mod_passes : Vec < LateLintPassFactory > ,
6482
6583 /// Lints indexed by name.
6684 by_name : UnordMap < String , TargetLint > ,
@@ -136,10 +154,10 @@ impl LintStore {
136154 pub fn new ( ) -> LintStore {
137155 LintStore {
138156 lints : vec ! [ ] ,
139- pre_expansion_passes : vec ! [ ] ,
140- early_passes : vec ! [ ] ,
141- late_passes : vec ! [ ] ,
142- late_module_passes : vec ! [ ] ,
157+ pre_expansion_lint_passes : vec ! [ ] ,
158+ early_lint_passes : vec ! [ ] ,
159+ late_lint_passes : vec ! [ ] ,
160+ late_lint_mod_passes : vec ! [ ] ,
143161 by_name : Default :: default ( ) ,
144162 lint_groups : Default :: default ( ) ,
145163 }
@@ -166,26 +184,24 @@ impl LintStore {
166184 self . lint_groups . keys ( ) . copied ( )
167185 }
168186
169- pub fn register_early_pass ( & mut self , pass : EarlyLintPassFactory ) {
170- self . early_passes . push ( pass) ;
187+ /// See the comment on `LintStore::pre_expansion_lint_passes`.
188+ pub fn register_pre_expansion_lint_pass ( & mut self , pass : EarlyLintPassFactory ) {
189+ self . pre_expansion_lint_passes . push ( pass) ;
171190 }
172191
173- /// This lint pass is softly deprecated. It misses expanded code and has caused a few
174- /// errors in the past. Currently, it is only used in Clippy. New implementations
175- /// should avoid using this interface, as it might be removed in the future.
176- ///
177- /// * See [rust#69838](https://github.com/rust-lang/rust/pull/69838)
178- /// * See [rust-clippy#5518](https://github.com/rust-lang/rust-clippy/pull/5518)
179- pub fn register_pre_expansion_pass ( & mut self , pass : EarlyLintPassFactory ) {
180- self . pre_expansion_passes . push ( pass) ;
192+ /// See the comment on `LintStore::early_lint_passes`.
193+ pub fn register_early_lint_pass ( & mut self , pass : EarlyLintPassFactory ) {
194+ self . early_lint_passes . push ( pass) ;
181195 }
182196
183- pub fn register_late_pass ( & mut self , pass : LateLintPassFactory ) {
184- self . late_passes . push ( pass) ;
197+ /// See the comment on `LintStore::late_lint_passes`.
198+ pub fn register_late_lint_pass ( & mut self , pass : LateLintPassFactory ) {
199+ self . late_lint_passes . push ( pass) ;
185200 }
186201
187- pub fn register_late_mod_pass ( & mut self , pass : LateLintPassFactory ) {
188- self . late_module_passes . push ( pass) ;
202+ /// See the comment on `LintStore::late_lint_mod_passes`.
203+ pub fn register_late_lint_mod_pass ( & mut self , pass : LateLintPassFactory ) {
204+ self . late_lint_mod_passes . push ( pass) ;
189205 }
190206
191207 /// Helper method for register_early/late_pass
0 commit comments