@@ -8,8 +8,7 @@ something. We appreciate any sort of contributions, and don't want a wall of rul
88
99Clippy welcomes contributions from everyone. There are many ways to contribute to Clippy and the following document
1010explains how you can contribute and how to get started. If you have any questions about contributing or need help with
11- anything, feel free to ask questions on issues or visit the ` #clippy ` IRC channel on ` irc.mozilla.org ` or meet us in
12- ` #clippy ` on [ Discord] ( https://discord.gg/rust-lang ) .
11+ anything, feel free to ask questions on issues or visit the ` #clippy ` on [ Discord] ( https://discord.gg/rust-lang ) .
1312
1413All contributors are expected to follow the [ Rust Code of Conduct] ( http://www.rust-lang.org/conduct.html ) .
1514
@@ -55,8 +54,7 @@ and resolved paths.
5554[ ` T-AST ` ] ( https://github.com/rust-lang/rust-clippy/labels/T-AST ) issues will generally need you to match against a
5655predefined syntax structure. To figure out how this syntax structure is encoded in the AST, it is recommended to run
5756` rustc -Z ast-json ` on an example of the structure and compare with the [ nodes in the AST
58- docs] ( https://doc.rust-lang.org/nightly/nightly-rustc/syntax/ast ) . Usually the lint will end up to be a nested series of
59- matches and ifs, [ like
57+ docs] . Usually the lint will end up to be a nested series of matches and ifs, [ like
6058so] ( https://github.com/rust-lang/rust-clippy/blob/de5ccdfab68a5e37689f3c950ed1532ba9d652a0/src/misc.rs#L34 ) .
6159
6260[ ` E-medium ` ] ( https://github.com/rust-lang/rust-clippy/labels/E-medium ) issues are generally
@@ -69,6 +67,8 @@ be more involved and require verifying types. The
6967lot of methods that are useful, though one of the most useful would be ` expr_ty ` (gives the type of
7068an AST expression). ` match_def_path() ` in Clippy's ` utils ` module can also be useful.
7169
70+ [ nodes in the AST docs ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_ast/ast/
71+
7272## Writing code
7373
7474Have a look at the [ docs for writing lints] ( doc/adding_lints.md ) for more details. [ Llogiq's blog post on
@@ -82,11 +82,8 @@ quick read.
8282
8383## How Clippy works
8484
85- Clippy is a [ rustc compiler plugin] [ compiler_plugin ] . The main entry point is at [ ` src/lib.rs ` ] [ main_entry ] . In there,
86- the lint registration is delegated to the [ ` clippy_lints ` ] [ lint_crate ] crate.
87-
88- [ ` clippy_lints/src/lib.rs ` ] [ lint_crate_entry ] imports all the different lint modules and registers them with the rustc
89- plugin registry. For example, the [ ` else_if_without_else ` ] [ else_if_without_else ] lint is registered like this:
85+ [ ` clippy_lints/src/lib.rs ` ] [ lint_crate_entry ] imports all the different lint modules and registers in the [ ` LintStore ` ] .
86+ For example, the [ ` else_if_without_else ` ] [ else_if_without_else ] lint is registered like this:
9087
9188``` rust
9289// ./clippy_lints/src/lib.rs
@@ -95,25 +92,24 @@ plugin registry. For example, the [`else_if_without_else`][else_if_without_else]
9592pub mod else_if_without_else ;
9693// ...
9794
98- pub fn register_plugins (reg : & mut rustc_driver :: plugin :: Registry ) {
95+ pub fn register_plugins (store : & mut rustc_lint :: LintStore , sess : & Session , conf : & Conf ) {
9996 // ...
100- reg . register_early_lint_pass ( box else_if_without_else :: ElseIfWithoutElse );
97+ store . register_early_pass ( || box else_if_without_else :: ElseIfWithoutElse );
10198 // ...
10299
103- reg . register_lint_group ( " clippy::restriction" , vec! [
100+ store . register_group ( true , " clippy::restriction" , Some ( " clippy_restriction " ) , vec! [
104101 // ...
105- else_if_without_else :: ELSE_IF_WITHOUT_ELSE ,
102+ LintId :: of ( & else_if_without_else :: ELSE_IF_WITHOUT_ELSE ) ,
106103 // ...
107104 ]);
108105}
109106```
110107
111- The [ ` plugin::PluginRegistry ` ] [ plugin_registry ] provides two methods to register lints:
112- [ register_early_lint_pass ] [ reg_early_lint_pass ] and [ register_late_lint_pass ] [ reg_late_lint_pass ] . Both take an object
108+ The [ ` rustc_lint::LintStore ` ] [ `LintStore` ] provides two methods to register lints:
109+ [ register_early_pass ] [ reg_early_pass ] and [ register_late_pass ] [ reg_late_pass ] . Both take an object
113110that implements an [ ` EarlyLintPass ` ] [ early_lint_pass ] or [ ` LateLintPass ` ] [ late_lint_pass ] respectively. This is done in
114111every single lint. It's worth noting that the majority of ` clippy_lints/src/lib.rs ` is autogenerated by `cargo dev
115- update_lints` and you don't have to add anything by hand. When you are writing your own lint, you can use that script to
116- save you some time.
112+ update_lints`. When you are writing your own lint, you can use that script to save you some time.
117113
118114``` rust
119115// ./clippy_lints/src/else_if_without_else.rs
@@ -135,18 +131,24 @@ The difference between `EarlyLintPass` and `LateLintPass` is that the methods of
135131AST information. The methods of the ` LateLintPass ` trait are executed after type checking and contain type information
136132via the ` LateContext ` parameter.
137133
138- That's why the ` else_if_without_else ` example uses the ` register_early_lint_pass ` function. Because the [ actual lint
134+ That's why the ` else_if_without_else ` example uses the ` register_early_pass ` function. Because the [ actual lint
139135logic] [ else_if_without_else ] does not depend on any type information.
140136
137+ See also [ the adding lints doc] .
138+
139+ [ the adding lints doc ] : https://github.com/rust-lang/rust-clippy/blob/master/doc/adding_lints.md
140+ [ `LintStore` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/struct.LintStore.html
141+
141142## Fixing build failures caused by Rust
142143
143144Clippy will sometimes fail to build from source because building it depends on unstable internal Rust features. Most of
144145the times we have to adapt to the changes and only very rarely there's an actual bug in Rust. Fixing build failures
145146caused by Rust updates, can be a good way to learn about Rust internals.
146147
147148In order to find out why Clippy does not work properly with a new Rust commit, you can use the [ rust-toolstate commit
148- history] [ toolstate_commit_history ] . You will then have to look for the last commit that contains `test-pass ->
149- build-fail` or ` test-pass` -> ` test-fail` for the ` clippy-driver` component. [ Here] [ toolstate_commit ] is an example.
149+ history] [ toolstate_commit_history ] . You will then have to look for the last commit that contains
150+ ` test-pass -> build-fail ` or ` test-pass ` -> ` test-fail ` for the ` clippy-driver ` component.
151+ [ Here] [ toolstate_commit ] is an example.
150152
151153The commit message contains a link to the PR. The PRs are usually small enough to discover the breaking API change and
152154if they are bigger, they likely include some discussion that may help you to fix Clippy.
@@ -158,14 +160,8 @@ If you decide to make Clippy work again with a Rust commit that breaks it,
158160you probably want to install the latest Rust from master locally and run Clippy
159161using that version of Rust.
160162
161- You can use [ rustup-toolchain-install-master] [ rtim ] to do that:
162-
163- ``` bash
164- cargo install rustup-toolchain-install-master
165- rustup-toolchain-install-master --force -n master -c rustc-dev
166- rustup override set master
167- cargo test
168- ```
163+ You can set up the master toolchain by running ` ./setup-toolchain.sh ` . That script will install
164+ [ rustup-toolchain-install-master] [ rtim ] and master toolchain, then run ` rustup override set master ` .
169165
170166After fixing the build failure on this repository, we can submit a pull request
171167to [ ` rust-lang/rust ` ] to fix the toolstate.
@@ -206,39 +202,34 @@ You can find the Clippy bors queue [here][homu_queue].
206202If you have @bors permissions, you can find an overview of the available
207203commands [ here] [ homu_instructions ] .
208204
209-
210205## Contributions
211206
212207Contributions to Clippy should be made in the form of GitHub pull requests. Each pull request will
213208be reviewed by a core contributor (someone with permission to land patches) and either landed in the
214209main tree or given feedback for changes that would be required.
215210
216- All code in this repository is under the [ Apache-2.0] ( http ://www.apache.org/licenses/LICENSE-2.0> )
217- or the [ MIT] ( http ://opensource.org/licenses/MIT) license.
211+ All code in this repository is under the [ Apache-2.0] ( https ://www.apache.org/licenses/LICENSE-2.0)
212+ or the [ MIT] ( https ://opensource.org/licenses/MIT) license.
218213
219214<!-- adapted from https://github.com/servo/servo/blob/master/CONTRIBUTING.md -->
220215
221- [ main_entry ] : https://github.com/rust-lang/rust-clippy/blob/c5b39a5917ffc0f1349b6e414fa3b874fdcf8429/src/lib.rs#L14
222- [ lint_crate ] : https://github.com/rust-lang/rust-clippy/tree/c5b39a5917ffc0f1349b6e414fa3b874fdcf8429/clippy_lints/src
223- [ lint_crate_entry ] : https://github.com/rust-lang/rust-clippy/blob/c5b39a5917ffc0f1349b6e414fa3b874fdcf8429/clippy_lints/src/lib.rs
224- [ else_if_without_else ] : https://github.com/rust-lang/rust-clippy/blob/c5b39a5917ffc0f1349b6e414fa3b874fdcf8429/clippy_lints/src/else_if_without_else.rs
225- [ compiler_plugin ] : https://doc.rust-lang.org/unstable-book/language-features/plugin.html#lint-plugins
226- [ plugin_registry ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_plugin_impl/registry/struct.Registry.html
227- [ reg_early_lint_pass ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_plugin_impl/registry/struct.Registry.html#method.register_early_lint_pass
228- [ reg_late_lint_pass ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_plugin_impl/registry/struct.Registry.html#method.register_late_lint_pass
229- [ early_lint_pass ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc/lint/trait.EarlyLintPass.html
230- [ late_lint_pass ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc/lint/trait.LateLintPass.html
216+ [ lint_crate_entry ] : https://github.com/rust-lang/rust-clippy/blob/master/clippy_lints/src/lib.rs
217+ [ else_if_without_else ] : https://github.com/rust-lang/rust-clippy/blob/4253aa7137cb7378acc96133c787e49a345c2b3c/clippy_lints/src/else_if_without_else.rs
218+ [ reg_early_pass ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/struct.LintStore.html#method.register_early_pass
219+ [ reg_late_pass ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/struct.LintStore.html#method.register_late_pass
220+ [ early_lint_pass ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/trait.EarlyLintPass.html
221+ [ late_lint_pass ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/trait.LateLintPass.html
231222[ toolstate_commit_history ] : https://github.com/rust-lang-nursery/rust-toolstate/commits/master
232- [ toolstate_commit ] : https://github.com/rust-lang-nursery/rust-toolstate/commit/6ce0459f6bfa7c528ae1886492a3e0b5ef0ee547
223+ [ toolstate_commit ] : https://github.com/rust-lang-nursery/rust-toolstate/commit/aad74d8294e198a7cf8ac81a91aebb7f3bbcf727
233224[ rtim ] : https://github.com/kennytm/rustup-toolchain-install-master
234- [ rustup_component_history ] : https://mexus .github.io/rustup-components-history
225+ [ rustup_component_history ] : https://rust-lang .github.io/rustup-components-history
235226[ clippy_rfc ] : https://github.com/rust-lang/rfcs/blob/master/text/2476-clippy-uno.md
236227[ rfc_stability ] : https://github.com/rust-lang/rfcs/blob/master/text/2476-clippy-uno.md#stability-guarantees
237228[ rfc_lint_cats ] : https://github.com/rust-lang/rfcs/blob/master/text/2476-clippy-uno.md#lint-audit-and-categories
238229[ triage ] : https://forge.rust-lang.org/triage-procedure.html
239230[ l-crash ] : https://github.com/rust-lang/rust-clippy/labels/L-crash%20%3Aboom%3A
240231[ l-bug ] : https://github.com/rust-lang/rust-clippy/labels/L-bug%20%3Abeetle%3A
241- [ homu ] : https://github.com/servo /homu
232+ [ homu ] : https://github.com/rust-lang /homu
242233[ homu_instructions ] : https://buildbot2.rust-lang.org/homu/
243234[ homu_queue ] : https://buildbot2.rust-lang.org/homu/queue/clippy
244235[ `rust-lang/rust` ] : https://github.com/rust-lang/rust
0 commit comments