]> git.lizzy.rs Git - rust.git/log
rust.git
3 years agoAuto merge of #6709 - rust-lang:flip1995-patch-1, r=matthiaskrgr
bors [Tue, 9 Feb 2021 16:50:35 +0000 (16:50 +0000)]
Auto merge of #6709 - rust-lang:flip1995-patch-1, r=matthiaskrgr

Remove rustfmt from rust-toolchain file

We use latest nightly rustfmt in our tests anyway

r? `@matthiaskrgr`

changelog: none

3 years agoRemove rustfmt from rust-toolchain file
Philipp Krones [Tue, 9 Feb 2021 16:44:36 +0000 (17:44 +0100)]
Remove rustfmt from rust-toolchain file

We use latest nightly rustfmt in our tests anyway

3 years agoAuto merge of #6704 - rust-lang:flip1995-patch-1, r=phansch
bors [Tue, 9 Feb 2021 15:47:30 +0000 (15:47 +0000)]
Auto merge of #6704 - rust-lang:flip1995-patch-1, r=phansch

Rename "good first issue" back to "good-first-issue"

changelog: none

3 years agoRename "good first issue" back to "good-first-issue"
Philipp Krones [Tue, 9 Feb 2021 09:29:00 +0000 (10:29 +0100)]
Rename "good first issue" back to "good-first-issue"

3 years agoAuto merge of #6696 - dtolnay-contrib:regex, r=Manishearth
bors [Mon, 8 Feb 2021 06:02:29 +0000 (06:02 +0000)]
Auto merge of #6696 - dtolnay-contrib:regex, r=Manishearth

Downgrade trivial_regex to nursery

See #6690. I think there is still value in a trivial_regex lint, but only if clippy can tell that the regex is only ever constructed and applied to a single input.

```rust
let regex = Regex::new("trivial_regex")?;
println!("{}", regex.is_match(s));
// `regex` never used again
```

---

changelog: remove `trivial_regex` from default set of enabled lints

3 years agoDowngrade trivial_regex to nursery
David Tolnay [Mon, 8 Feb 2021 00:54:09 +0000 (16:54 -0800)]
Downgrade trivial_regex to nursery

3 years agoAuto merge of #6694 - matthiaskrgr:lintcheck-cfg, r=Manishearth
bors [Sun, 7 Feb 2021 19:04:00 +0000 (19:04 +0000)]
Auto merge of #6694 - matthiaskrgr:lintcheck-cfg, r=Manishearth

lintcheck: add a cmdline option --crates-toml <TOML PATH> to override crate sources file to use.

Fixes #6691

changelog: lintcheck: add --crates-toml  cmdline option to override default crates.toml file.

3 years agolintcheck: add a cmdline option --crates-toml <TOML PATH> to override crate sources...
Matthias Krüger [Sun, 7 Feb 2021 15:12:21 +0000 (16:12 +0100)]
lintcheck: add a cmdline option --crates-toml <TOML PATH> to override crate sources file to use.

Fixes #6691

3 years agoAuto merge of #6686 - matthiaskrgr:lintcheck_git, r=flip1995
bors [Sun, 7 Feb 2021 13:25:00 +0000 (13:25 +0000)]
Auto merge of #6686 - matthiaskrgr:lintcheck_git, r=flip1995

lintcheck: support git sources

This adds support for git sources in `cargo dev-lintcheck`

You can add a git source to `clippy_dev/lintcheck_crates.toml` by having a `git_url` and a `git_hash` key instead of the `versions` array.
The repo will the be cloned and checked out to the requested commit before checking it with clippy.

Fixes https://github.com/rust-lang/rust-clippy/issues/6642

changelog: lintcheck: support git sources

3 years agoAuto merge of #6674 - phlip9:disallowed_functions, r=llogiq
bors [Sun, 7 Feb 2021 11:15:44 +0000 (11:15 +0000)]
Auto merge of #6674 - phlip9:disallowed_functions, r=llogiq

