Skip to content

Commit 6937d55

Browse files
author
Michael Wright
committed
Merge branch 'master' into fix-3739
2 parents 5332cdb + 1cdac4a commit 6937d55

File tree

233 files changed

+8356
-7187
lines changed

Some content is hidden

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

233 files changed

+8356
-7187
lines changed

CHANGELOG.md

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

55
## Unreleased / In Rust Beta or Nightly
66

7-
[b2601be...master](https://github.com/rust-lang/rust-clippy/compare/b2601be...master)
7+
[1b89724...master](https://github.com/rust-lang/rust-clippy/compare/1b89724...master)
8+
9+
## Rust 1.33 (2019-02-26)
10+
11+
[b2601be...1b89724](https://github.com/rust-lang/rust-clippy/compare/b2601be...1b89724)
12+
13+
* New lints: [`implicit_return`], [`vec_box`], [`cast_ref_to_mut`]
14+
* The `rust-clippy` repository is now part of the `rust-lang` org.
15+
* Rename `stutter` to `module_name_repetitions`
16+
* Merge `new_without_default_derive` into `new_without_default` lint
17+
* Move `large_digit_groups` from `style` group to `pedantic`
18+
* Expand `bool_comparison` to check for `<`, `<=`, `>`, `>=`, and `!=`
19+
comparisons against booleans
20+
* Expand `no_effect` to detect writes to constants such as `A_CONST.field = 2`
21+
* Expand `redundant_clone` to work on struct fields
22+
* Expand `suspicious_else_formatting` to detect `if .. {..} {..}`
23+
* Expand `use_self` to work on tuple structs and also in local macros
24+
* Fix ICE in `result_map_unit_fn` and `option_map_unit_fn`
25+
* Fix false positives in `implicit_return`
26+
* Fix false positives in `use_self`
27+
* Fix false negative in `clone_on_copy`
28+
* Fix false positive in `doc_markdown`
29+
* Fix false positive in `empty_loop`
30+
* Fix false positive in `if_same_then_else`
31+
* Fix false positive in `infinite_iter`
32+
* Fix false positive in `question_mark`
33+
* Fix false positive in `useless_asref`
34+
* Fix false positive in `wildcard_dependencies`
35+
* Fix false positive in `write_with_newline`
36+
* Add suggestion to `explicit_write`
37+
* Improve suggestions for `question_mark` lint
38+
* Fix incorrect suggestion for `get_unwrap`
839

940
## Rust 1.32 (2019-01-17)
1041

@@ -767,11 +798,11 @@ All notable changes to this project will be documented in this file.
767798
[`cmp_nan`]: https://rust-lang.github.io/rust-clippy/master/index.html#cmp_nan
768799
[`cmp_null`]: https://rust-lang.github.io/rust-clippy/master/index.html#cmp_null
769800
[`cmp_owned`]: https://rust-lang.github.io/rust-clippy/master/index.html#cmp_owned
801+
[`cognitive_complexity`]: https://rust-lang.github.io/rust-clippy/master/index.html#cognitive_complexity
770802
[`collapsible_if`]: https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_if
771803
[`const_static_lifetime`]: https://rust-lang.github.io/rust-clippy/master/index.html#const_static_lifetime
772804
[`copy_iterator`]: https://rust-lang.github.io/rust-clippy/master/index.html#copy_iterator
773805
[`crosspointer_transmute`]: https://rust-lang.github.io/rust-clippy/master/index.html#crosspointer_transmute
774-
[`cyclomatic_complexity`]: https://rust-lang.github.io/rust-clippy/master/index.html#cyclomatic_complexity
775806
[`dbg_macro`]: https://rust-lang.github.io/rust-clippy/master/index.html#dbg_macro
776807
[`decimal_literal_representation`]: https://rust-lang.github.io/rust-clippy/master/index.html#decimal_literal_representation
777808
[`declare_interior_mutable_const`]: https://rust-lang.github.io/rust-clippy/master/index.html#declare_interior_mutable_const

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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ rustc_tools_util = { version = "0.1.1", path = "rustc_tools_util"}
4747
[dev-dependencies]
4848
clippy_dev = { version = "0.0.1", path = "clippy_dev" }
4949
cargo_metadata = "0.7.1"
50-
compiletest_rs = "0.3.18"
50+
compiletest_rs = "0.3.19"
5151
lazy_static = "1.0"
5252
serde_derive = "1.0"
5353
clippy-mini-macro-test = { version = "0.2", path = "mini-macro" }

README.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ A collection of lints to catch common mistakes and improve your [Rust](https://g
1111

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

14-
* `clippy::all` (everything that has no false positives)
15-
* `clippy::pedantic` (everything)
16-
* `clippy::nursery` (new lints that aren't quite ready yet)
14+
* `clippy::all` (everything that is on by default: all the categories below except for `nursery`, `pedantic`, and `cargo`)
15+
* **`clippy::correctness`** (code that is just outright wrong or very very useless, causes hard errors by default)
1716
* `clippy::style` (code that should be written in a more idiomatic way)
1817
* `clippy::complexity` (code that does something simple but in a complex way)
1918
* `clippy::perf` (code that can be written in a faster way)
20-
* `clippy::cargo` (checks against the cargo manifest)
21-
* **`clippy::correctness`** (code that is just outright wrong or very very useless)
19+
* `clippy::pedantic` (lints which are rather strict, off by default)
20+
* `clippy::nursery` (new lints that aren't quite ready yet, off by default)
21+
* `clippy::cargo` (checks against the cargo manifest, off by default)
2222

2323
More to come, please [file an issue](https://github.com/rust-lang/rust-clippy/issues) if you have ideas!
2424

@@ -31,6 +31,8 @@ Only the following of those categories are enabled by default:
3131

3232
Other categories need to be enabled in order for their lints to be executed.
3333

34+
The [lint list](https://rust-lang.github.io/rust-clippy/master/index.html) also contains "restriction lints", which are for things which are usually not considered "bad", but may be useful to turn on in specific cases. These should be used very selectively, if at all.
35+
3436
Table of contents:
3537

3638
* [Usage instructions](#usage)
@@ -105,13 +107,13 @@ script:
105107
- cargo clippy
106108
# if you want the build job to fail when encountering warnings, use
107109
- cargo clippy -- -D warnings
108-
# 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
109111
- cargo clippy --all-targets --all-features -- -D warnings
110112
- cargo test
111113
# etc.
112114
```
113115

114-
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.
115117
In this case you can try to conditionally install Clippy from the git repo.
116118

117119
```yaml
@@ -129,7 +131,7 @@ Some lints can be configured in a TOML file named `clippy.toml` or `.clippy.toml
129131

130132
```toml
131133
blacklisted-names = ["toto", "tata", "titi"]
132-
cyclomatic-complexity-threshold = 30
134+
cognitive-complexity-threshold = 30
133135
```
134136

135137
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: 2 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,7 @@ 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/methods.rs" -not -path "tests/ui/format.rs" -not -path "tests/ui/formatting.rs" -not -path "tests/ui/empty_line_after_outer_attribute.rs" -not -path "tests/ui/double_parens.rs" -not -path "tests/ui/doc.rs" -not -path "tests/ui/unused_unit.rs" | grep "\.rs$"` ; do
62+
for file in `find tests | grep "\.rs$"` ; do
6363
rustfmt ${file} --check
6464
if [ $? -ne 0 ]; then
6565
echo "${file} needs reformatting!"

clippy_dev/src/lib.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ use walkdir::WalkDir;
1212
lazy_static! {
1313
static ref DEC_CLIPPY_LINT_RE: Regex = Regex::new(
1414
r#"(?x)
15-
declare_clippy_lint!\s*[\{(]\s*
16-
pub\s+(?P<name>[A-Z_][A-Z_0-9]*)\s*,\s*
15+
declare_clippy_lint!\s*[\{(]
16+
(?:\s+///.*)*
17+
\s+pub\s+(?P<name>[A-Z_][A-Z_0-9]*)\s*,\s*
1718
(?P<cat>[a-z_]+)\s*,\s*
1819
"(?P<desc>(?:[^"\\]+|\\(?s).(?-s))*)"\s*[})]
1920
"#
@@ -22,7 +23,8 @@ lazy_static! {
2223
static ref DEC_DEPRECATED_LINT_RE: Regex = Regex::new(
2324
r#"(?x)
2425
declare_deprecated_lint!\s*[{(]\s*
25-
pub\s+(?P<name>[A-Z_][A-Z_0-9]*)\s*,\s*
26+
(?:\s+///.*)*
27+
\s+pub\s+(?P<name>[A-Z_][A-Z_0-9]*)\s*,\s*
2628
"(?P<desc>(?:[^"\\]+|\\(?s).(?-s))*)"\s*[})]
2729
"#
2830
)
@@ -189,7 +191,7 @@ pub struct FileChange {
189191
pub new_lines: String,
190192
}
191193

192-
/// Replace a region in a file delimited by two lines matching regexes.
194+
/// Replaces a region in a file delimited by two lines matching regexes.
193195
///
194196
/// `path` is the relative path to the file on which you want to perform the replacement.
195197
///
@@ -223,7 +225,7 @@ where
223225
file_change
224226
}
225227

226-
/// Replace a region in a text delimited by two lines matching regexes.
228+
/// Replaces a region in a text delimited by two lines matching regexes.
227229
///
228230
/// * `text` is the input text on which you want to perform the replacement
229231
/// * `start` is a `&str` that describes the delimiter line before the region you want to replace.

clippy_dev/src/main.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ extern crate clap;
22
extern crate clippy_dev;
33
extern crate regex;
44

5-
use clap::{App, Arg, SubCommand};
5+
use clap::{App, AppSettings, Arg, SubCommand};
66
use clippy_dev::*;
77

88
#[derive(PartialEq)]
@@ -13,9 +13,11 @@ enum UpdateMode {
1313

1414
fn main() {
1515
let matches = App::new("Clippy developer tooling")
16+
.setting(AppSettings::SubcommandRequiredElseHelp)
1617
.subcommand(
1718
SubCommand::with_name("update_lints")
18-
.about(
19+
.about("Updates lint registration and information from the source code")
20+
.long_about(
1921
"Makes sure that:\n \
2022
* the lint count in README.md is correct\n \
2123
* the changelog contains markdown link references at the bottom\n \

clippy_lints/src/approx_const.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,28 @@ use std::f64::consts as f64;
66
use syntax::ast::{FloatTy, Lit, LitKind};
77
use syntax::symbol;
88

9-
/// **What it does:** Checks for floating point literals that approximate
10-
/// constants which are defined in
11-
/// [`std::f32::consts`](https://doc.rust-lang.org/stable/std/f32/consts/#constants)
12-
/// or
13-
/// [`std::f64::consts`](https://doc.rust-lang.org/stable/std/f64/consts/#constants),
14-
/// respectively, suggesting to use the predefined constant.
15-
///
16-
/// **Why is this bad?** Usually, the definition in the standard library is more
17-
/// precise than what people come up with. If you find that your definition is
18-
/// actually more precise, please [file a Rust
19-
/// issue](https://github.com/rust-lang/rust/issues).
20-
///
21-
/// **Known problems:** If you happen to have a value that is within 1/8192 of a
22-
/// known constant, but is not *and should not* be the same, this lint will
23-
/// report your value anyway. We have not yet noticed any false positives in
24-
/// code we tested clippy with (this includes servo), but YMMV.
25-
///
26-
/// **Example:**
27-
/// ```rust
28-
/// let x = 3.14;
29-
/// ```
309
declare_clippy_lint! {
10+
/// **What it does:** Checks for floating point literals that approximate
11+
/// constants which are defined in
12+
/// [`std::f32::consts`](https://doc.rust-lang.org/stable/std/f32/consts/#constants)
13+
/// or
14+
/// [`std::f64::consts`](https://doc.rust-lang.org/stable/std/f64/consts/#constants),
15+
/// respectively, suggesting to use the predefined constant.
16+
///
17+
/// **Why is this bad?** Usually, the definition in the standard library is more
18+
/// precise than what people come up with. If you find that your definition is
19+
/// actually more precise, please [file a Rust
20+
/// issue](https://github.com/rust-lang/rust/issues).
21+
///
22+
/// **Known problems:** If you happen to have a value that is within 1/8192 of a
23+
/// known constant, but is not *and should not* be the same, this lint will
24+
/// report your value anyway. We have not yet noticed any false positives in
25+
/// code we tested clippy with (this includes servo), but YMMV.
26+
///
27+
/// **Example:**
28+
/// ```rust
29+
/// let x = 3.14;
30+
/// ```
3131
pub APPROX_CONSTANT,
3232
correctness,
3333
"the approximate of a known float constant (in `std::fXX::consts`)"
@@ -104,7 +104,7 @@ fn check_known_consts(cx: &LateContext<'_, '_>, e: &Expr, s: symbol::Symbol, mod
104104
}
105105
}
106106

107-
/// Returns false if the number of significant figures in `value` are
107+
/// Returns `false` if the number of significant figures in `value` are
108108
/// less than `min_digits`; otherwise, returns true if `value` is equal
109109
/// to `constant`, rounded to the number of digits present in `value`.
110110
fn is_approx_const(constant: f64, value: &str, min_digits: usize) -> bool {

0 commit comments

Comments
 (0)