Skip to content

Commit 70b84e5

Browse files
committed
Merge branch 'master' of github.com:HarrisonMc555/rust-clippy
2 parents d885e3a + bf3f7d5 commit 70b84e5

File tree

354 files changed

+11166
-10374
lines changed

Some content is hidden

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

354 files changed

+11166
-10374
lines changed

.cargo/config

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
[alias]
22
uitest = "test --test compile-test"
3+
4+
[build]
5+
rustflags = ["-Zunstable-options"]

.github/PULL_REQUEST_TEMPLATE

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<!--
2+
Thank you for making Clippy better!
3+
4+
We're collecting our changelog from pull request descriptions.
5+
If your PR only updates to the latest nightly, you can leave the
6+
`changelog` entry as `none`. Otherwise, please write a short comment
7+
explaining your change.
8+
9+
If your PR fixes an issue, you can add "fixes #issue_number" into this
10+
PR description. This way the issue will be automatically closed when
11+
your PR is merged.
12+
13+
If you added a new lint, here's a checklist for things that will be
14+
checked during review or continuous integration.
15+
16+
- [ ] Followed [lint naming conventions][lint_naming]
17+
- [ ] Added passing UI tests (including committed `.stderr` file)
18+
- [ ] `cargo test` passes locally
19+
- [ ] Executed `util/dev update_lints`
20+
- [ ] Added lint documentation
21+
- [ ] Run `cargo fmt`
22+
23+
Note that you can skip the above if you are just opening a WIP PR in
24+
order to get feedback.
25+
26+
Delete this line and everything above before opening your PR -->
27+
28+
changelog: none

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ matrix:
7878
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
7979
- env: INTEGRATION=bluss/rust-itertools
8080
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
81+
- env: INTEGRATION=Marwes/combine
82+
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
8183
allow_failures:
8284
- os: windows
8385
env: CARGO_INCREMENTAL=0 BASE_TESTS=true

CHANGELOG.md

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,59 @@ All notable changes to this project will be documented in this file.
44

55
## Unreleased / In Rust Beta or Nightly
66

