@@ -8,8 +8,7 @@ something. We appreciate any sort of contributions, and don't want a wall of rul
8
8
9
9
Clippy welcomes contributions from everyone. There are many ways to contribute to Clippy and the following document
10
10
explains 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 ) .
13
12
14
13
All contributors are expected to follow the [ Rust Code of Conduct] ( http://www.rust-lang.org/conduct.html ) .
15
14
@@ -55,8 +54,7 @@ and resolved paths.
55
54
[ ` T-AST ` ] ( https://github.com/rust-lang/rust-clippy/labels/T-AST ) issues will generally need you to match against a
56
55
predefined syntax structure. To figure out how this syntax structure is encoded in the AST, it is recommended to run
57
56
` 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
60
58
so] ( https://github.com/rust-lang/rust-clippy/blob/de5ccdfab68a5e37689f3c950ed1532ba9d652a0/src/misc.rs#L34 ) .
61
59
62
60
[ ` 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
69
67
lot of methods that are useful, though one of the most useful would be ` expr_ty ` (gives the type of
70
68
an AST expression). ` match_def_path() ` in Clippy's ` utils ` module can also be useful.
71
69
70
+ [ nodes in the AST docs ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_ast/ast/
71
+
72
72
## Writing code
73
73
74
74
Have 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.
82
82
83
83
## How Clippy works
84
84
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:
90
87
91
88
``` rust
92
89
// ./clippy_lints/src/lib.rs
@@ -95,25 +92,24 @@ plugin registry. For example, the [`else_if_without_else`][else_if_without_else]
95
92
pub mod else_if_without_else ;
96
93
// ...
97
94
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 ) {
99
96
// ...
100
- reg . register_early_lint_pass ( box else_if_without_else :: ElseIfWithoutElse );
97
+ store . register_early_pass ( || box else_if_without_else :: ElseIfWithoutElse );
101
98
// ...
102
99
103
- reg . register_lint_group ( " clippy::restriction" , vec! [
100
+ store . register_group ( true , " clippy::restriction" , Some ( " clippy_restriction " ) , vec! [
104
101
// ...
105
- else_if_without_else :: ELSE_IF_WITHOUT_ELSE ,
102
+ LintId :: of ( & else_if_without_else :: ELSE_IF_WITHOUT_ELSE ) ,
106
103
// ...
107
104
]);
108
105
}
109
106
```
110
107
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
113
110
that implements an [ ` EarlyLintPass ` ] [ early_lint_pass ] or [ ` LateLintPass ` ] [ late_lint_pass ] respectively. This is done in
114
111
every 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.
117
113
118
114
``` rust
119
115
// ./clippy_lints/src/else_if_without_else.rs
@@ -135,18 +131,24 @@ The difference between `EarlyLintPass` and `LateLintPass` is that the methods of
135
131
AST information. The methods of the ` LateLintPass ` trait are executed after type checking and contain type information
136
132
via the ` LateContext ` parameter.
137
133
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
139
135
logic] [ else_if_without_else ] does not depend on any type information.
140
136
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
+
141
142
## Fixing build failures caused by Rust
142
143
143
144
Clippy will sometimes fail to build from source because building it depends on unstable internal Rust features. Most of
144
145
the times we have to adapt to the changes and only very rarely there's an actual bug in Rust. Fixing build failures
145
146
caused by Rust updates, can be a good way to learn about Rust internals.
146
147
147
148
In 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.
150
152
151
153
The commit message contains a link to the PR. The PRs are usually small enough to discover the breaking API change and
152
154
if 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,
158
160
you probably want to install the latest Rust from master locally and run Clippy
159
161
using that version of Rust.
160
162
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 ` .
169
165
170
166
After fixing the build failure on this repository, we can submit a pull request
171
167
to [ ` rust-lang/rust ` ] to fix the toolstate.
@@ -206,39 +202,34 @@ You can find the Clippy bors queue [here][homu_queue].
206
202
If you have @bors permissions, you can find an overview of the available
207
203
commands [ here] [ homu_instructions ] .
208
204
209
-
210
205
## Contributions
211
206
212
207
Contributions to Clippy should be made in the form of GitHub pull requests. Each pull request will
213
208
be reviewed by a core contributor (someone with permission to land patches) and either landed in the
214
209
main tree or given feedback for changes that would be required.
215
210
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.
218
213
219
214
<!-- adapted from https://github.com/servo/servo/blob/master/CONTRIBUTING.md -->
220
215
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
231
222
[ 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
233
224
[ 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
235
226
[ clippy_rfc ] : https://github.com/rust-lang/rfcs/blob/master/text/2476-clippy-uno.md
236
227
[ rfc_stability ] : https://github.com/rust-lang/rfcs/blob/master/text/2476-clippy-uno.md#stability-guarantees
237
228
[ rfc_lint_cats ] : https://github.com/rust-lang/rfcs/blob/master/text/2476-clippy-uno.md#lint-audit-and-categories
238
229
[ triage ] : https://forge.rust-lang.org/triage-procedure.html
239
230
[ l-crash ] : https://github.com/rust-lang/rust-clippy/labels/L-crash%20%3Aboom%3A
240
231
[ 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
242
233
[ homu_instructions ] : https://buildbot2.rust-lang.org/homu/
243
234
[ homu_queue ] : https://buildbot2.rust-lang.org/homu/queue/clippy
244
235
[ `rust-lang/rust` ] : https://github.com/rust-lang/rust
0 commit comments