disallowed_methods: Support functions in addition to methods

## Context:

Hey all! I have a particular use case where I'd like to ban certain functions in a code base I work on. For example, I want to ban `Instant::now()` (among others) as we have a time service for mocking time in deterministic simulation tests. Obviously, it doesn't make sense to include a lint like this for all clippy users. Imagine my excitement when I spotted the new `disallowed_methods` lint in clippy--perfect! Unfortunately, after playing around with it for a bit, I was frustrated to realize that it didn't support functions like `Instant::now()`, so I've added support for them in this PR.

It might also make sense to rename the lint from `disallowed_methods` -> `disallowed_functions`, though I've held off from including that rename in this change, since I'm unsure of clippy's breaking change policy.

## Change

Support functions in addition to methods. In other words, support:

`disallowed_methods = ["alloc::vec::Vec::new"]` (a function) in addition to
`disallowed_methods = ["alloc::vec::Vec::leak"]` (a method).

Improve the documentation to clarify that users must specify the full qualified path for each disallowed function, which can be confusing for reexports. Include an example `clippy.toml`.

Simplify the actual lint pass so we can reuse `utils::fn_def_id`.

changelog: disallowed_method: Now supports functions in addition to methods

3 years agoAuto merge of #6685 - magurotuna:filter_map_identity, r=phansch
bors [Sun, 7 Feb 2021 09:55:32 +0000 (09:55 +0000)]
Auto merge of #6685 - magurotuna:filter_map_identity, r=phansch

Add new lint `filter_map_identity`

<!--
Thank you for making Clippy better!

We're collecting our changelog from pull request descriptions.
If your PR only includes internal changes, you can just write
`changelog: none`. Otherwise, please write a short comment
explaining your change.

If your PR fixes an issue, you can add "fixes #issue_number" into this
PR description. This way the issue will be automatically closed when
your PR is merged.

If you added a new lint, here's a checklist for things that will be
checked during review or continuous integration.

- \[x] Followed [lint naming conventions][lint_naming]
- \[x] Added passing UI tests (including committed `.stderr` file)
- \[x] `cargo test` passes locally
- \[x] Executed `cargo dev update_lints`
- \[x] Added lint documentation
- \[x] Run `cargo dev fmt`

[lint_naming]: https://rust-lang.github.io/rfcs/0344-conventions-galore.html#lints

Note that you can skip the above if you are just opening a WIP PR in
order to get feedback.

Delete this line and everything above before opening your PR.
-->

This commit adds a new lint named filter_map_identity.
This lint is the same as `flat_map_identity` except that it checks for the usage of `filter_map`.

---

Closes #6643

changelog: Added a new lint: `filter_map_identity`

3 years agoAuto merge of #6681 - 1c3t3a:1c3t3a-issue-6467, r=xFrednet,flip1995,phansch
bors [Sun, 7 Feb 2021 08:53:52 +0000 (08:53 +0000)]
Auto merge of #6681 - 1c3t3a:1c3t3a-issue-6467, r=xFrednet,flip1995,phansch

Adds a new lint that checks if there is a semicolon on the last block statement if it returns nothing

changelog: Added a new lint: `SEMICOLON_IF_NOTHING_RETURNED`
fixes #6467
Adds the `SEMICOLON_IF_NOTHING_RETURNED` lint and therefore closes #6467.

3 years agoAuto merge of #6660 - camsteffen:path-to-local, r=llogiq
bors [Sun, 7 Feb 2021 08:40:41 +0000 (08:40 +0000)]
Auto merge of #6660 - camsteffen:path-to-local, r=llogiq

Cleanup path-to-local checks

changelog: none

It seemed like too much ceremony going on to check if an expression matches a variable. So I created two util functions `path_to_local(Expr) -> Option<HirId>` and `path_to_local_id(Expr, HirId) -> bool` to make this easier, and used them wherever applicable.

