Skip to content

Commit 0905ec4

Browse files
committed
Merge remote-tracking branch 'upstream/master' into rustup
2 parents c31637e + 70bca29 commit 0905ec4

File tree

117 files changed

+1578
-345
lines changed

Some content is hidden

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

117 files changed

+1578
-345
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -3437,9 +3437,11 @@ Released 2018-09-13
34373437
[`almost_complete_letter_range`]: https://rust-lang.github.io/rust-clippy/master/index.html#almost_complete_letter_range
34383438
[`almost_swapped`]: https://rust-lang.github.io/rust-clippy/master/index.html#almost_swapped
34393439
[`approx_constant`]: https://rust-lang.github.io/rust-clippy/master/index.html#approx_constant
3440+
[`arithmetic`]: https://rust-lang.github.io/rust-clippy/master/index.html#arithmetic
34403441
[`as_conversions`]: https://rust-lang.github.io/rust-clippy/master/index.html#as_conversions
34413442
[`as_underscore`]: https://rust-lang.github.io/rust-clippy/master/index.html#as_underscore
34423443
[`assertions_on_constants`]: https://rust-lang.github.io/rust-clippy/master/index.html#assertions_on_constants
3444+
[`assertions_on_result_states`]: https://rust-lang.github.io/rust-clippy/master/index.html#assertions_on_result_states
34433445
[`assign_op_pattern`]: https://rust-lang.github.io/rust-clippy/master/index.html#assign_op_pattern
34443446
[`assign_ops`]: https://rust-lang.github.io/rust-clippy/master/index.html#assign_ops
34453447
[`async_yields_async`]: https://rust-lang.github.io/rust-clippy/master/index.html#async_yields_async
@@ -3793,6 +3795,7 @@ Released 2018-09-13
37933795
[`nonsensical_open_options`]: https://rust-lang.github.io/rust-clippy/master/index.html#nonsensical_open_options
37943796
[`nonstandard_macro_braces`]: https://rust-lang.github.io/rust-clippy/master/index.html#nonstandard_macro_braces
37953797
[`not_unsafe_ptr_arg_deref`]: https://rust-lang.github.io/rust-clippy/master/index.html#not_unsafe_ptr_arg_deref
3798+
[`obfuscated_if_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#obfuscated_if_else
37963799
[`octal_escapes`]: https://rust-lang.github.io/rust-clippy/master/index.html#octal_escapes
37973800
[`ok_expect`]: https://rust-lang.github.io/rust-clippy/master/index.html#ok_expect
37983801
[`only_used_in_recursion`]: https://rust-lang.github.io/rust-clippy/master/index.html#only_used_in_recursion

Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ compiletest_rs = { version = "0.8", features = ["tmp"] }
3232
tester = "0.9"
3333
regex = "1.5"
3434
toml = "0.5"
35+
walkdir = "2.3"
3536
# This is used by the `collect-metadata` alias.
3637
filetime = "0.2"
3738

@@ -41,6 +42,7 @@ filetime = "0.2"
4142
rustc-workspace-hack = "1.0"
4243

4344
# UI test dependencies
45+
clap = { version = "3.1", features = ["derive"] }
4446
clippy_utils = { path = "clippy_utils" }
4547
derive-new = "0.5"
4648
if_chain = "1.0"

book/src/continuous_integration/github_actions.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# GitHub Actions
22

3-
On the GitHub hosted runners, Clippy from the latest stable Rust version comes
4-
pre-installed. So all you have to do is to run `cargo clippy`.
3+
GitHub hosted runners using the latest stable version of Rust have Clippy pre-installed.
4+
It is as simple as running `cargo clippy` to run lints against the codebase.
55

66
```yml
77
on: push
@@ -15,7 +15,7 @@ jobs:
1515
clippy_check:
1616
runs-on: ubuntu-latest
1717
steps:
18-
- uses: actions/checkout@v1
18+
- uses: actions/checkout@v3
1919
- name: Run Clippy
2020
run: cargo clippy --all-targets --all-features
2121
```

book/src/development/adding_lints.md

+35-10
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ because that's clearly a non-descriptive name.
1010
- [Adding a new lint](#adding-a-new-lint)
1111
- [Setup](#setup)
1212
- [Getting Started](#getting-started)
13+
- [Defining Our Lint](#defining-our-lint)
14+
- [Standalone](#standalone)
15+
- [Specific Type](#specific-type)
16+
- [Tests Location](#tests-location)
1317
- [Testing](#testing)
1418
- [Cargo lints](#cargo-lints)
1519
- [Rustfix tests](#rustfix-tests)
@@ -36,17 +40,38 @@ See the [Basics](basics.md#get-the-code) documentation.
3640
## Getting Started
3741

3842
There is a bit of boilerplate code that needs to be set up when creating a new
39-
lint. Fortunately, you can use the clippy dev tools to handle this for you. We
43+
lint. Fortunately, you can use the Clippy dev tools to handle this for you. We
4044
are naming our new lint `foo_functions` (lints are generally written in snake
41-
case), and we don't need type information so it will have an early pass type
42-
(more on this later on). If you're not sure if the name you chose fits the lint,
43-
take a look at our [lint naming guidelines][lint_naming]. To get started on this
44-
lint you can run `cargo dev new_lint --name=foo_functions --pass=early
45-
--category=pedantic` (category will default to nursery if not provided). This
46-
command will create two files: `tests/ui/foo_functions.rs` and
47-
`clippy_lints/src/foo_functions.rs`, as well as [registering the
48-
lint](#lint-registration). For cargo lints, two project hierarchies (fail/pass)
49-
will be created by default under `tests/ui-cargo`.
45+
case), and we don't need type information, so it will have an early pass type
46+
(more on this later). If you're unsure if the name you chose fits the lint,
47+
take a look at our [lint naming guidelines][lint_naming].
48+
49+
## Defining Our Lint
50+
To get started, there are two ways to define our lint.
51+
52+
### Standalone
53+
Command: `cargo dev new_lint --name=foo_functions --pass=early --category=pedantic`
54+
(category will default to nursery if not provided)
55+
56+
This command will create a new file: `clippy_lints/src/foo_functions.rs`, as well
57+
as [register the lint](#lint-registration).
58+
59+
### Specific Type
60+
Command: `cargo dev new_lint --name=foo_functions --type=functions --category=pedantic`
61+
62+
This command will create a new file: `clippy_lints/src/{type}/foo_functions.rs`.
63+
64+
Notice how this command has a `--type` flag instead of `--pass`. Unlike a standalone
65+
definition, this lint won't be registered in the traditional sense. Instead, you will
66+
call your lint from within the type's lint pass, found in `clippy_lints/src/{type}/mod.rs`.
67+
68+
A "type" is just the name of a directory in `clippy_lints/src`, like `functions` in
69+
the example command. These are groupings of lints with common behaviors, so if your
70+
lint falls into one, it would be best to add it to that type.
71+
72+
### Tests Location
73+
Both commands will create a file: `tests/ui/foo_functions.rs`. For cargo lints,
74+
two project hierarchies (fail/pass) will be created by default under `tests/ui-cargo`.
5075

5176
Next, we'll open up these files and add our lint!
5277

book/src/development/infrastructure/book.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ instructions for other options.
2525
## Make changes
2626

2727
The book's
28-
[src](https://github.com/joshrotenberg/rust-clippy/tree/clippy_guide/book/src)
28+
[src](https://github.com/rust-lang/rust-clippy/tree/master/book/src)
2929
directory contains all of the markdown files used to generate the book. If you
3030
want to see your changes in real time, you can use the mdbook `serve` command to
3131
run a web server locally that will automatically update changes as they are

clippy_dev/src/fmt.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub enum CliError {
1313
IoError(io::Error),
1414
RustfmtNotInstalled,
1515
WalkDirError(walkdir::Error),
16-
RaSetupActive,
16+
IntellijSetupActive,
1717
}
1818

1919
impl From<io::Error> for CliError {
@@ -48,7 +48,7 @@ pub fn run(check: bool, verbose: bool) {
4848
.expect("Failed to read clippy Cargo.toml")
4949
.contains(&"[target.'cfg(NOT_A_PLATFORM)'.dependencies]")
5050
{
51-
return Err(CliError::RaSetupActive);
51+
return Err(CliError::IntellijSetupActive);
5252
}
5353

5454
rustfmt_test(context)?;
@@ -93,11 +93,11 @@ pub fn run(check: bool, verbose: bool) {
9393
CliError::WalkDirError(err) => {
9494
eprintln!("error: {}", err);
9595
},
96-
CliError::RaSetupActive => {
96+
CliError::IntellijSetupActive => {
9797
eprintln!(
9898
"error: a local rustc repo is enabled as path dependency via `cargo dev setup intellij`.
9999
Not formatting because that would format the local repo as well!
100-
Please revert the changes to Cargo.tomls first."
100+
Please revert the changes to Cargo.tomls with `cargo dev remove intellij`."
101101
);
102102
},
103103
}

clippy_dev/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![cfg_attr(bootstrap, feature(let_chains))]
21
#![feature(let_else)]
32
#![feature(once_cell)]
43
#![feature(rustc_private)]

clippy_dev/src/main.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ fn main() {
3636
match new_lint::create(
3737
matches.get_one::<String>("pass"),
3838
matches.get_one::<String>("name"),
39-
matches.get_one::<String>("category"),
39+
matches.get_one::<String>("category").map(String::as_str),
40+
matches.get_one::<String>("type").map(String::as_str),
4041
matches.contains_id("msrv"),
4142
) {
4243
Ok(_) => update_lints::update(update_lints::UpdateMode::Change),
@@ -157,7 +158,8 @@ fn get_clap_config() -> ArgMatches {
157158
.help("Specify whether the lint runs during the early or late pass")
158159
.takes_value(true)
159160
.value_parser([PossibleValue::new("early"), PossibleValue::new("late")])
160-
.required(true),
161+
.conflicts_with("type")
162+
.required_unless_present("type"),
161163
Arg::new("name")
162164
.short('n')
163165
.long("name")
@@ -183,6 +185,11 @@ fn get_clap_config() -> ArgMatches {
183185
PossibleValue::new("internal_warn"),
184186
])
185187
.takes_value(true),
188+
Arg::new("type")
189+
.long("type")
190+
.help("What directory the lint belongs in")
191+
.takes_value(true)
192+
.required(false),
186193
Arg::new("msrv").long("msrv").help("Add MSRV config code to the lint"),
187194
]),
188195
Command::new("setup")

0 commit comments

Comments
 (0)