Skip to content

Commit 3bebee7

Browse files
committed
Auto merge of #98173 - flip1995:clippyup, r=Manishearth
Update Clippy r? `@Manishearth`
2 parents 6ec3993 + 37cdd7e commit 3bebee7

File tree

200 files changed

+4142
-1913
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

200 files changed

+4142
-1913
lines changed

Cargo.lock

+2
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,7 @@ name = "clippy_lints"
698698
version = "0.1.63"
699699
dependencies = [
700700
"cargo_metadata",
701+
"clippy_dev",
701702
"clippy_utils",
702703
"if_chain",
703704
"itertools",
@@ -708,6 +709,7 @@ dependencies = [
708709
"semver",
709710
"serde",
710711
"serde_json",
712+
"tempfile",
711713
"toml",
712714
"unicode-normalization",
713715
"unicode-script",

src/tools/clippy/.github/workflows/clippy_bors.yml

+19
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,25 @@ jobs:
143143
env:
144144
OS: ${{ runner.os }}
145145

146+
metadata_collection:
147+
needs: base
148+
runs-on: ubuntu-latest
149+
150+
steps:
151+
# Setup
152+
- uses: rust-lang/simpleinfra/github-actions/cancel-outdated-builds@master
153+
with:
154+
github_token: "${{ secrets.github_token }}"
155+
156+
- name: Checkout
157+
uses: actions/[email protected]
158+
159+
- name: Install toolchain
160+
run: rustup show active-toolchain
161+
162+
- name: Test metadata collection
163+
run: cargo collect-metadata
164+
146165
integration_build:
147166
needs: changelog
148167
runs-on: ubuntu-latest

src/tools/clippy/.github/workflows/remark.yml

+9
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,19 @@ jobs:
2626
- name: Install remark
2727
run: npm install remark-cli remark-lint remark-lint-maximum-line-length remark-preset-lint-recommended remark-gfm
2828

29+
- name: Install mdbook
30+
run: |
31+
mkdir mdbook
32+
curl -Lf https://github.com/rust-lang/mdBook/releases/download/v0.4.18/mdbook-v0.4.18-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=./mdbook
33+
echo `pwd`/mdbook >> $GITHUB_PATH
34+
2935
# Run
3036
- name: Check *.md files
3137
run: git ls-files -z '*.md' | xargs -0 -n 1 -I {} ./node_modules/.bin/remark {} -u lint -f > /dev/null
3238

39+
- name: Build mdbook
40+
run: mdbook build book
41+
3342
# These jobs doesn't actually test anything, but they're only used to tell
3443
# bors the build completed, as there is no practical way to detect when a
3544
# workflow is successful listening to webhooks only.

src/tools/clippy/.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,6 @@ helper.txt
3939
*.iml
4040
.vscode
4141
.idea
42+
43+
# mdbook generated output
44+
/book/book

src/tools/clippy/CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -3605,6 +3605,7 @@ Released 2018-09-13
36053605
[`needless_match`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_match
36063606
[`needless_option_as_deref`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_option_as_deref
36073607
[`needless_option_take`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_option_take
3608+
[`needless_parens_on_range_literals`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_parens_on_range_literals
36083609
[`needless_pass_by_value`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_pass_by_value
36093610
[`needless_question_mark`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_question_mark
36103611
[`needless_range_loop`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_range_loop
@@ -3677,6 +3678,7 @@ Released 2018-09-13
36773678
[`rc_buffer`]: https://rust-lang.github.io/rust-clippy/master/index.html#rc_buffer
36783679
[`rc_clone_in_vec_init`]: https://rust-lang.github.io/rust-clippy/master/index.html#rc_clone_in_vec_init
36793680
[`rc_mutex`]: https://rust-lang.github.io/rust-clippy/master/index.html#rc_mutex
3681+
[`read_zero_byte_vec`]: https://rust-lang.github.io/rust-clippy/master/index.html#read_zero_byte_vec
36803682
[`recursive_format_impl`]: https://rust-lang.github.io/rust-clippy/master/index.html#recursive_format_impl
36813683
[`redundant_allocation`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_allocation
36823684
[`redundant_clone`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_clone

src/tools/clippy/CONTRIBUTING.md

+17-151
Original file line numberDiff line numberDiff line change
@@ -13,44 +13,44 @@ anything, feel free to ask questions on issues or visit the `#clippy` on [Zulip]
1313
All contributors are expected to follow the [Rust Code of Conduct].
1414

1515
- [Contributing to Clippy](#contributing-to-clippy)
16-
- [Getting started](#getting-started)
17-
- [High level approach](#high-level-approach)
18-
- [Finding something to fix/improve](#finding-something-to-fiximprove)
16+
- [The Clippy book](#the-clippy-book)
17+
- [High level approach](#high-level-approach)
18+
- [Finding something to fix/improve](#finding-something-to-fiximprove)
1919
- [Writing code](#writing-code)
2020
- [Getting code-completion for rustc internals to work](#getting-code-completion-for-rustc-internals-to-work)
2121
- [IntelliJ Rust](#intellij-rust)
2222
- [Rust Analyzer](#rust-analyzer)
2323
- [How Clippy works](#how-clippy-works)
24-
- [Syncing changes between Clippy and `rust-lang/rust`](#syncing-changes-between-clippy-and-rust-langrust)
25-
- [Patching git-subtree to work with big repos](#patching-git-subtree-to-work-with-big-repos)
26-
- [Performing the sync from `rust-lang/rust` to Clippy](#performing-the-sync-from-rust-langrust-to-clippy)
27-
- [Performing the sync from Clippy to `rust-lang/rust`](#performing-the-sync-from-clippy-to-rust-langrust)
28-
- [Defining remotes](#defining-remotes)
2924
- [Issue and PR triage](#issue-and-pr-triage)
3025
- [Bors and Homu](#bors-and-homu)
3126
- [Contributions](#contributions)
3227

3328
[Zulip]: https://rust-lang.zulipchat.com/#narrow/stream/clippy
3429
[Rust Code of Conduct]: https://www.rust-lang.org/policies/code-of-conduct
3530

36-
## Getting started
31+
## The Clippy book
3732

38-
**Note: If this is your first time contributing to Clippy, you should
39-
first read the [Basics docs](doc/basics.md).**
33+
If you're new to Clippy and don't know where to start the [Clippy book] includes
34+
a developer guide and is a good place to start your journey.
4035

41-
### High level approach
36+
<!-- FIXME: Link to the deployed book, once it is deployed through CI -->
37+
[Clippy book]: book/src
38+
39+
## High level approach
4240

4341
1. Find something to fix/improve
4442
2. Change code (likely some file in `clippy_lints/src/`)
45-
3. Follow the instructions in the [Basics docs](doc/basics.md) to get set up
43+
3. Follow the instructions in the [Basics docs](book/src/development/basics.md)
44+
to get set up
4645
4. Run `cargo test` in the root directory and wiggle code until it passes
4746
5. Open a PR (also can be done after 2. if you run into problems)
4847

49-
### Finding something to fix/improve
48+
## Finding something to fix/improve
5049

51-
All issues on Clippy are mentored, if you want help simply ask @Manishearth, @flip1995, @phansch
52-
or @llogiq directly by mentioning them in the issue or over on [Zulip]. This list may be out of date.
53-
All currently active mentors can be found [here](https://github.com/rust-lang/highfive/blob/master/highfive/configs/rust-lang/rust-clippy.json#L3)
50+
All issues on Clippy are mentored, if you want help simply ask someone from the
51+
Clippy team directly by mentioning them in the issue or over on [Zulip]. All
52+
currently active team members can be found
53+
[here](https://github.com/rust-lang/highfive/blob/master/highfive/configs/rust-lang/rust-clippy.json#L3)
5454

5555
Some issues are easier than others. The [`good-first-issue`] label can be used to find the easy
5656
issues. You can use `@rustbot claim` to assign the issue to yourself.
@@ -91,20 +91,6 @@ an AST expression). `match_def_path()` in Clippy's `utils` module can also be us
9191
[let chains]: https://github.com/rust-lang/rust/pull/94927
9292
[nest-less]: https://github.com/rust-lang/rust-clippy/blob/5e4f0922911536f80d9591180fa604229ac13939/clippy_lints/src/bit_mask.rs#L133-L159
9393

94-
## Writing code
95-
96-
Have a look at the [docs for writing lints][adding_lints] for more details.
97-
98-
If you want to add a new lint or change existing ones apart from bugfixing, it's
99-
also a good idea to give the [stability guarantees][rfc_stability] and
100-
[lint categories][rfc_lint_cats] sections of the [Clippy 1.0 RFC][clippy_rfc] a
101-
quick read.
102-
103-
[adding_lints]: https://github.com/rust-lang/rust-clippy/blob/master/doc/adding_lints.md
104-
[clippy_rfc]: https://github.com/rust-lang/rfcs/blob/master/text/2476-clippy-uno.md
105-
[rfc_stability]: https://github.com/rust-lang/rfcs/blob/master/text/2476-clippy-uno.md#stability-guarantees
106-
[rfc_lint_cats]: https://github.com/rust-lang/rfcs/blob/master/text/2476-clippy-uno.md#lint-audit-and-categories
107-
10894
## Getting code-completion for rustc internals to work
10995

11096
### IntelliJ Rust
@@ -205,126 +191,6 @@ That's why the `else_if_without_else` example uses the `register_early_pass` fun
205191
[early_lint_pass]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/trait.EarlyLintPass.html
206192
[late_lint_pass]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/trait.LateLintPass.html
207193

208-
## Syncing changes between Clippy and [`rust-lang/rust`]
209-
210-
Clippy currently gets built with a pinned nightly version.
211-
212-
In the `rust-lang/rust` repository, where rustc resides, there's a copy of Clippy
213-
that compiler hackers modify from time to time to adapt to changes in the unstable
214-
API of the compiler.
215-
216-
We need to sync these changes back to this repository periodically, and the changes
217-
made to this repository in the meantime also need to be synced to the `rust-lang/rust` repository.
218-
219-
To avoid flooding the `rust-lang/rust` PR queue, this two-way sync process is done
220-
in a bi-weekly basis if there's no urgent changes. This is done starting on the day of
221-
the Rust stable release and then every other week. That way we guarantee that we keep
222-
this repo up to date with the latest compiler API, and every feature in Clippy is available
223-
for 2 weeks in nightly, before it can get to beta. For reference, the first sync
224-
following this cadence was performed the 2020-08-27.
225-
226-
This process is described in detail in the following sections. For general information
227-
about `subtree`s in the Rust repository see [Rust's `CONTRIBUTING.md`][subtree].
228-
229-
### Patching git-subtree to work with big repos
230-
231-
Currently, there's a bug in `git-subtree` that prevents it from working properly
232-
with the [`rust-lang/rust`] repo. There's an open PR to fix that, but it's stale.
233-
Before continuing with the following steps, we need to manually apply that fix to
234-
our local copy of `git-subtree`.
235-
236-
You can get the patched version of `git-subtree` from [here][gitgitgadget-pr].
237-
Put this file under `/usr/lib/git-core` (taking a backup of the previous file)
238-
and make sure it has the proper permissions:
239-
240-
```bash
241-
sudo cp --backup /path/to/patched/git-subtree.sh /usr/lib/git-core/git-subtree
242-
sudo chmod --reference=/usr/lib/git-core/git-subtree~ /usr/lib/git-core/git-subtree
243-
sudo chown --reference=/usr/lib/git-core/git-subtree~ /usr/lib/git-core/git-subtree
244-
```
245-
246-
_Note:_ The first time running `git subtree push` a cache has to be built. This
247-
involves going through the complete Clippy history once. For this you have to
248-
increase the stack limit though, which you can do with `ulimit -s 60000`.
249-
Make sure to run the `ulimit` command from the same session you call git subtree.
250-
251-
_Note:_ If you are a Debian user, `dash` is the shell used by default for scripts instead of `sh`.
252-
This shell has a hardcoded recursion limit set to 1000. In order to make this process work,
253-
you need to force the script to run `bash` instead. You can do this by editing the first
254-
line of the `git-subtree` script and changing `sh` to `bash`.
255-
256-
### Performing the sync from [`rust-lang/rust`] to Clippy
257-
258-
Here is a TL;DR version of the sync process (all of the following commands have
259-
to be run inside the `rust` directory):
260-
261-
1. Clone the [`rust-lang/rust`] repository or make sure it is up to date.
262-
2. Checkout the commit from the latest available nightly. You can get it using `rustup check`.
263-
3. Sync the changes to the rust-copy of Clippy to your Clippy fork:
264-
```bash
265-
# Make sure to change `your-github-name` to your github name in the following command. Also be
266-
# sure to either use a net-new branch, e.g. `sync-from-rust`, or delete the branch beforehand
267-
# because changes cannot be fast forwarded
268-
git subtree push -P src/tools/clippy [email protected]:your-github-name/rust-clippy sync-from-rust
269-
```
270-
271-
_Note:_ This will directly push to the remote repository. You can also push
272-
to your local copy by replacing the remote address with `/path/to/rust-clippy`
273-
directory.
274-
275-
_Note:_ Most of the time you have to create a merge commit in the
276-
`rust-clippy` repo (this has to be done in the Clippy repo, not in the
277-
rust-copy of Clippy):
278-
```bash
279-
git fetch origin && git fetch upstream
280-
git checkout sync-from-rust
281-
git merge upstream/master
282-
```
283-
4. Open a PR to `rust-lang/rust-clippy` and wait for it to get merged (to
284-
accelerate the process ping the `@rust-lang/clippy` team in your PR and/or
285-
~~annoy~~ ask them in the [Zulip] stream.)
286-
287-
### Performing the sync from Clippy to [`rust-lang/rust`]
288-
289-
All of the following commands have to be run inside the `rust` directory.
290-
291-
1. Make sure Clippy itself is up-to-date by following the steps outlined in the previous
292-
section if necessary.
293-
294-
2. Sync the `rust-lang/rust-clippy` master to the rust-copy of Clippy:
295-
```bash
296-
git checkout -b sync-from-clippy
297-
git subtree pull -P src/tools/clippy https://github.com/rust-lang/rust-clippy master
298-
```
299-
3. Open a PR to [`rust-lang/rust`]
300-
301-
### Defining remotes
302-
303-
You may want to define remotes, so you don't have to type out the remote
304-
addresses on every sync. You can do this with the following commands (these
305-
commands still have to be run inside the `rust` directory):
306-
307-
```bash
308-
# Set clippy-upstream remote for pulls
309-
$ git remote add clippy-upstream https://github.com/rust-lang/rust-clippy
310-
# Make sure to not push to the upstream repo
311-
$ git remote set-url --push clippy-upstream DISABLED
312-
# Set clippy-origin remote to your fork for pushes
313-
$ git remote add clippy-origin [email protected]:your-github-name/rust-clippy
314-
# Set a local remote
315-
$ git remote add clippy-local /path/to/rust-clippy
316-
```
317-
318-
You can then sync with the remote names from above, e.g.:
319-
320-
```bash
321-
$ git subtree push -P src/tools/clippy clippy-local sync-from-rust
322-
```
323-
324-
[gitgitgadget-pr]: https://github.com/gitgitgadget/git/pull/493
325-
[subtree]: https://rustc-dev-guide.rust-lang.org/contributing.html#external-dependencies-subtree
326-
[`rust-lang/rust`]: https://github.com/rust-lang/rust
327-
328194
## Issue and PR triage
329195

330196
Clippy is following the [Rust triage procedure][triage] for issues and pull

src/tools/clippy/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ rustc_tools_util = { version = "0.2", path = "rustc_tools_util" }
5858
[features]
5959
deny-warnings = ["clippy_lints/deny-warnings"]
6060
integration = ["tempfile"]
61-
internal = ["clippy_lints/internal"]
61+
internal = ["clippy_lints/internal", "tempfile"]
6262

6363
[package.metadata.rust-analyzer]
6464
# This package uses #[feature(rustc_private)]

src/tools/clippy/book/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Clippy Book
2+
3+
This is the source for the Clippy Book. See the
4+
[book](src/infrastructure/book.md) for more information.

src/tools/clippy/book/book.toml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
[book]
2+
authors = ["The Rust Clippy Developers"]
3+
language = "en"
4+
multilingual = false
5+
src = "src"
6+
title = "Clippy Documentation"
7+
8+
[rust]
9+
edition = "2018"
10+
11+
[output.html]
12+
edit-url-template = "https://github.com/rust-lang/rust-clippy/edit/master/book/{path}"
13+
git-repository-url = "https://github.com/rust-lang/rust-clippy/tree/master/book"
14+
mathjax-support = true
15+
site-url = "/rust-clippy/"
16+
17+
[output.html.playground]
18+
editable = true
19+
line-numbers = true
20+
21+
[output.html.search]
22+
boost-hierarchy = 2
23+
boost-paragraph = 1
24+
boost-title = 2
25+
expand = true
26+
heading-split-level = 2
27+
limit-results = 20
28+
use-boolean-and = true

src/tools/clippy/book/src/README.md

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Clippy
2+
3+
[![Clippy Test](https://github.com/rust-lang/rust-clippy/workflows/Clippy%20Test/badge.svg?branch=auto&event=push)](https://github.com/rust-lang/rust-clippy/actions?query=workflow%3A%22Clippy+Test%22+event%3Apush+branch%3Aauto)
4+
[![License: MIT OR Apache-2.0](https://img.shields.io/crates/l/clippy.svg)](#license)
5+
6+
A collection of lints to catch common mistakes and improve your
7+
[Rust](https://github.com/rust-lang/rust) code.
8+
9+
[There are over 500 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
10+
11+
Lints are divided into categories, each with a default [lint
12+
level](https://doc.rust-lang.org/rustc/lints/levels.html). You can choose how
13+
much Clippy is supposed to ~~annoy~~ help you by changing the lint level by
14+
category.
15+
16+
| Category | Description | Default level |
17+
| --------------------- | ----------------------------------------------------------------------------------- | ------------- |
18+
| `clippy::all` | all lints that are on by default (correctness, suspicious, style, complexity, perf) | **warn/deny** |
19+
| `clippy::correctness` | code that is outright wrong or useless | **deny** |
20+
| `clippy::suspicious` | code that is most likely wrong or useless | **warn** |
21+
| `clippy::complexity` | code that does something simple but in a complex way | **warn** |
22+
| `clippy::perf` | code that can be written to run faster | **warn** |
23+
| `clippy::style` | code that should be written in a more idiomatic way | **warn** |
24+
| `clippy::pedantic` | lints which are rather strict or might have false positives | allow |
25+
| `clippy::nursery` | new lints that are still under development | allow |
26+
| `clippy::cargo` | lints for the cargo manifest | allow | | allow |
27+
28+
More to come, please [file an
29+
issue](https://github.com/rust-lang/rust-clippy/issues) if you have ideas!
30+
31+
The [lint list](https://rust-lang.github.io/rust-clippy/master/index.html) also
32+
contains "restriction lints", which are for things which are usually not
33+
considered "bad", but may be useful to turn on in specific cases. These should
34+
be used very selectively, if at all.

src/tools/clippy/book/src/SUMMARY.md

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Summary
2+
3+
[Introduction](README.md)
4+
5+
- [Installation](installation.md)
6+
- [Usage](usage.md)
7+
- [Configuration](configuration.md)
8+
- [Clippy's Lints](lints.md)
9+
- [Continuous Integration](continuous_integration/README.md)
10+
- [GitHub Actions](continuous_integration/github_actions.md)
11+
- [Travis CI](continuous_integration/travis.md)
12+
- [Development](development/README.md)
13+
- [Basics](development/basics.md)
14+
- [Adding Lints](development/adding_lints.md)
15+
- [Common Tools](development/common_tools_writing_lints.md)
16+
- [Infrastructure](development/infrastructure/README.md)
17+
- [Syncing changes between Clippy and rust-lang/rust](development/infrastructure/sync.md)
18+
- [Backporting Changes](development/infrastructure/backport.md)
19+
- [Updating the Changelog](development/infrastructure/changelog_update.md)
20+
- [Release a New Version](development/infrastructure/release.md)
21+
- [The Clippy Book](development/infrastructure/book.md)
22+
- [Proposals](development/proposals/README.md)
23+
- [Roadmap 2021](development/proposals/roadmap-2021.md)

0 commit comments

Comments
 (0)