I changed logic in a few places to use `HirId` instead of `Symbol` where it was easy to do so. I believe this is more correct and may even fix some bugs.

I also removed some calls to `qpath_res`. This is not needed if you are only looking for a `Res::Local`.

As a note, I wanted to name the util functions in a way that encourages understanding of the HIR.

3 years agoAuto merge of #6688 - rust-lang:triagebot_update, r=phansch
bors [Sun, 7 Feb 2021 08:24:50 +0000 (08:24 +0000)]
Auto merge of #6688 - rust-lang:triagebot_update, r=phansch

Update triagebot.toml to new label names

changelog: none

3 years agoAuto merge of #6682 - camsteffen:let-underscore-ref, r=llogiq
bors [Sun, 7 Feb 2021 08:13:42 +0000 (08:13 +0000)]
Auto merge of #6682 - camsteffen:let-underscore-ref, r=llogiq

Fix let_underscore_drop FP

changelog: Fix let_underscore_drop false positives and negatives

Fixes #6633

3 years agoUpdate triagebot.toml to new label names
Philipp Krones [Sat, 6 Feb 2021 22:56:08 +0000 (23:56 +0100)]
Update triagebot.toml to new label names

3 years agoEat dogfood
Cameron Steffen [Fri, 5 Feb 2021 20:55:09 +0000 (14:55 -0600)]
Eat dogfood

3 years agoFixed suggestion in macro invocations
Bastian Kersting [Sat, 6 Feb 2021 19:05:51 +0000 (20:05 +0100)]
Fixed suggestion in macro invocations

3 years agolintcheck: avoid dbg!() calls
Matthias Krüger [Sat, 6 Feb 2021 18:12:28 +0000 (19:12 +0100)]
lintcheck: avoid dbg!() calls

3 years agoChanged lint level to `restriction`
Bastian Kersting [Sat, 6 Feb 2021 16:06:06 +0000 (17:06 +0100)]
Changed lint level to `restriction`

3 years agoSwitched to `snippet_with_macro_callsite`
Bastian Kersting [Sat, 6 Feb 2021 15:56:18 +0000 (16:56 +0100)]
Switched to `snippet_with_macro_callsite`

3 years agoRevert "Fixed for loop problem, corrected all occurences that got linted"
Bastian Kersting [Sat, 6 Feb 2021 15:44:57 +0000 (16:44 +0100)]
Revert "Fixed for loop problem, corrected all occurences that got linted"

This reverts commit 6626295fbc747d04f1a8d14f19ee48c789b90e50.

3 years agoAuto merge of #6684 - matthiaskrgr:versiontest_dont_break_upstream, r=flip1995
bors [Sat, 6 Feb 2021 13:38:36 +0000 (13:38 +0000)]
Auto merge of #6684 - matthiaskrgr:versiontest_dont_break_upstream, r=flip1995

tests: ignore check_that_clippy_has_the_same_major_version_as_rustc()inside the rustc repo

Do not check if clippy version matches rustc version when runnning tests inside the rustc repo.
This makes sure that upstream rustc maintainers do not have to deal with our test failing/mismatching versions
when the rustc version bump is happening.
cc #6683

We already do the "don't run inside the rustc-repo" workaround for the dogfood test:
https://github.com/rust-lang/rust-clippy/blob/a507c27660d05f37307369d30bee9e82ce3a11e1/tests/dogfood.rs#L16

changelog: None

3 years agoFixed for loop problem, corrected all occurences that got linted
Bastian Kersting [Sat, 6 Feb 2021 13:07:49 +0000 (14:07 +0100)]
Fixed for loop problem, corrected all occurences that got linted

3 years agolintcheck: cleanup, fix --only for git crates, better error msgs
Matthias Krüger [Sat, 6 Feb 2021 11:04:31 +0000 (12:04 +0100)]
lintcheck: cleanup, fix --only for git crates, better error msgs

