@@ -78,7 +78,7 @@ fn main() {
7878
7979Now we can run the test with ` TESTNAME=ui/foo_functions cargo uitest ` .
8080Currently this test will fail. If you go through the output you will see that we
81- have to add some missing imports to our lint file .
81+ are told that ` clippy::foo_functions ` is an unknown lint, which is expected .
8282
8383While you are working on implementing your lint, you can keep running the UI
8484test. That allows you to check if the output is turning into what you want.
@@ -97,16 +97,16 @@ that test. Rustfix will apply the suggestions from the lint to the code of the
9797test file and compare that to the contents of a ` .fixed ` file.
9898
9999Use ` tests/ui/update-all-references.sh ` to automatically generate the
100- ` .fixed ` file after running ` cargo test ` .
100+ ` .fixed ` file after running the tests .
101101
102102With tests in place, let's have a look at implementing our lint now.
103103
104104### Testing manually
105105
106- Manually testing against an example file is useful if you have added some
107- ` println! ` s and test suite output becomes unreadable. To try Clippy with your
108- local modifications, run ` env CLIPPY_TESTS=true cargo run --bin clippy-driver -- -L ./target/debug input.rs `
109- from the working copy root.
106+ Manually testing against an example file can be useful if you have added some
107+ ` println! ` s and the test suite output becomes unreadable. To try Clippy with
108+ your local modifications, run `env CLIPPY_TESTS=true cargo run --bin
109+ clippy-driver -- -L ./target/debug input.rs` from the working copy root.
110110
111111### Lint declaration
112112
@@ -177,9 +177,9 @@ in `clippy_lints/src/lib.rs`:
177177reg . register_early_lint_pass (box foo_functions :: FooFunctionsPass );
178178```
179179
180- Without that, running the UI tests would produce an error like `unknown clippy
181- lint: clippy::foo_functions`. The next decision we have to make is which lint
182- pass our lint is going to need.
180+ This should fix the ` unknown clippy lint: clippy::foo_functions ` error that we
181+ saw when we executed our tests the first time. The next decision we have to make
182+ is which lint pass our lint is going to need.
183183
184184### Lint passes
185185
@@ -189,8 +189,6 @@ This is good, because it makes writing this particular lint less complicated.
189189
190190We have to make this decision with every new Clippy lint. It boils down to using
191191either [ ` EarlyLintPass ` ] [ early_lint_pass ] or [ ` LateLintPass ` ] [ late_lint_pass ] .
192- This is a result of Rust's compilation process. You can read more about it [ in
193- the rustc guide] [ compilation_stages ] .
194192
195193In short, the ` LateLintPass ` has access to type information while the
196194` EarlyLintPass ` doesn't. If you don't need access to type information, use the
@@ -209,8 +207,7 @@ use rustc::{declare_tool_lint, lint_array};
209207### Emitting a lint
210208
211209With UI tests and the lint declaration in place, we can start working on the
212- implementation of the lint logic. We can keep executing the tests until we make
213- them pass.
210+ implementation of the lint logic.
214211
215212Let's start by implementing the ` EarlyLintPass ` for our ` FooFunctionsPass ` :
216213
@@ -229,9 +226,12 @@ the next section. Let's worry about the details later and emit our lint for
229226* every* function definition first.
230227
231228Depending on how complex we want our lint message to be, we can choose from a
232- variety of lint emission functions. They can all be found in
229+ variety of lint emission functions. They can all be found in
233230[ ` clippy_lints/src/utils/diagnostics.rs ` ] [ diagnostics ] .
234231
232+ ` span_help_and_lint ` seems most appropriate in this case. It allows us to
233+ provide an extra help message and we can't really suggest a better name
234+ automatically. This is how it looks:
235235
236236``` rust
237237impl EarlyLintPass for Pass {
@@ -247,9 +247,11 @@ impl EarlyLintPass for Pass {
247247}
248248```
249249
250+ Running our UI test should now produce output that contains the lint message.
251+
250252### Adding the lint logic
251253
252- Writing the logic for your lint will most likely be different from this example,
254+ Writing the logic for our lint will most likely be different from this example,
253255so this section is kept rather short.
254256
255257Using the [ ` check_fn ` ] [ check_fn ] method gives us access to [ ` FnKind ` ] [ fn_kind ]
0 commit comments