]> git.lizzy.rs Git - rust.git/blobdiff - CONTRIBUTING.md
Merge pull request #3382 from rust-lang-nursery/rustup
[rust.git] / CONTRIBUTING.md
index 09f4f34b98d7231c6813cf0e3e3cbc279c8e548e..c4080a5fa9c47494cce50a3ee54fbb7c616f005b 100644 (file)
@@ -1,4 +1,4 @@
-# Contributing to rust-clippy
+# Contributing to Clippy
 
 Hello fellow Rustacean! Great to see your interest in compiler internals and lints!
 
@@ -7,7 +7,7 @@ Hello fellow Rustacean! Great to see your interest in compiler internals and lin
 Clippy welcomes contributions from everyone. There are many ways to contribute to Clippy and the following document explains how
 you can contribute and how to get started.
 If you have any questions about contributing or need help with anything, feel free to ask questions on issues or
-visit the `#clippy` IRC channel on `irc.mozilla.org`.
+visit the `#clippy` IRC channel on `irc.mozilla.org` or meet us in `#wg-clippy` on [Discord](https://discord.gg/rust-lang).
 
 All contributors are expected to follow the [Rust Code of Conduct](http://www.rust-lang.org/conduct.html).
 
@@ -19,7 +19,7 @@ All contributors are expected to follow the [Rust Code of Conduct](http://www.ru
   * [Running test suite](#running-test-suite)
   * [Testing manually](#testing-manually)
   * [How Clippy works](#how-clippy-works)
-  * [Fixing nightly build failures](#fixing-nightly-build-failures)
+  * [Fixing nightly build failures](#fixing-build-failures-caused-by-rust)
 * [Contributions](#contributions)
 
 ## Getting started
@@ -63,7 +63,7 @@ an AST expression). `match_def_path()` in Clippy's `utils` module can also be us
 
 ## Writing code
 
-Compiling clippy from scratch can take almost a minute or more depending on your machine.
+Compiling Clippy from scratch can take almost a minute or more depending on your machine.
 However, since Rust 1.24.0 incremental compilation is enabled by default and compile times for small changes should be quick.
 
 [Llogiq's blog post on lints](https://llogiq.github.io/2015/06/04/workflows.html) is a nice primer
@@ -74,7 +74,7 @@ of this.
 
 ### Author lint
 
-There is also the internal `author` lint to generate clippy code that detects the offending pattern. It does not work for all of the Rust syntax, but can give a good starting point.
+There is also the internal `author` lint to generate Clippy code that detects the offending pattern. It does not work for all of the Rust syntax, but can give a good starting point.
 
 First, create a new UI test file in the `tests/ui/` directory with the pattern you want to match:
 
@@ -93,9 +93,9 @@ a `.stdout` file with the generated code:
 // ./tests/ui/my_lint.stdout
 
 if_chain! {
-    if let Expr_::ExprArray(ref elements) = stmt.node;
+    if let ExprKind::Array(ref elements) = stmt.node;
     if elements.len() == 1;
-    if let Expr_::ExprLit(ref lit) = elements[0].node;
+    if let ExprKind::Lit(ref lit) = elements[0].node;
     if let LitKind::Int(7, _) = lit.node;
     then {
         // report your lint here
@@ -148,9 +148,9 @@ Therefore you should use `tests/ui/update-all-references.sh` (after running
 ### Testing manually
 
 Manually testing against an example file is useful if you have added some
-`println!`s and test suite output becomes unreadable.  To try clippy with your
-local modifications, run `cargo run --bin clippy-driver -- -L ./target/debug input.rs` from the
-working copy root.
+`println!`s and test suite output becomes unreadable.  To try Clippy with your
+local modifications, run `env CLIPPY_TESTS=true cargo run --bin clippy-driver -- -L ./target/debug input.rs`
+from the working copy root.
 
 ### How Clippy works
 
@@ -170,7 +170,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) {
     reg.register_early_lint_pass(box else_if_without_else::ElseIfWithoutElse);
     // ...
 
-    reg.register_lint_group("clippy_restriction", vec![
+    reg.register_lint_group("clippy::restriction", vec![
         // ...
         else_if_without_else::ELSE_IF_WITHOUT_ELSE,
         // ...
@@ -179,13 +179,13 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) {
 ```
 
 The [`rustc_plugin::PluginRegistry`][plugin_registry] provides two methods to register lints: [register_early_lint_pass][reg_early_lint_pass] and [register_late_lint_pass][reg_late_lint_pass].
-Both take an object that implements an [`EarlyLintPass`][early_lint_pass] or [`LateLintPass`][late_lint_pass] respectively. This is done in every single lint. 
+Both take an object that implements an [`EarlyLintPass`][early_lint_pass] or [`LateLintPass`][late_lint_pass] respectively. This is done in every single lint.
 It's worth noting that the majority of `clippy_lints/src/lib.rs` is autogenerated by `util/update_lints.py` and you don't have to add anything by hand. When you are writing your own lint, you can use that script to save you some time.
 
 ```rust
 // ./clippy_lints/src/else_if_without_else.rs
 
-use rustc::lint::*;
+use rustc::lint::{EarlyLintPass, LintArray, LintPass};
 
 // ...
 
@@ -202,16 +202,30 @@ The difference between `EarlyLintPass` and `LateLintPass` is that the methods of
 
 That's why the `else_if_without_else` example uses the `register_early_lint_pass` function. Because the [actual lint logic][else_if_without_else] does not depend on any type information.
 
-### Fixing nightly build failures
+### Fixing build failures caused by Rust
 
-Clippy will sometimes break with new nightly version releases. This is expected because Clippy still depends on nightly Rust. Most of the times we have to adapt to the changes and only very rarely there's an actual bug in rust.
+Clippy will sometimes break because it still depends on unstable internal Rust features. Most of the times we have to adapt to the changes and only very rarely there's an actual bug in Rust. Fixing build failures caused by Rust updates, can be a good way to learn about Rust internals.
 
-In order to find out why Clippy does not work properly with a new nightly version, you can use the [rust-toolstate commit history][toolstate_commit_history].
+In order to find out why Clippy does not work properly with a new Rust commit, you can use the [rust-toolstate commit history][toolstate_commit_history].
 You will then have to look for the last commit that contains `test-pass -> build-fail` or `test-pass` -> `test-fail` for the `clippy-driver` component. [Here][toolstate_commit] is an example.
 
 The commit message contains a link to the PR. The PRs are usually small enough to discover the breaking API change and if they are bigger, they likely include some discussion that may help you to fix Clippy.
 
-Fixing nightly build failures is also a good way to learn about actual rustc internals.
+To check if Clippy is available for a specific target platform, you can check
+the [rustup component history][rustup_component_history].
+
+If you decide to make Clippy work again with a Rust commit that breaks it,
+you probably want to install the latest Rust from master locally and run Clippy
+using that version of Rust.
+
+You can use [rustup-toolchain-install-master][rtim] to do that:
+
+```
+cargo install rustup-toolchain-install-master
+rustup-toolchain-install-master -n master --force
+rustup override set master
+cargo test
+```
 
 ## Contributions
 
@@ -235,3 +249,5 @@ All code in this repository is under the [Mozilla Public License, 2.0](https://w
 [late_lint_pass]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc/lint/trait.LateLintPass.html
 [toolstate_commit_history]: https://github.com/rust-lang-nursery/rust-toolstate/commits/master
 [toolstate_commit]: https://github.com/rust-lang-nursery/rust-toolstate/commit/6ce0459f6bfa7c528ae1886492a3e0b5ef0ee547
+[rtim]: https://github.com/kennytm/rustup-toolchain-install-master
+[rustup_component_history]: https://mexus.github.io/rustup-components-history