3 years agolintcheck: add git source as an example and update logs
Matthias Krüger [Sat, 6 Feb 2021 10:36:06 +0000 (11:36 +0100)]
lintcheck: add git source as an example and update logs

3 years agoimplement the download_and_extract() step for git sources
Matthias Krüger [Sat, 6 Feb 2021 11:02:42 +0000 (12:02 +0100)]
implement the download_and_extract() step for git sources

3 years agolintcheck: make TomlCrate also accept git-data from lintcheck_crates.toml
Matthias Krüger [Fri, 5 Feb 2021 22:13:59 +0000 (23:13 +0100)]
lintcheck: make TomlCrate also accept git-data from lintcheck_crates.toml

3 years agolintcheck: update logs
Matthias Krüger [Sat, 6 Feb 2021 10:59:34 +0000 (11:59 +0100)]
lintcheck: update logs

3 years agoUse flatten instead of filter_map
Yusuke Tanaka [Sat, 6 Feb 2021 09:06:58 +0000 (18:06 +0900)]
Use flatten instead of filter_map

3 years agoAdd new lint `filter_map_identity`
Yusuke Tanaka [Wed, 3 Feb 2021 14:24:06 +0000 (23:24 +0900)]
Add new lint `filter_map_identity`

This commit adds a new lint named `filter_map_identity`. This lint is
the same as `flat_map_identity` except that it checks for `filter_map`.

Closes #6643

3 years agotests: ignore check_that_clippy_has_the_same_major_version_as_rustc() inside the...
Matthias Krüger [Fri, 5 Feb 2021 23:56:54 +0000 (00:56 +0100)]
tests: ignore check_that_clippy_has_the_same_major_version_as_rustc() inside the rustc repo.

Do not check if clippy version matches rustc version when runnning tests inside the rustc repo.
This makes sure that upstream rustc maintainers do not have to deal with our test failing/mismatching versions
when the rustc version bump is happening.
cc #6683

3 years agoFix let_underscore_drop implements Drop logic
Cameron Steffen [Fri, 5 Feb 2021 20:45:24 +0000 (14:45 -0600)]
Fix let_underscore_drop implements Drop logic

This fixes false positives and false negatives.

3 years agoFixed macro edge case for `semicolon_if_nothing_returned lint`
Bastian Kersting [Fri, 5 Feb 2021 17:54:13 +0000 (18:54 +0100)]
Fixed macro edge case for `semicolon_if_nothing_returned lint`

3 years agoAdded documentation
Bastian Kersting [Mon, 21 Dec 2020 17:24:08 +0000 (18:24 +0100)]
Added documentation

3 years agoFirst version of the lint
Bastian Kersting [Sun, 20 Dec 2020 10:48:56 +0000 (11:48 +0100)]
First version of the lint

3 years agoAuto merge of #6679 - flip1995:ra_setup_abs_path, r=Manishearth
bors [Fri, 5 Feb 2021 17:48:46 +0000 (17:48 +0000)]
Auto merge of #6679 - flip1995:ra_setup_abs_path, r=Manishearth

Use absolute path to Rust repo in ra_setup

This will convert the path to the Rust repo to an absolute path. This is
important for the clippy_lints/Cargo.toml file. Otherwise if a relative
path is passed, rst-analyzer won't find the Rust repo, because it starts
the relative path search from the clippy_lints dir, not the
rust-clippy dir where the ra_setup command was run from.

changelog: none

3 years agoAuto merge of #6678 - TaKO8Ki:fix-typo, r=flip1995
bors [Fri, 5 Feb 2021 17:16:50 +0000 (17:16 +0000)]
Auto merge of #6678 - TaKO8Ki:fix-typo, r=flip1995

Fix typo

This patch fixes a typo.

changelog: none

3 years agoCleanup path to local checks
Cameron Steffen [Tue, 2 Feb 2021 01:22:31 +0000 (19:22 -0600)]
Cleanup path to local checks

