@@ -124,8 +124,11 @@ To have `rust-analyzer` also work in the `clippy_dev` and `lintcheck` crates, ad
124124
125125## How Clippy works
126126
127- [ ` clippy_lints/src/lib.rs ` ] [ lint_crate_entry ] imports all the different lint modules and registers in the [ ` LintStore ` ] .
128- For example, the [ ` else_if_without_else ` ] [ else_if_without_else ] lint is registered like this:
127+ [ ` clippy_lints/src/lib.rs ` ] [ lint_crate_entry ] imports all the different lint modules and registers them in the
128+ [ ` LintStore ` ] . All early passes are folded into a single ` CombinedEarlyLintPass ` , and all late passes into a single
129+ ` CombinedLateLintPass ` , each registered once with the store. A pass is added to one of these by listing it in the
130+ ` early_lint_methods! ` or ` late_lint_methods! ` macro invocation. For example, the
131+ [ ` else_if_without_else ` ] [ else_if_without_else ] lint is added like this:
129132
130133``` rust
131134// ./clippy_lints/src/lib.rs
@@ -134,18 +137,21 @@ For example, the [`else_if_without_else`][else_if_without_else] lint is register
134137pub mod else_if_without_else ;
135138// ...
136139
137- pub fn register_lints (store : & mut rustc_lint :: LintStore , conf : & 'static Conf ) {
138- // ...
139- store . register_early_pass (|| Box :: new (else_if_without_else :: ElseIfWithoutElse ));
140- // ...
141- }
140+ rustc_lint :: early_lint_methods! (
141+ crate :: combined_early_lint_pass ,
142+ [CombinedEarlyLintPass , (/* ... */ ), [
143+ // ...
144+ ElseIfWithoutElse : else_if_without_else :: ElseIfWithoutElse = else_if_without_else :: ElseIfWithoutElse ,
145+ // ...
146+ ]]
147+ );
142148```
143149
144- The [ ` rustc_lint::LintStore ` ] [ `LintStore` ] provides two methods to register lints:
145- [ register_early_pass ] [ reg_early_pass ] and [ register_late_pass ] [ reg_late_pass ] . Both take an object
146- that implements an [ ` EarlyLintPass ` ] [ early_lint_pass ] or [ ` LateLintPass ` ] [ late_lint_pass ] respectively. This is done in
147- every single lint. It's worth noting that the majority of ` clippy_lints/src/lib.rs ` is autogenerated by `cargo dev
148- update_lints`. When you are writing your own lint, you can use that script to save you some time.
150+ Each entry has the form ` Field: Type = constructor ` , where the constructor builds the pass (passing ` conf ` when the pass
151+ needs the user configuration). The combined passes implement [ ` EarlyLintPass ` ] [ early_lint_pass ] and
152+ [ ` LateLintPass ` ] [ late_lint_pass ] respectively, so each listed pass must also implement the matching trait. It's worth
153+ noting that the majority of ` clippy_lints/src/lib.rs ` is autogenerated by ` cargo dev update_lints ` . When you are
154+ writing your own lint, you can use that script to save you some time.
149155
150156``` rust
151157// ./clippy_lints/src/else_if_without_else.rs
@@ -167,14 +173,12 @@ The difference between `EarlyLintPass` and `LateLintPass` is that the methods of
167173AST information. The methods of the ` LateLintPass ` trait are executed after type checking and contain type information
168174via the ` LateContext ` parameter.
169175
170- That's why the ` else_if_without_else ` example uses the ` register_early_pass ` function . Because the
176+ That's why the ` else_if_without_else ` example is listed in ` early_lint_methods! ` . Because the
171177[ actual lint logic] [ else_if_without_else ] does not depend on any type information.
172178
173179[ lint_crate_entry ] : https://github.com/rust-lang/rust-clippy/blob/master/clippy_lints/src/lib.rs
174180[ else_if_without_else ] : https://github.com/rust-lang/rust-clippy/blob/4253aa7137cb7378acc96133c787e49a345c2b3c/clippy_lints/src/else_if_without_else.rs
175181[ `LintStore` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/struct.LintStore.html
176- [ reg_early_pass ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/struct.LintStore.html#method.register_early_pass
177- [ reg_late_pass ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/struct.LintStore.html#method.register_late_pass
178182[ early_lint_pass ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/trait.EarlyLintPass.html
179183[ late_lint_pass ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/trait.LateLintPass.html
180184
0 commit comments