Commit graph

10548 commits

Author SHA1 Message Date
bors
f870876d92 Auto merge of #6659 - phlip9:let_and_return_fix, r=phansch
Fix let_and_return false positive

The issue:

See this Rust playground link: https://play.rust-lang.org/?edition=2018&gist=12cb5d1e7527f8c37743b87fc4a53748

Run the above with clippy to see the following warning:

```
warning: returning the result of a `let` binding from a block
  --> src/main.rs:24:5
   |
23 |     let value = Foo::new(&x).value();
   |     --------------------------------- unnecessary `let` binding
24 |     value
   |     ^^^^^
   |
   = note: `#[warn(clippy::let_and_return)]` on by default
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#let_and_return
help: return the expression directly
   |
23 |
24 |     Foo::new(&x).value()
   |
```

Implementing the suggested fix, removing the temporary let binding,
yields a compiler error:

```
error[E0597]: `x` does not live long enough
  --> src/main.rs:23:14
   |
23 |     Foo::new(&x).value()
   |     ---------^^-
   |     |        |
   |     |        borrowed value does not live long enough
   |     a temporary with access to the borrow is created here ...
24 | }
   | -
   | |
   | `x` dropped here while still borrowed
   | ... and the borrow might be used here, when that temporary is dropped and runs the `Drop` code for type `Foo`
   |
   = note: the temporary is part of an expression at the end of a block;
           consider forcing this temporary to be dropped sooner, before the block's local variables are dropped
help: for example, you could save the expression's value in a new local variable `x` and then make `x` be the expression at the end of the block
   |
23 |     let x = Foo::new(&x).value(); x
   |     ^^^^^^^                     ^^^
```

The fix:

Of course, clippy looks like it should already handle this edge case;
however, it appears `utils::fn_def_id` is not returning a `DefId` for
`Foo::new`. Changing the `qpath_res` lookup to use the child Path
`hir_id` instead of the parent Call `hir_id` fixes the issue.

changelog: none
2021-02-02 15:04:35 +00:00
bors
8d82ac5e73 Auto merge of #6661 - Manishearth:exhaustive-fix, r=flip1995
exhaustive_structs: don't trigger for structs with private fields

changelog: Restrict `exhaustive_structs` to structs with all-public
fields
2021-02-02 07:59:39 +00:00
Philipp Krones
4a13c8c22e
Fix test formatting 2021-02-02 08:59:23 +01:00
Manish Goregaokar
0fb09d6b21 exhaustive_structs: don't trigger for structs with private fields 2021-02-01 18:42:08 -08:00
bors
c5f3f9df3b Auto merge of #6603 - ThibsG:MatchOverlappingArm5986, r=flip1995
Do not lint when range is completely included into another one

This fix has been developed following this [comment](https://github.com/rust-lang/rust-clippy/issues/5986#issuecomment-703313548).
So this will be linted:
```
|----------|
        |-----------|
```
Now this won't be linted:
```
              |---|
