@@ -155,47 +155,77 @@ That's why the `else_if_without_else` example uses the `register_early_pass` fun
155155
156156## Fixing build failures caused by Rust
157157
158- Clippy will sometimes fail to build from source because building it depends on unstable internal Rust features. Most of
159- the times we have to adapt to the changes and only very rarely there's an actual bug in Rust. Fixing build failures
160- caused by Rust updates, can be a good way to learn about Rust internals.
158+ Clippy currently gets built with ` rustc ` of the ` rust-lang/rust ` ` master `
159+ branch. Most of the times we have to adapt to the changes and only very rarely
160+ there's an actual bug in Rust.
161+
162+ If you decide to make Clippy work again with a Rust commit that breaks it, you
163+ have to sync the ` rust-lang/rust-clippy ` repository with the ` subtree ` copy of
164+ Clippy in the ` rust-lang/rust ` repository.
165+
166+ For general information about ` subtree ` s in the Rust repository see [ Rust's
167+ ` CONTRIBUTING.md ` ] [ subtree ] .
168+
169+ Here is a TL;DR version of the sync process (all of the following commands have
170+ to be run inside the ` rust ` directory):
171+
172+ 1 . Clone the [ ` rust-lang/rust ` ] repository
173+ 2 . Sync the changes to the rust-copy of Clippy to your Clippy fork:
174+ ``` bash
175+ # Make sure to change `your-github-name` to your github name in the following command
176+ git subtree push -P src/tools/clippy git@github.com:your-github-name/rust-clippy sync-from-rust
177+ ```
178+ _Note:_ This will directly push to the remote repository. You can also push
179+ to your local copy by replacing the remote address with ` /path/to/rust-clippy`
180+ directory.
181+
182+ _Note:_ Most of the time you have to create a merge commit in the
183+ ` rust-clippy` repo (this has to be done in the Clippy repo, not in the
184+ rust-copy of Clippy):
185+ ` ` ` bash
186+ git fetch origin && git fetch upstream
187+ git checkout sync-from-rust
188+ git merge upstream/master
189+ ` ` `
190+ 3. Open a PR to ` rust-lang/rust-clippy` and wait for it to get merged (to
191+ accelerate the process ping the ` @rust-lang/clippy` team in your PR and/or
192+ ~ ~annoy~~ ask them in the [Discord] channel.)
193+ 4. Sync the ` rust-lang/rust-clippy` master to the rust-copy of Clippy:
194+ ` ` ` bash
195+ git checkout -b sync-from-clippy
196+ git subtree pull -P src/tools/clippy https://github.com/rust-lang/rust-clippy master
197+ ` ` `
198+ 5. Open a PR to [` rust-lang/rust` ]
199+
200+ Also, you may want to define remotes, so you don' t have to type out the remote
201+ addresses on every sync. You can do this with the following commands (these
202+ commands still have to be run inside the `rust` directory):
161203
162- In order to find out why Clippy does not work properly with a new Rust commit, you can use the [ rust-toolstate commit
163- history] [ toolstate_commit_history ] . You will then have to look for the last commit that contains
164- ` test-pass -> build-fail ` or ` test-pass -> test-fail ` for the ` clippy-driver ` component.
165- [ Here] [ toolstate_commit ] is an example.
166-
167- The commit message contains a link to the PR. The PRs are usually small enough to discover the breaking API change and
168- if they are bigger, they likely include some discussion that may help you to fix Clippy.
169-
170- To check if Clippy is available for a specific target platform, you can check
171- the [ rustup component history] [ rustup_component_history ] .
172-
173- If you decide to make Clippy work again with a Rust commit that breaks it,
174- you probably want to install the latest Rust from master locally and run Clippy
175- using that version of Rust.
176-
177- You can set up the master toolchain by running ` ./setup-toolchain.sh ` . That script will install
178- [ rustup-toolchain-install-master] [ rtim ] and master toolchain, then run ` rustup override set master ` .
179-
180- After fixing the build failure on this repository, we can submit a pull request
181- to [ ` rust-lang/rust ` ] to fix the toolstate.
204+ ```bash
205+ # Set clippy-upstream remote for pulls
206+ $ git remote add clippy-upstream https://github.com/rust-lang/rust-clippy
207+ # Make sure to not push to the upstream repo
208+ $ git remote set-url --push clippy-upstream DISABLED
209+ # Set clippy-origin remote to your fork for pushes
210+ $ git remote add clippy-origin git@github.com:your-github-name/rust-clippy
211+ # Set a local remote
212+ $ git remote add clippy-local /path/to/rust-clippy
213+ ```
182214
183- To submit a pull request, you should follow these steps :
215+ You can then sync with the remote names from above, e.g. :
184216
185217```bash
186- # Assuming you already cloned the rust-lang/rust repo and you're in the correct directory
187- git submodule update --remote src/tools/clippy
188- cargo update -p clippy
189- git add -u
190- git commit -m " Update Clippy"
191- ./x.py test -i --stage 1 src/tools/clippy # This is optional and should succeed anyway
192- # Open a PR in rust-lang/rust
218+ $ git subtree push -P src/tools/clippy clippy-local sync-from-rust
193219```
194220
195- [ rustup_component_history ] : https://rust-lang.github.io/rustup-components-history
196- [ toolstate_commit_history ] : https://github.com/rust-lang-nursery/rust-toolstate/commits/master
197- [ toolstate_commit ] : https://github.com/rust-lang-nursery/rust-toolstate/commit/aad74d8294e198a7cf8ac81a91aebb7f3bbcf727
198- [ rtim ] : https://github.com/kennytm/rustup-toolchain-install-master
221+ _Note:_ The first time running `git subtree push` a cache has to be built. This
222+ involves going through the complete Clippy history once. For this you have to
223+ increase the stack limit though, which you can do with `ulimit -s 60000`. For
224+ this to work, you will need the fix of `git subtree` available
225+ [here][gitgitgadget-pr].
226+
227+ [gitgitgadget-pr]: https://github.com/gitgitgadget/git/pull/493
228+ [subtree]: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#external-dependencies-subtree
199229[`rust-lang/rust`]: https://github.com/rust-lang/rust
200230
201231## Issue and PR triage
0 commit comments