Commit graph

10562 commits

Author SHA1 Message Date
Manish Goregaokar
5c957b8a6f Merge remote-tracking branch 'origin/master' into rustup 2021-02-02 16:46:12 -08:00
bors
11edf92946 Auto merge of #6639 - xFrednet:0000-configuration-documentation-some-nits, r=flip1995
Updated some NITs in the documentation from #6630

I've implemented the two suggestions from #6630 that were added after the merge. This PR also changes the example code to use `register_*_pass` instead of `register_late_pass`. I'm not sure if this is better or worse, but it makes it clearer in my opinion. Let me know if I should change it back.

---

changelog: none

r? `@flip1995`
2021-02-02 18:05:35 +00:00
xFrednet
a2d2aeeb4b
Updated the list of active mentors 2021-02-02 18:53:15 +01:00
bors
448a97bf52 Auto merge of #81405 - bugadani:ast, r=cjgillot
Box the biggest ast::ItemKind variants

This PR is a different approach on https://github.com/rust-lang/rust/pull/81400, aiming to save memory in humongous ASTs.

The three affected item kind enums are:
 - `ast::ItemKind` (208 -> 112 bytes)
 - `ast::AssocItemKind` (176 -> 72 bytes)
 - `ast::ForeignItemKind` (176 -> 72 bytes)
2021-02-02 17:34:08 +00:00
bors
9fd4f3ea8f Auto merge of #6664 - camsteffen:path-to-res, r=Manishearth
Remove Option from `path_to_res` return type

changelog: none

Tiny cleanup for `path_to_res` to return `Res` instead of `Option<Res>`.
2021-02-02 16:56:39 +00:00
bors
28794e956e Auto merge of #6523 - brightly-salty:missing-panic-doc, r=flip1995
Add new lint "missing_panics_doc"

fixes #1974
changelog: Added the "missing_panics_doc" lint which lints when public functions that may panic are missing "# Panics" in their doc comment
2021-02-02 15:37:24 +00:00
Caden Haustein
bde667af7e
Add missing_panics_doc lint 2021-02-02 16:36:32 +01:00
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
9607b5c6ac Auto merge of #80851 - m-ou-se:panic-2021, r=petrochenkov
Implement Rust 2021 panic

This implements the Rust 2021 versions of `panic!()`. See https://github.com/rust-lang/rust/issues/80162 and https://github.com/rust-lang/rfcs/pull/3007.

It does so by replacing `{std, core}::panic!()` by a bulitin macro that expands to either `$crate::panic::panic_2015!(..)` or `$crate::panic::panic_2021!(..)` depending on the edition of the caller.

This does not yet make std's panic an alias for core's panic on Rust 2021 as the RFC proposes. That will be a separate change: c5273bdfb2 That change is blocked on figuring out what to do with https://github.com/rust-lang/rust/issues/80846 first.
2021-02-01 10:25:31 +00:00
Dániel Buga
6fd01e0b6e Box the biggest ast::ItemKind variants 2021-02-01 09:23:39 +01:00
Cameron Steffen
939136d1bc Remove Option from path_to_res return type 2021-01-31 15:59:34 -06: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
Mara Bos
3a0ae08ae2 Update clippy test output for panic macros. 2021-01-30 19:33:21 +01:00
flip1995
ac912be984 Merge commit '95c0459217d1661edfa794c8bb122452b92fb485' into clippyup 2021-01-30 18:06:34 +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
xFrednet
52fabbf08b Added the rustbot claim command to the contribution guide. 2021-01-26 18:36:43 +01: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
xFrednet
69f2b8f0f8 Updated some NITs in the documentation from #6630 2021-01-25 19:46:19 +01: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