|--------------------|
```
and this will still lint:
```
|--------|
|--------------|
```

Fixes: #5986

changelog: Fix FPs in match_overlapping_arm, when first arm is completely included in second arm
2021-01-31 15:09:55 +00:00
bors
ed112741b2 Auto merge of #6656 - phansch:command-failed-print-stderr, r=flip1995
clippy_dev: Pass stderr to CommandFailed

This improves error reporting when running `rustfmt` fails for some reason, as seen [on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/Issue.20with.20rustfmt). It will now include the stderr output in the `CliError::CommandFailed` error.

changelog: none
2021-01-31 14:56:53 +00:00
Philipp Hansch
da26b2149f
clippy_dev: Pass stderr to CommandFailed 2021-01-31 11:21:33 +01:00
bors
95c0459217 Auto merge of #6654 - flip1995:no_lazy_static_regex, r=flip1995
No lazy static regex

r? `@llogiq`

#6500

regex is unnecessary for this lint (https://github.com/rust-lang/rust-clippy/pull/6500#discussion_r558555071)
lazy_static is unnecessary. The std lazy feature should be  used instead.

changelog: none
2021-01-30 16:49:45 +00:00
flip1995
3874631600
Remove unknown_clippy_lints allow attribute 2021-01-30 17:43:20 +01:00
flip1995
797cf6554d
Get rid of regex and lazy_static dependencies 2021-01-30 17:43:00 +01:00
bors
4db76a6bcc Auto merge of #6653 - flip1995:rustup, r=flip1995
Rustup

changelog: Deprecate `unknown_clippy_lints` (integrated in `unknown_lints`)

r? `@ghost`
2021-01-30 14:53:30 +00:00
flip1995
60ab57e4eb
Bump nightly version -> 2021-01-30 2021-01-30 15:52:02 +01:00
flip1995
e2859437f9
Merge remote-tracking branch 'upstream/master' into rustup 2021-01-30 15:51:16 +01:00
Philip Hayes
7f1595e18f Fix let_and_return false positive
The issue:

See this Rust playground link: https://play.rust-lang.org/?edition=2018&gist=12cb5d1e7527f8c37743b87fc4a53748

Run the above with clippy to see the following warning:

```
warning: returning the result of a `let` binding from a block
  --> src/main.rs:24:5
   |
23 |     let value = Foo::new(&x).value();
   |     --------------------------------- unnecessary `let` binding
24 |     value
   |     ^^^^^
   |
   = note: `#[warn(clippy::let_and_return)]` on by default
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#let_and_return
help: return the expression directly
   |
23 |
24 |     Foo::new(&x).value()
   |
```

Implementing the suggested fix, removing the temporary let binding,
yields a compiler error:

```
error[E0597]: `x` does not live long enough
  --> src/main.rs:23:14
   |
23 |     Foo::new(&x).value()
   |     ---------^^-
   |     |        |
   |     |        borrowed value does not live long enough
   |     a temporary with access to the borrow is created here ...
24 | }
   | -
   | |
   | `x` dropped here while still borrowed
   | ... and the borrow might be used here, when that temporary is dropped and runs the `Drop` code for type `Foo`
   |
   = note: the temporary is part of an expression at the end of a block;
           consider forcing this temporary to be dropped sooner, before the block's local variables are dropped
help: for example, you could save the expression's value in a new local variable `x` and then make `x` be the expression at the end of the block
   |
23 |     let x = Foo::new(&x).value(); x
   |     ^^^^^^^                     ^^^
