Commit Graph

10619 Commits

Author SHA1 Message Date
Cameron Steffen
1021327781 Simplify if_chain 2021-02-08 10:51:40 -06:00
bors
4bbd7e46ee 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
2021-02-08 06:02:29 +00:00
David Tolnay
fd35517bd4
Downgrade trivial_regex to nursery 2021-02-07 16:54:09 -08:00
bors
de35c297bf 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.
2021-02-07 19:04:00 +00:00
Matthias Krüger
6f3eeac83c lintcheck: add a cmdline option --crates-toml <TOML PATH> to override crate sources file to use.
Fixes #6691
2021-02-07 16:14:43 +01:00
bors
c1ce78f0b2 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
2021-02-07 13:25:00 +00:00
bors
83b7b16330 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
2021-02-07 11:15:44 +00:00
bors
ad9ceeebdc 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`
2021-02-07 09:55:32 +00:00
bors
001185d863 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.
2021-02-07 08:53:52 +00:00
bors
d51db24132 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.
2021-02-07 08:40:41 +00:00
bors
b36d1a4727 Auto merge of #6688 - rust-lang:triagebot_update, r=phansch
Update triagebot.toml to new label names

changelog: none
2021-02-07 08:24:50 +00:00
bors
d792210c26 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
2021-02-07 08:13:42 +00:00
Philipp Krones
dfe08f4e48
Update triagebot.toml to new label names 2021-02-06 23:56:08 +01:00
Cameron Steffen
40ce05654b Eat dogfood 2021-02-06 16:35:38 -06:00
Bastian Kersting
6b4789d7cf Fixed suggestion in macro invocations 2021-02-06 20:05:51 +01:00
Matthias Krüger
2bffbfccc1 lintcheck: avoid dbg!() calls 2021-02-06 19:12:58 +01:00
Bastian Kersting
f1c15840a2 Changed lint level to restriction 2021-02-06 17:06:06 +01:00
Bastian Kersting
85c2b1e5f4 Switched to snippet_with_macro_callsite 2021-02-06 16:56:18 +01:00
Bastian Kersting
cd6748749a Revert "Fixed for loop problem, corrected all occurences that got linted"
This reverts commit 6626295fbc.
2021-02-06 16:44:57 +01:00
bors
dfb34c085f 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:
a507c27660/tests/dogfood.rs (L16)

changelog: None
2021-02-06 13:38:36 +00:00
Bastian Kersting
6626295fbc Fixed for loop problem, corrected all occurences that got linted 2021-02-06 14:25:40 +01:00
Matthias Krüger
e1c284bff7 lintcheck: cleanup, fix --only for git crates, better error msgs 2021-02-06 12:24:13 +01:00
Matthias Krüger
9ab505a3c7 lintcheck: add git source as an example and update logs 2021-02-06 12:11:31 +01:00
Matthias Krüger
10fbafa562 implement the download_and_extract() step for git sources 2021-02-06 12:10:47 +01:00
Matthias Krüger
64982cc435 lintcheck: make TomlCrate also accept git-data from lintcheck_crates.toml 2021-02-06 12:10:45 +01:00
Matthias Krüger
cb3021999c lintcheck: update logs 2021-02-06 11:59:34 +01:00
Yusuke Tanaka
fbe436b1d4
Use flatten instead of filter_map 2021-02-06 18:06:58 +09:00
Yusuke Tanaka
a60c143fe0
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
2021-02-06 18:03:14 +09:00
Matthias Krüger
93daf27a40 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
2021-02-06 00:56:54 +01:00
Cameron Steffen
ac5e9c8d26 Fix let_underscore_drop implements Drop logic
This fixes false positives and false negatives.
2021-02-05 14:54:06 -06:00
Bastian Kersting
55bfaa12d3 Fixed macro edge case for semicolon_if_nothing_returned lint 2021-02-05 20:48:46 +01:00
Bastian Kersting
f907986580 Added documentation 2021-02-05 20:19:22 +01:00
Bastian Kersting
eb9c6698ee First version of the lint 2021-02-05 20:19:22 +01:00
bors
a507c27660 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
2021-02-05 17:48:46 +00:00
bors
89f266a082 Auto merge of #6678 - TaKO8Ki:fix-typo, r=flip1995
Fix typo

This patch fixes a typo.

changelog: none
2021-02-05 17:16:50 +00:00
Cameron Steffen
56f7fbb4ae Cleanup path to local checks 2021-02-05 10:24:32 -06:00
flip1995
79dbf10736
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.
2021-02-05 17:23:04 +01:00
Takayuki Maeda
67d48e1c59 fix typo 2021-02-06 00:10:52 +09:00
Philip Hayes
7b7e3ca511 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`.
2021-02-04 11:28:55 -08:00
bors
357c6a7e27 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`.
2021-02-04 10:03:45 +00:00
nahuakang
2f8a8d3468 Improve lint message; add note for future autofixable updates 2021-02-04 10:51:40 +01:00
nahuakang
78ef0f2f6c Add additional test cases and improve span lint 2021-02-03 21:54:38 +01:00
bors
876ffa4674 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
2021-02-03 15:39:37 +00:00
Yusuke Tanaka
6396b8fb7f
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
2021-02-04 00:06:26 +09:00
nahuakang
0f5e71f8f2 Add additional check on if arg type has iter method 2021-02-03 09:39:35 +01:00
bors
3e4179766b Auto merge of #6667 - Manishearth:rustup, r=Manishearth
Rustup

Pulling in AST changes

changelog: none
2021-02-03 04:09:03 +00:00
Manish Goregaokar
741259bece Merge branch 'sync-from-rust3' into rustup 2021-02-02 19:57:31 -08:00
Manish Goregaokar
a31e5f5f3b Run rustfmt 2021-02-02 19:57:08 -08:00
Manish Goregaokar
6fb10755c0 Rustup 2021-02-02 19:54:21 -08:00
Manish Goregaokar
5c957b8a6f Merge remote-tracking branch 'origin/master' into rustup 2021-02-02 16:46:12 -08:00