3 years agoUse absolute path to Rust repo in ra_setup
flip1995 [Fri, 5 Feb 2021 16:23:04 +0000 (17:23 +0100)]
Use absolute path to Rust repo in ra_setup

This will convert the path to the Rust repo to an absolute path. This is
important for the clippy_lints/Cargo.toml file. Otherwise if a relative
path is passed, rst-analyzer won't find the Rust repo, because it starts
the relative path search from the clippy_lints dir, not the
rust-clippy dir where the ra_setup command was run from.

3 years agofix typo
Takayuki Maeda [Fri, 5 Feb 2021 15:10:52 +0000 (00:10 +0900)]
fix typo

3 years agoSupport free functions in disallowed-methods lint
Philip Hayes [Sat, 30 Jan 2021 06:18:56 +0000 (22:18 -0800)]
Support free functions in disallowed-methods lint

In other words, support:

`disallowed_methods = ["alloc::vec::Vec::new"]` (a free function) in
addition to
`disallowed_methods = ["alloc::vec::Vec::leak"]` (a method).

Improve the documentation to clarify that users must specify the full
qualified path for each disallowed function, which can be confusing for
reexports. Include an example `clippy.toml`.

Simplify the actual lint pass so we can reuse `utils::fn_def_id`.

3 years agoAuto merge of #6646 - nahuakang:for_loops_over_options_or_results, r=flip1995
bors [Thu, 4 Feb 2021 10:03:45 +0000 (10:03 +0000)]
Auto merge of #6646 - nahuakang:for_loops_over_options_or_results, r=flip1995

New Lint: Manual Flatten