```

The fix:

Of course, clippy looks like it should already handle this edge case;
however, it appears `utils::fn_def_id` is not returning a `DefId` for
`Foo::new`. Changing the `qpath_res` lookup to use the child Path
`hir_id` instead of the parent Call `hir_id` fixes the issue.
2021-01-29 22:19:09 -08:00
Yuki Okushi
c18d6f1ffa Rollup merge of #81176 - camsteffen:qpath-res, r=oli-obk
Improve safety of `LateContext::qpath_res`

This is my first rustc code change, inspired by hacking on clippy!

The first change is to clear cached `TypeckResults` from `LateContext` when visiting a nested item. I took a hint from [here](5e91c4ecc0/compiler/rustc_privacy/src/lib.rs (L1300)).

Clippy has a `qpath_res` util function to avoid a possible ICE in `LateContext::qpath_res`. But the docs of `LateContext::qpath_res` promise no ICE. So this updates the `LateContext` method to keep its promises, and removes the util function.

Related: rust-lang/rust-clippy#4545

CC ````````````@eddyb```````````` since you've done related work
CC ````````````@flip1995```````````` FYI
2021-01-29 09:17:32 +09:00
Yuki Okushi
299ff49667 Rollup merge of #81277 - flip1995:from_diag_items, r=matthewjasper
Make more traits of the From/Into family diagnostic items

Following traits are now diagnostic items:
- `From` (unchanged)
- `Into`
- `TryFrom`
- `TryInto`

This also adds symbols for those items:
- `into_trait`
- `try_from_trait`
- `try_into_trait`

Related: https://github.com/rust-lang/rust-clippy/pull/6620#discussion_r562482587
2021-01-28 15:09:08 +09:00
Yuki Okushi
7bd3d6ce22 Rollup merge of #79951 - LeSeulArtichaut:ty-ir, r=nikomatsakis
Refractor a few more types to `rustc_type_ir`

In the continuation of #79169, ~~blocked on that PR~~.

This PR:
 - moves `IntVarValue`, `FloatVarValue`, `InferTy` (and friends) and `Variance`
 - creates the `IntTy`, `UintTy` and `FloatTy` enums in `rustc_type_ir`, based on their `ast` and `chalk_ir` equilavents, and uses them for types in the rest of the compiler.

~~I will split up that commit to make this easier to review and to have a better commit history.~~
EDIT: done, I split the PR in commits of 200-ish lines each

r? `````@nikomatsakis````` cc `````@jackh726`````
2021-01-28 15:09:02 +09:00
bors
5db215bca8 Auto merge of #6645 - camsteffen:syntax-highlighting, r=phansch
Fix website syntax highlighting

changelog: none

Fix syntax highlighting on website when the docs contain ` ```rust,ignore`
2021-01-27 06:47:07 +00:00
Cameron Steffen
cbf9d492b9 Fix some website syntax highlighting 2021-01-26 17:38:52 -06:00
bors
be0125bed4 Auto merge of #6469 - matthiaskrgr:clippy_dev_crater, r=flip1995
add "cargo dev crater" to run clippy on a fixed set of crates and diff the lint warnings

`cargo dev crater` now does the following:
build clippy in debug mode
for a fixed set of crates:
 download and extract the crate
 run compiled clippy on the crate
 dump the warnings into a file that is inside the repo

We can then do a "git diff" and see what effects our clippy changes had on a tiny fraction of the rust ecosystem and can see when an change unexpectedly added or silenced a lot of warnings.

Checking all the crates took less than 5 minutes on my system.

Should help with https://github.com/rust-lang/rust-clippy/issues/6429

---

*Please write a short comment explaining your change (or "none" for internal only changes)*
changelog: extend cargo dev to run clippy against a fixed set of crates and compare warnings
2021-01-26 06:58:04 +00:00
bors
8d57cee9ca Auto merge of #6617 - Manishearth:exhaustive_enums, r=camsteffen
New lint: exhaustive_enums, exhaustive_structs

Fixes #6616

changelog: Added restriction lint: `exhaustive_enums`, `exhaustive_structs`
2021-01-25 23:06:39 +00:00
Manish Goregaokar
3e3dff7135 Add test with attrs 2021-01-25 14:39:03 -08:00
Manish Goregaokar
e0ae980fab Better suggestion span 2021-01-25 14:35:57 -08:00
bors
c56b32899f Auto merge of #6630 - xFrednet:0000-configuration-documentation, r=llogiq
Documentation for adding configuration to a lint and common abbreviations

This PR adds some commonly used abbreviations to the `basis.md` file and a guide on how to implement a configuration value for a lint.