7-
[1b89724...master](https://github.com/rust-lang/rust-clippy/compare/1b89724...master)
7+
[eb9f9b1...master](https://github.com/rust-lang/rust-clippy/compare/eb9f9b1...master)
8+
9+
## Rust 1.35 (beta)
10+
[1fac380..37f5c1e](https://github.com/rust-lang/rust-clippy/compare/1fac380...37f5c1e)
11+
12+
* New lint: [`drop_bounds`] to detect `T: Drop` bounds
13+
* Rename `cyclomatic_complexity` to [`cognitive_complexity`], start work on making lint more practical for Rust code
14+
* Move [`get_unwrap`] to the restriction category
15+
* Improve suggestions for [`iter_cloned_collect`]
16+
* Improve suggestions for [`cast_lossless`] to suggest suffixed literals
17+
* Fix false positives in [`print_with_newline`] and [`write_with_newline`] pertaining to raw strings
18+
* Fix false positive in [`needless_range_loop`] pertaining to structs without a `.iter()`
19+
* Fix false positive in [`bool_comparison`] pertaining to non-bool types
20+
* Fix false positive in [`redundant_closure`] pertaining to differences in borrows
21+
* Fix false positive in [`option_map_unwrap_or`] on non-copy types
22+
* Fix false positives in [`missing_const_for_fn`] pertaining to macros and trait method impls
23+
* Fix false positive in [`needless_pass_by_value`] pertaining to procedural macros
24+
* Fix false positive in [`needless_continue`] pertaining to loop labels
25+
* Fix false positive for [`boxed_local`] pertaining to arguments moved into closures
26+
* Fix false positive for [`use_self`] in nested functions
27+
* Fix suggestion for [`expect_fun_call`] (https://github.com/rust-lang/rust-clippy/pull/3846)
28+
* Fix suggestion for [`explicit_counter_loop`] to deal with parenthesizing range variables
29+
* Fix suggestion for [`single_char_pattern`] to correctly escape single quotes
30+
* Avoid triggering [`redundant_closure`] in macros
31+
* ICE fixes: [#3805](https://github.com/rust-lang/rust-clippy/pull/3805), [#3772](https://github.com/rust-lang/rust-clippy/pull/3772), [#3741](https://github.com/rust-lang/rust-clippy/pull/3741)
32+
33+
## Rust 1.34 (2019-04-10)
34+
35+
[1b89724...1fac380](https://github.com/rust-lang/rust-clippy/compare/1b89724...1fac380)
36+
37+
* New lint: [`assertions_on_constants`] to detect for example `assert!(true)`
38+
* New lint: [`dbg_macro`] to detect uses of the `dbg!` macro
39+
* New lint: [`missing_const_for_fn`] that can suggest functions to be made `const`
40+
* New lint: [`too_many_lines`] to detect functions with excessive LOC. It can be
41+
configured using the `too-many-lines-threshold` configuration.
42+
* New lint: [`wildcard_enum_match_arm`] to check for wildcard enum matches using `_`
43+
* Expand `redundant_closure` to also work for methods (not only functions)
44+
* Fix ICEs in `vec_box`, `needless_pass_by_value` and `implicit_hasher`
45+
* Fix false positive in `cast_sign_loss`
46+
* Fix false positive in `integer_arithmetic`
47+
* Fix false positive in `unit_arg`
48+
* Fix false positives in `implicit_return`
49+
* Add suggestion to `explicit_write`
50+
* Improve suggestions for `question_mark` lint
51+
* Fix incorrect suggestion for `cast_lossless`
52+
* Fix incorrect suggestion for `expect_fun_call`
53+
* Fix incorrect suggestion for `needless_bool`
54+
* Fix incorrect suggestion for `needless_range_loop`
55+
* Fix incorrect suggestion for `use_self`
56+
* Fix incorrect suggestion for `while_let_on_iterator`
57+
* Clippy is now slightly easier to invoke in non-cargo contexts. See
58+
[#3665][pull3665] for more details.
59+
* We now have [improved documentation][adding_lints] on how to add new lints
860

961
## Rust 1.33 (2019-02-26)
1062

@@ -763,6 +815,8 @@ All notable changes to this project will be documented in this file.
763815
[`AsMut`]: https://doc.rust-lang.org/std/convert/trait.AsMut.html
764816
[`AsRef`]: https://doc.rust-lang.org/std/convert/trait.AsRef.html
765817
[configuration file]: ./rust-clippy#configuration
818+
[pull3665]: https://github.com/rust-lang/rust-clippy/pull/3665
819+
[adding_lints]: https://github.com/rust-lang/rust-clippy/blob/master/doc/adding_lints.md
766820

767821
<!-- begin autogenerated links to lint list -->
768822
[`absurd_extreme_comparisons`]: https://rust-lang.github.io/rust-clippy/master/index.html#absurd_extreme_comparisons
@@ -798,11 +852,11 @@ All notable changes to this project will be documented in this file.
798852
[`cmp_nan`]: https://rust-lang.github.io/rust-clippy/master/index.html#cmp_nan
799853
[`cmp_null`]: https://rust-lang.github.io/rust-clippy/master/index.html#cmp_null
800854
[`cmp_owned`]: https://rust-lang.github.io/rust-clippy/master/index.html#cmp_owned
855+
[`cognitive_complexity`]: https://rust-lang.github.io/rust-clippy/master/index.html#cognitive_complexity
801856
[`collapsible_if`]: https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_if
802857
[`const_static_lifetime`]: https://rust-lang.github.io/rust-clippy/master/index.html#const_static_lifetime
803858
[`copy_iterator`]: https://rust-lang.github.io/rust-clippy/master/index.html#copy_iterator
804859
[`crosspointer_transmute`]: https://rust-lang.github.io/rust-clippy/master/index.html#crosspointer_transmute
805-
[`cyclomatic_complexity`]: https://rust-lang.github.io/rust-clippy/master/index.html#cyclomatic_complexity
806860
[`dbg_macro`]: https://rust-lang.github.io/rust-clippy/master/index.html#dbg_macro
807861
[`decimal_literal_representation`]: https://rust-lang.github.io/rust-clippy/master/index.html#decimal_literal_representation
808862
[`declare_interior_mutable_const`]: https://rust-lang.github.io/rust-clippy/master/index.html#declare_interior_mutable_const
@@ -961,6 +1015,7 @@ All notable changes to this project will be documented in this file.
9611015
[`panic_params`]: https://rust-lang.github.io/rust-clippy/master/index.html#panic_params
9621016
[`panicking_unwrap`]: https://rust-lang.github.io/rust-clippy/master/index.html#panicking_unwrap
9631017
[`partialeq_ne_impl`]: https://rust-lang.github.io/rust-clippy/master/index.html#partialeq_ne_impl
1018+
[`path_buf_push_overwrite`]: https://rust-lang.github.io/rust-clippy/master/index.html#path_buf_push_overwrite
9641019
[`possible_missing_comma`]: https://rust-lang.github.io/rust-clippy/master/index.html#possible_missing_comma
9651020
[`precedence`]: https://rust-lang.github.io/rust-clippy/master/index.html#precedence
9661021
[`print_literal`]: https://rust-lang.github.io/rust-clippy/master/index.html#print_literal
@@ -1022,6 +1077,7 @@ All notable changes to this project will be documented in this file.
10221077
[`transmute_int_to_float`]: https://rust-lang.github.io/rust-clippy/master/index.html#transmute_int_to_float
10231078
[`transmute_ptr_to_ptr`]: https://rust-lang.github.io/rust-clippy/master/index.html#transmute_ptr_to_ptr
10241079
[`transmute_ptr_to_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#transmute_ptr_to_ref
1080+
[`transmuting_null`]: https://rust-lang.github.io/rust-clippy/master/index.html#transmuting_null
10251081
[`trivial_regex`]: https://rust-lang.github.io/rust-clippy/master/index.html#trivial_regex
10261082
[`trivially_copy_pass_by_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#trivially_copy_pass_by_ref
10271083
[`type_complexity`]: https://rust-lang.github.io/rust-clippy/master/index.html#type_complexity

CONTRIBUTING.md

Lines changed: 3 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@ All contributors are expected to follow the [Rust Code of Conduct](http://www.ru
1414
* [Getting started](#getting-started)
1515
* [Finding something to fix/improve](#finding-something-to-fiximprove)
1616
* [Writing code](#writing-code)
17-
* [Author lint](#author-lint)
18-
* [Documentation](#documentation)
19-
* [Running test suite](#running-test-suite)
20-
* [Running rustfmt](#running-rustfmt)
21-
* [Testing manually](#testing-manually)
2217
* [How Clippy works](#how-clippy-works)
2318
* [Fixing nightly build failures](#fixing-build-failures-caused-by-rust)
2419
* [Issue and PR Triage](#issue-and-pr-triage)
@@ -73,121 +68,15 @@ an AST expression). `match_def_path()` in Clippy's `utils` module can also be us
7368

7469
## Writing code
7570

76-
Clippy depends on the current git master version of rustc, which can change rapidly. Make sure you're
77-
working near rust-clippy's master, and use the `setup-toolchain.sh` script to configure the appropriate
78-
toolchain for this directory.
79-
80-
[Llogiq's blog post on lints](https://llogiq.github.io/2015/06/04/workflows.html) is a nice primer
81-
to lint-writing, though it does get into advanced stuff. Most lints consist of an implementation of
82-
`LintPass` with one or more of its default methods overridden. See the existing lints for examples
83-
of this.
71+
Have a look at the [docs for writing lints](doc/adding_lints.md) for more details. [Llogiq's blog post on lints](https://llogiq.github.io/2015/06/04/workflows.html) is also a nice primer
72+
to lint-writing, though it does get into advanced stuff and may be a bit
73+
outdated.
8474

8575
If you want to add a new lint or change existing ones apart from bugfixing, it's
8676
also a good idea to give the [stability guarantees][rfc_stability] and
8777
[lint categories][rfc_lint_cats] sections of the [Clippy 1.0 RFC][clippy_rfc] a
8878
quick read.
8979

90-
### Author lint
91-
92-
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.
93-
94-
First, create a new UI test file in the `tests/ui/` directory with the pattern you want to match:
95-
96-
```rust
97-
// ./tests/ui/my_lint.rs
98-
fn main() {
99-
#[clippy::author]
100-
let arr: [i32; 1] = [7]; // Replace line with the code you want to match
101-
}
102-
```
103-
104-
Now you run `TESTNAME=ui/my_lint cargo uitest` to produce
105-
a `.stdout` file with the generated code:
106-
107-
```rust
108-
// ./tests/ui/my_lint.stdout
109-
110-
if_chain! {
111-
if let ExprKind::Array(ref elements) = stmt.node;
112-
if elements.len() == 1;
113-
if let ExprKind::Lit(ref lit) = elements[0].node;
114-
if let LitKind::Int(7, _) = lit.node;
115-
then {
116-
// report your lint here
117-
}
118-
}
119-
```
120-
121-
If the command was executed successfully, you can copy the code over to where you are implementing your lint.
122-
123-
### Documentation
124-
125-
Please document your lint with a doc comment akin to the following:
126-
127-
```rust
128-
/// **What it does:** Checks for ... (describe what the lint matches).
129-
///
130-
/// **Why is this bad?** Supply the reason for linting the code.
131-
///
132-
/// **Known problems:** None. (Or describe where it could go wrong.)
133-
///
134-
/// **Example:**
135-
///
136-
/// ```rust
137-
/// // Bad
138-
/// Insert a short example of code that triggers the lint
139-
///
140-
/// // Good
141-
/// Insert a short example of improved code that doesn't trigger the lint
142-
/// ```
143-
```
144-
145-
Once your lint is merged it will show up in the [lint list](https://rust-lang.github.io/rust-clippy/master/index.html)
146-
147-
### Running test suite
148-
149-
Use `cargo test` to run the whole testsuite.
150-
151-
If you don't want to wait for all tests to finish, you can also execute a single test file by using `TESTNAME` to specify the test to run:
152-
153-
```bash
154-
TESTNAME=ui/empty_line_after_outer_attr cargo uitest
155-
```
156-
157-
Clippy uses UI tests. UI tests check that the output of the compiler is exactly as expected.
158-
Of course there's little sense in writing the output yourself or copying it around.
159-
Therefore you should use `tests/ui/update-all-references.sh` (after running
160-
`cargo test`) and check whether the output looks as you expect with `git diff`. Commit all
161-
`*.stderr` files, too.
162-
163-
If the lint you are working on is making use of structured suggestions, the
164-
test file should include a `// run-rustfix` comment at the top. This will
165-
additionally run [rustfix](https://github.com/rust-lang-nursery/rustfix) for
166-
that test. Rustfix will apply the suggestions from the lint to the code of the
167-
test file and compare that to the contents of a `.fixed` file.
168-
169-
Use `tests/ui/update-all-references.sh` to automatically generate the
170-
`.fixed` file after running `cargo test`.
171-
172-
### Running rustfmt
173-
174-
[Rustfmt](https://github.com/rust-lang/rustfmt) is a tool for formatting Rust code according
175-
to style guidelines. The code has to be formatted by `rustfmt` before a PR will be merged.
176-
177-
It can be installed via `rustup`:
178-
```bash
179-
rustup component add rustfmt
180-
```
181-
182-
Use `cargo fmt --all` to format the whole codebase.
183-
184-
### Testing manually
185-
186-
Manually testing against an example file is useful if you have added some
187-
`println!`s and test suite output becomes unreadable. To try Clippy with your
188-
local modifications, run `env CLIPPY_TESTS=true cargo run --bin clippy-driver -- -L ./target/debug input.rs`
189-
from the working copy root.
190-
19180
## How Clippy works
19281

19382
Clippy is a [rustc compiler plugin][compiler_plugin]. The main entry point is at [`src/lib.rs`][main_entry]. In there, the lint registration is delegated to the [`clippy_lints`][lint_crate] crate.

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,8 @@ semver = "0.9"
4545
rustc_tools_util = { version = "0.1.1", path = "rustc_tools_util"}
4646

4747
[dev-dependencies]
48-
clippy_dev = { version = "0.0.1", path = "clippy_dev" }
4948
cargo_metadata = "0.7.1"
50-
compiletest_rs = "0.3.18"
49+
compiletest_rs = { version = "0.3.22", features = ["tmp"] }
5150
lazy_static = "1.0"
5251
serde_derive = "1.0"
5352
clippy-mini-macro-test = { version = "0.2", path = "mini-macro" }

README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
A collection of lints to catch common mistakes and improve your [Rust](https://github.com/rust-lang/rust) code.
99

10-
[There are 297 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
10+
[There are 299 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
1111

1212
We have a bunch of lint categories to allow you to choose how much Clippy is supposed to ~~annoy~~ help you:
1313

@@ -107,13 +107,13 @@ script:
107107
- cargo clippy
108108
# if you want the build job to fail when encountering warnings, use
109109
- cargo clippy -- -D warnings
110-
# in order to also check tests and none-default crate features, use
110+
# in order to also check tests and non-default crate features, use
111111
- cargo clippy --all-targets --all-features -- -D warnings
112112
- cargo test
113113
# etc.
114114
```
115115

116-
It might happen that Clippy is not available for a certain nightly release.
116+
If you are on nightly, It might happen that Clippy is not available for a certain nightly release.
117117
In this case you can try to conditionally install Clippy from the git repo.
118118

119119
```yaml
@@ -125,13 +125,18 @@ before_script:
125125
# etc
126126
```
127127

128+
Note that adding `-D warnings` will cause your build to fail if **any** warnings are found in your code.
129+
That includes warnings found by rustc (e.g. `dead_code`, etc.). If you want to avoid this and only cause
130+
an error for clippy warnings, use `#![deny(clippy::all)]` in your code or `-D clippy::all` on the command
131+
line. (You can swap `clippy::all` with the specific lint category you are targeting.)
132+
128133
## Configuration
129134

130135
Some lints can be configured in a TOML file named `clippy.toml` or `.clippy.toml`. It contains a basic `variable = value` mapping eg.
131136

132137
```toml
133138
blacklisted-names = ["toto", "tata", "titi"]
134-
cyclomatic-complexity-threshold = 30
139+
cognitive-complexity-threshold = 30
135140
```
136141

137142
See the [list of lints](https://rust-lang.github.io/rust-clippy/master/index.html) for more information about which lints can be configured and the

ci/base-tests.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ echo "Running clippy base tests"
44

55
PATH=$PATH:./node_modules/.bin
66
if [ "$TRAVIS_OS_NAME" == "linux" ]; then
7-
remark -f *.md > /dev/null
7+
remark -f *.md -f doc/*.md > /dev/null
88
fi
99
# build clippy in debug mode and run tests
1010
cargo build --features debugging
@@ -59,7 +59,9 @@ rustup override set nightly
5959
# avoid loop spam and allow cmds with exit status != 0
6060
set +ex
6161

62-
for file in `find tests -not -path "tests/ui/doc.rs" -not -path "tests/ui/unused_unit.rs" | grep "\.rs$"` ; do
62+
# Excluding `ice-3891.rs` because the code triggers a rustc parse error which
63+
# makes rustfmt fail.
64+
for file in `find tests -not -path "tests/ui/crashes/ice-3891.rs" | grep "\.rs$"` ; do
6365
rustfmt ${file} --check
6466
if [ $? -ne 0 ]; then
6567
echo "${file} needs reformatting!"

0 commit comments

Comments
 (0)