This is a draft PR for [Issue 6564](https://github.com/rust-lang/rust-clippy/issues/6564).

r? `@camsteffen`

- \[x] Followed [lint naming conventions][lint_naming]
- \[x] Added passing UI tests (including committed `.stderr` file)
- \[x] `cargo test` passes locally
- \[x] Executed `cargo dev update_lints`
- \[x] Added lint documentation
- \[x] Run `cargo dev fmt`

---

*Please write a short comment explaining your change (or "none" for internal only changes)*
changelog: Add new lint [`manual_flatten`] to check for loops over a single `if let` expression with `Result` or `Option`.

3 years agoImprove lint message; add note for future autofixable updates
nahuakang [Thu, 4 Feb 2021 09:51:40 +0000 (10:51 +0100)]
Improve lint message; add note for future autofixable updates

3 years agoAdd additional test cases and improve span lint
nahuakang [Wed, 3 Feb 2021 18:45:58 +0000 (19:45 +0100)]
Add additional test cases and improve span lint

3 years agoAuto merge of #6669 - magurotuna:fix-test-name, r=flip1995
bors [Wed, 3 Feb 2021 15:39:37 +0000 (15:39 +0000)]
Auto merge of #6669 - magurotuna:fix-test-name, r=flip1995

Fix file names of flat_map_identity test

This patch fixes the file names of the `flat_map_identity` test.
Previously, their names were started with `unnecessary_flat_map` even though the lint rule name is `flat_map_identity`. This inconsistency happened probably because the rule name was changed during the discussion in the PR where this rule was introduced.

ref: https://github.com/rust-lang/rust-clippy/pull/4231

changelog: none

3 years agoFix file names of flat_map_identity test
Yusuke Tanaka [Wed, 3 Feb 2021 15:06:26 +0000 (00:06 +0900)]
Fix file names of flat_map_identity test

This commit fixes the file names of the `flat_map_identity` test.
Previously, their names were started with `unnecessary_flat_map` even
though the lint rule name is `flat_map_identity`. This inconsistency
happened probably because the rule name was changed during the
discussion in the PR where this rule was introduced.

ref: https://github.com/rust-lang/rust-clippy/pull/4231

3 years agoAdd additional check on if arg type has iter method
nahuakang [Wed, 3 Feb 2021 08:39:35 +0000 (09:39 +0100)]
Add additional check on if arg type has iter method

3 years agoAuto merge of #6667 - Manishearth:rustup, r=Manishearth
bors [Wed, 3 Feb 2021 04:09:03 +0000 (04:09 +0000)]
Auto merge of #6667 - Manishearth:rustup, r=Manishearth

Rustup

Pulling in AST changes

changelog: none

3 years agoMerge branch 'sync-from-rust3' into rustup
Manish Goregaokar [Wed, 3 Feb 2021 03:57:31 +0000 (19:57 -0800)]
Merge branch 'sync-from-rust3' into rustup

3 years agoRun rustfmt
Manish Goregaokar [Wed, 3 Feb 2021 03:57:08 +0000 (19:57 -0800)]
Run rustfmt

3 years agoRustup
Manish Goregaokar [Wed, 3 Feb 2021 01:35:39 +0000 (17:35 -0800)]
Rustup

3 years agoMerge remote-tracking branch 'origin/master' into rustup
Manish Goregaokar [Wed, 3 Feb 2021 00:46:12 +0000 (16:46 -0800)]
Merge remote-tracking branch 'origin/master' into rustup

3 years agoEnhance manual flatten
nahuakang [Tue, 2 Feb 2021 18:04:20 +0000 (19:04 +0100)]
Enhance manual flatten

3 years agoRollup merge of #81260 - vn971:restore-editorconfig, r=Mark-Simulacrum
Jack Huey [Tue, 2 Feb 2021 21:01:33 +0000 (16:01 -0500)]
Rollup merge of #81260 - vn971:restore-editorconfig, r=Mark-Simulacrum

Add .editorconfig

This adds a .editorconfig file to rust-lang/rust, matching Clippy's. It's not clear that this will benefit many people, but the cost is low and the rewards are potentially meaningful.

3 years agoAuto merge of #6639 - xFrednet:0000-configuration-documentation-some-nits, r=flip1995
bors [Tue, 2 Feb 2021 18:05:35 +0000 (18:05 +0000)]
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`

3 years agoUpdated the list of active mentors
xFrednet [Tue, 2 Feb 2021 17:53:15 +0000 (18:53 +0100)]
Updated the list of active mentors

3 years agoAuto merge of #81405 - bugadani:ast, r=cjgillot
bors [Tue, 2 Feb 2021 17:34:08 +0000 (17:34 +0000)]
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)

3 years agoAdd .editorconfig
Vasili Novikov [Fri, 22 Jan 2021 08:51:23 +0000 (09:51 +0100)]
Add .editorconfig

Editorconfig is a lightweight specification that
helps maintaining consistent coding/formatting style
accross editors, especially those editors
that are not explicitly aware of Rust and rustfmt.

https://editorconfig.org/

3 years agoAuto merge of #6664 - camsteffen:path-to-res, r=Manishearth
bors [Tue, 2 Feb 2021 16:56:39 +0000 (16:56 +0000)]
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>`.

3 years agoAuto merge of #6523 - brightly-salty:missing-panic-doc, r=flip1995
bors [Tue, 2 Feb 2021 15:37:24 +0000 (15:37 +0000)]
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

3 years agoAdd missing_panics_doc lint
Caden Haustein [Wed, 30 Dec 2020 22:37:59 +0000 (16:37 -0600)]
Add missing_panics_doc lint

3 years agoAuto merge of #6659 - phlip9:let_and_return_fix, r=phansch
bors [Tue, 2 Feb 2021 15:04:35 +0000 (15:04 +0000)]
Auto merge of #6659 - phlip9:let_and_return_fix, r=phansch

Fix let_and_return false positive

The issue:

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

3 years agoAuto merge of #6661 - Manishearth:exhaustive-fix, r=flip1995
bors [Tue, 2 Feb 2021 07:59:39 +0000 (07:59 +0000)]
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

3 years agoFix test formatting
Philipp Krones [Tue, 2 Feb 2021 07:59:23 +0000 (08:59 +0100)]
Fix test formatting

3 years agoexhaustive_structs: don't trigger for structs with private fields
Manish Goregaokar [Tue, 2 Feb 2021 02:38:43 +0000 (18:38 -0800)]
exhaustive_structs: don't trigger for structs with private fields

3 years agoImplement manual flatten lint
nahuakang [Fri, 29 Jan 2021 00:38:34 +0000 (01:38 +0100)]
Implement manual flatten lint

3 years agoRun cargo dev update_lints
nahuakang [Wed, 27 Jan 2021 08:56:56 +0000 (09:56 +0100)]
Run cargo dev update_lints

3 years agoRename lint
nahuakang [Wed, 27 Jan 2021 08:49:53 +0000 (09:49 +0100)]
Rename lint

3 years agoDraft skeleton for new lint
nahuakang [Wed, 27 Jan 2021 08:34:59 +0000 (09:34 +0100)]
Draft skeleton for new lint

3 years agoAdd unit tests for new lint
nahuakang [Wed, 27 Jan 2021 08:34:36 +0000 (09:34 +0100)]
Add unit tests for new lint

3 years agoAuto merge of #80851 - m-ou-se:panic-2021, r=petrochenkov
bors [Mon, 1 Feb 2021 10:25:31 +0000 (10:25 +0000)]
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: https://github.com/rust-lang/rust/pull/80879/commits/c5273bdfb266c35e8eab9413aa8d58d27fdbe114 That change is blocked on figuring out what to do with https://github.com/rust-lang/rust/issues/80846 first.

3 years agoBox the biggest ast::ItemKind variants
Dániel Buga [Fri, 29 Jan 2021 07:31:08 +0000 (08:31 +0100)]
Box the biggest ast::ItemKind variants

3 years agoRemove Option from path_to_res return type
Cameron Steffen [Mon, 25 Jan 2021 19:39:35 +0000 (13:39 -0600)]
Remove Option from path_to_res return type

3 years agoAuto merge of #6603 - ThibsG:MatchOverlappingArm5986, r=flip1995
bors [Sun, 31 Jan 2021 15:09:55 +0000 (15:09 +0000)]
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

3 years agoAuto merge of #6656 - phansch:command-failed-print-stderr, r=flip1995
bors [Sun, 31 Jan 2021 14:56:53 +0000 (14:56 +0000)]
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

3 years agoclippy_dev: Pass stderr to CommandFailed
Philipp Hansch [Sun, 31 Jan 2021 10:17:37 +0000 (11:17 +0100)]
clippy_dev: Pass stderr to CommandFailed

3 years agoUpdate clippy test output for panic macros.
Mara Bos [Sat, 30 Jan 2021 18:33:21 +0000 (19:33 +0100)]
Update clippy test output for panic macros.

3 years agoMerge commit '95c0459217d1661edfa794c8bb122452b92fb485' into clippyup
flip1995 [Sat, 30 Jan 2021 17:06:34 +0000 (18:06 +0100)]
Merge commit '95c0459217d1661edfa794c8bb122452b92fb485' into clippyup

3 years agoAuto merge of #6654 - flip1995:no_lazy_static_regex, r=flip1995
bors [Sat, 30 Jan 2021 16:49:45 +0000 (16:49 +0000)]
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

3 years agoRemove unknown_clippy_lints allow attribute
flip1995 [Sat, 30 Jan 2021 16:43:20 +0000 (17:43 +0100)]
Remove unknown_clippy_lints allow attribute

3 years agoGet rid of regex and lazy_static dependencies
flip1995 [Sat, 30 Jan 2021 16:43:00 +0000 (17:43 +0100)]
Get rid of regex and lazy_static dependencies

3 years agoAuto merge of #6653 - flip1995:rustup, r=flip1995
bors [Sat, 30 Jan 2021 14:53:30 +0000 (14:53 +0000)]
Auto merge of #6653 - flip1995:rustup, r=flip1995

Rustup

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

r? `@ghost`

3 years agoBump nightly version -> 2021-01-30
flip1995 [Sat, 30 Jan 2021 14:52:02 +0000 (15:52 +0100)]
Bump nightly version -> 2021-01-30

3 years agoMerge remote-tracking branch 'upstream/master' into rustup
flip1995 [Sat, 30 Jan 2021 14:51:16 +0000 (15:51 +0100)]
Merge remote-tracking branch 'upstream/master' into rustup

3 years agoFix let_and_return false positive
Philip Hayes [Sat, 30 Jan 2021 06:17:18 +0000 (22:17 -0800)]
Fix let_and_return false positive

The issue:

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.

3 years agoRollup merge of #81176 - camsteffen:qpath-res, r=oli-obk
Yuki Okushi [Fri, 29 Jan 2021 00:17:32 +0000 (09:17 +0900)]
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](https://github.com/rust-lang/rust/blob/5e91c4ecc09312d8b63d250a432b0f3ef83f1df7/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

3 years agoRollup merge of #81277 - flip1995:from_diag_items, r=matthewjasper
Yuki Okushi [Thu, 28 Jan 2021 06:09:08 +0000 (15:09 +0900)]
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

3 years agoRollup merge of #79951 - LeSeulArtichaut:ty-ir, r=nikomatsakis
Yuki Okushi [Thu, 28 Jan 2021 06:09:02 +0000 (15:09 +0900)]
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`````

3 years agoAuto merge of #6645 - camsteffen:syntax-highlighting, r=phansch
bors [Wed, 27 Jan 2021 06:47:07 +0000 (06:47 +0000)]
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`

3 years agoFix some website syntax highlighting
Cameron Steffen [Tue, 26 Jan 2021 23:38:37 +0000 (17:38 -0600)]
Fix some website syntax highlighting

3 years agoAdded the rustbot claim command to the contribution guide.
xFrednet [Tue, 26 Jan 2021 17:36:43 +0000 (18:36 +0100)]
Added the rustbot claim command to the contribution guide.

3 years agoAuto merge of #6469 - matthiaskrgr:clippy_dev_crater, r=flip1995
bors [Tue, 26 Jan 2021 06:58:04 +0000 (06:58 +0000)]
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

3 years agoAuto merge of #6617 - Manishearth:exhaustive_enums, r=camsteffen
bors [Mon, 25 Jan 2021 23:06:39 +0000 (23:06 +0000)]
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`

3 years agoAdd test with attrs
Manish Goregaokar [Mon, 25 Jan 2021 22:39:03 +0000 (14:39 -0800)]
Add test with attrs

3 years agoBetter suggestion span
Manish Goregaokar [Mon, 25 Jan 2021 22:35:57 +0000 (14:35 -0800)]
Better suggestion span

3 years agoUpdated some NITs in the documentation from #6630
xFrednet [Mon, 25 Jan 2021 18:46:19 +0000 (19:46 +0100)]
Updated some NITs in the documentation from #6630

3 years agoAuto merge of #6630 - xFrednet:0000-configuration-documentation, r=llogiq
bors [Mon, 25 Jan 2021 00:25:31 +0000 (00:25 +0000)]
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. :upside_down_face:

 ---

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 :upside_down_face:

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

changelog: none

3 years agoAdded documentation for adding a configuration to lints
xFrednet [Fri, 22 Jan 2021 18:04:28 +0000 (19:04 +0100)]
Added documentation for adding a configuration to lints

* Fixed some spelling

3 years agoAdd more tests for `match_overlapping_arm` lint
ThibsG [Sun, 24 Jan 2021 11:28:59 +0000 (12:28 +0100)]
Add more tests for `match_overlapping_arm` lint