* [Rendered `/doc/basics.md` (Abbreviation list)](https://github.com/xFrednet/rust-clippy/blob/0000-configuration-documentation/doc/basics.md#common-abbreviations)
* [Rendered `/doc/adding_lints.md` (Configuration value guide)](https://github.com/xFrednet/rust-clippy/blob/0000-configuration-documentation/doc/adding_lints.md#adding-configuration-to-a-lint)

I'm not sure if the guide is written in the best way. Style suggestions are appreciated. 🙃

 ---

Again a big **thank you** for everyone who helped to collect the abbreviation list over on [zulip]. I had a lot of fun, and it was also very informative. Keep up the good work 🙃

[zulip]: https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/Common.20abbreviations.20in.20basics.2Emd/near/223548065
---

changelog: none
2021-01-25 00:25:31 +00:00
xFrednet
0373dc3ade Added documentation for adding a configuration to lints
* Fixed some spelling
2021-01-24 21:16:41 +01:00
ThibsG
051891173d Add more tests for match_overlapping_arm lint 2021-01-24 12:28:59 +01:00
Matthias Krüger
5b6a18362b lintcheck: fix paths in the logs 2021-01-23 02:18:11 +01:00
Matthias Krüger
d0d28b11d7 update lintcheck-logs 2021-01-23 02:18:11 +01:00
Matthias Krüger
83fcf95f52 rename cargo dev crater to cargo dev lintcheck 2021-01-23 02:18:11 +01:00
Matthias Krüger
48fc948ca3 clippy dev crater: address more review commetns
make serde a feature-dep
save clippy version in the crater log
2021-01-23 02:18:11 +01:00
Matthias Krüger
94a73d7b11 add shortcut "dev-crater" command to build and run "cargo dev crater" 2021-01-23 02:18:11 +01:00
Matthias Krüger
ec1902ce43 cargo dev crater: throw an error if we can't find our specified crate in the .toml list 2021-01-23 02:18:11 +01:00
Matthias Krüger
b6ef1e282e clippy dev crater: add option to only check a single one of the listed crates with --only crate 2021-01-23 02:18:11 +01:00
Matthias Krüger
d257101109 make stats stable 2021-01-23 02:18:11 +01:00
Matthias Krüger
e56c9a5253 cargo dev crater: gather and save lint statistics (how often a lint triggered) 2021-01-23 02:18:11 +01:00
Matthias Krüger
4ec9cb84bb cargo dev crater: refactor to get a list of all ClippyWarnings 2021-01-23 02:18:11 +01:00
Matthias Krüger
6c5bf2778f clippy dev crater: use and parse clippy messages as json message, to get the lint name of a warning 2021-01-23 02:18:11 +01:00
Matthias Krüger
62337f2842 remove duplicate code and other cleanup 2021-01-23 02:18:11 +01:00
Matthias Krüger
22824d21da rename symbols: krate -> crate 2021-01-23 02:18:11 +01:00
Matthias Krüger
f986d78c5e cargo dev crater: support multiple versions per crate 2021-01-23 02:18:11 +01:00
Matthias Krüger
588efa7da9 use a .toml file to list the crates we want to check
Also sort lint results alphabetically.
2021-01-23 02:18:11 +01:00
Matthias Krüger
a9fce6d2d0 allow clippy::filter_map 2021-01-23 02:18:11 +01:00
Matthias Krüger
ccfaa338ed cargo dev crater: share target dir between clippy runs, enable pedantic and cargo lints, ignore tokei for now. 2021-01-23 02:18:11 +01:00
Matthias Krüger
1e5ac1dfd2 cargo dev crater: add more crates to be checked 2021-01-23 02:18:11 +01:00
Matthias Krüger
728dc06d88 add the log file 2021-01-23 02:18:11 +01:00
Matthias Krüger
dbb8c0020e cargo dev crater: save all warnings into a file 2021-01-23 02:18:11 +01:00
Matthias Krüger
7314133722 cargo dev crater: cleanup, don't re-download and reextract crates on every run 2021-01-23 02:18:11 +01:00
Matthias Krüger
734d2052df print all clippy warnings in the end 2021-01-23 02:18:11 +01:00
Matthias Krüger
2360a7cad0 cargo clippy dev: collecting one-line clippy warnings works now 2021-01-23 02:18:11 +01:00
Matthias Krüger
69c0757334 clippy cargo dev: fix checking of crates 2021-01-23 02:18:11 +01:00