]> git.lizzy.rs Git - rust.git/log
rust.git
2 years agoAuto merge of #8504 - xFrednet:8502-allow-lint-without-reason, r=flip1995
bors [Fri, 4 Mar 2022 19:23:39 +0000 (19:23 +0000)]
Auto merge of #8504 - xFrednet:8502-allow-lint-without-reason, r=flip1995

Add lint to detect `allow` attributes without reason

I was considering putting this lint into the pedantic group. However, that would result in countless warnings for existing projects. Having it in restriction also seems good to me :upside_down_face: (And now I need sleep :zzz: )

---

changelog: New lint [`allow_lint_without_reason`] (Requires the `lint_reasons` feature)

Closes: rust-lang/rust-clippy#8502
2 years agoAdd lint to detect `allow` attributes without reason
xFrednet [Thu, 3 Mar 2022 22:57:35 +0000 (23:57 +0100)]
Add lint to detect `allow` attributes without reason

2 years agoAuto merge of #8500 - rust-lang:testless-dbg-macro, r=Manishearth
bors [Thu, 3 Mar 2022 18:32:07 +0000 (18:32 +0000)]
Auto merge of #8500 - rust-lang:testless-dbg-macro, r=Manishearth

Omit dbg_macro in test code

This fixes #8481.

---

changelog: none

2 years agoOmit dbg_macro in test code
Andre Bogus [Thu, 3 Mar 2022 18:28:05 +0000 (19:28 +0100)]
Omit dbg_macro in test code

2 years agoAuto merge of #8414 - MiSawa:fix/optimize-redundant-clone, r=oli-obk
bors [Thu, 3 Mar 2022 14:47:49 +0000 (14:47 +0000)]
Auto merge of #8414 - MiSawa:fix/optimize-redundant-clone, r=oli-obk

Optimize `redundant_clone`

Fixes #8412

changelog: none

2 years agoAuto merge of #8483 - ldm0:iter_with_drain_simple, r=flip1995,giraffate
bors [Thu, 3 Mar 2022 13:36:49 +0000 (13:36 +0000)]
Auto merge of #8483 - ldm0:iter_with_drain_simple, r=flip1995,giraffate

Use `.into_iter()` rather than `.drain(..)`

Replacing `.drain(..)` with `.into_iter()` makes my project's binary size smaller.

Fixes #1908

Applicability of this suggestion is `MaybeIncorrect` rather than `MachineApplicable` due to the complexity of "checking otherwise usage" X-|

changelog: Add new lint [`iter_with_drain`]

2 years agoAuto merge of #8497 - Manishearth:transmute-undefined-repr-note, r=flip1995
bors [Thu, 3 Mar 2022 09:05:21 +0000 (09:05 +0000)]
Auto merge of #8497 - Manishearth:transmute-undefined-repr-note, r=flip1995

comment about transmute_undefined_repr in nursery

See discussion in https://github.com/rust-lang/rust-clippy/pull/8432

changelog: none

2 years agocomment about transmute_undefined_repr in nursery
Manish Goregaokar [Wed, 2 Mar 2022 17:54:50 +0000 (09:54 -0800)]
comment about transmute_undefined_repr in nursery

2 years agoSuggest `into_iter()` over `drain(..)`
Liu Dingming [Sat, 12 Feb 2022 19:14:04 +0000 (03:14 +0800)]
Suggest `into_iter()` over `drain(..)`

Add doc

Add description

iter_with_drain dogfood

Disable emiting on struct field.

Fix clippy

Add eq_path for SpanlessEq

Fix tests

Better error message

Fix doc test

Fix version

Apply suggestions

2 years agoAuto merge of #8489 - smoelius:unnecessary-find-map, r=llogiq
bors [Wed, 2 Mar 2022 19:50:27 +0000 (19:50 +0000)]
Auto merge of #8489 - smoelius:unnecessary-find-map, r=llogiq

Add `unnecessary_find_map` lint

This PR adds an `unnecessary_find_map` lint. It is essentially just a minor enhancement of `unnecessary_filter_map`.

Closes #8467

changelog: New lint `unnecessary_find_map`

2 years agoAuto merge of #8456 - ebobrow:use_self_pat, r=llogiq
bors [Wed, 2 Mar 2022 19:31:22 +0000 (19:31 +0000)]
Auto merge of #8456 - ebobrow:use_self_pat, r=llogiq

check `use_self` in `pat`

fixes #6955

changelog: check `use_self` in `pat`

2 years agoAuto merge of #8174 - rust-lang:missing-spin-loop, r=flip1995
bors [Wed, 2 Mar 2022 19:12:32 +0000 (19:12 +0000)]
Auto merge of #8174 - rust-lang:missing-spin-loop, r=flip1995

new lint: `missing-spin-loop`

This fixes #7809. I went with the shorter name because the function is called `std::hint::spin_loop`. It doesn't yet detect `while let` loops. I left that for a follow-up PR.

---

changelog: new lint: [`missing_spin_loop`]

2 years agonew lint: `missing-spin-loop`
Andre Bogus [Sun, 26 Dec 2021 09:00:29 +0000 (10:00 +0100)]
new lint: `missing-spin-loop`

2 years agoAuto merge of #8432 - dtolnay-contrib:transmuteundefinedrepr2, r=Manishearth
bors [Wed, 2 Mar 2022 17:05:06 +0000 (17:05 +0000)]
Auto merge of #8432 - dtolnay-contrib:transmuteundefinedrepr2, r=Manishearth

Transmute_undefined_repr to nursery again

This PR reinstates #8418, which was reverted in #8425 (incorrectly I think).

I don't want to start a revert war over this but I feel very strongly that this lint is not in a state that would be a net benefit to users of clippy. In its current form, making this an enabled-by-default `correctness` lint with authoritative-sounding proclamations of undefined behavior does more harm than the benefit of the true positive cases.

I can file a bunch more examples of false positives but I don't want to give the author of this lint the impression that it is ready to graduate from `nursery` as soon as I've exhausted the amount of time I am willing to spend revising this lint.

Instead I would recommend that the author of the lint try running it on some reputable codebases containing transmutes. Everywhere that the lint triggers please consider critically whether it should be triggering. For cases that you think are true positives, please raise a few of them with the crate authors (in a PR or issue) to better understand their perspective if they think the transmute is correct.

---

*Please write a short comment explaining your change (or "none" for internal only changes)*

changelog: Re-remove [`transmute_undefined_repr`] from default set of enabled lints

2 years agoAuto merge of #8491 - matthiaskrgr:no_num_cpus, r=flip1995
bors [Wed, 2 Mar 2022 09:26:11 +0000 (09:26 +0000)]
Auto merge of #8491 - matthiaskrgr:no_num_cpus, r=flip1995

tests: use std::thread::available_parallelism() instead of num_cpus to get thread count

removes the dependency added in https://github.com/rust-lang/rust-clippy/pull/8451
---

*Please write a short comment explaining your change (or "none" for internal only changes)*

changelog: tests: use std::thread::available_parallelism() instead of num_cpus to get thread count

2 years agoAdd `unnecessary_find_map` lint
Samuel E. Moelius III [Tue, 1 Mar 2022 00:17:45 +0000 (19:17 -0500)]
Add `unnecessary_find_map` lint

2 years agotests: use std::thread::available_parallelism() instead of num_cpus to get thread...
Matthias Krüger [Tue, 1 Mar 2022 19:56:03 +0000 (20:56 +0100)]
tests: use std::thread::available_parallelism() instead of num_cpus to get thread count

removes the dependency added in https://github.com/rust-lang/rust-clippy/pull/8451

2 years agoAuto merge of #8488 - flip1995:ci-cargo-dev-new-lint, r=llogiq
bors [Tue, 1 Mar 2022 20:05:21 +0000 (20:05 +0000)]
Auto merge of #8488 - flip1995:ci-cargo-dev-new-lint, r=llogiq

Move testing of cargo dev new_lint to cargo dev workflow

This should be placed there. No need to run this in PR CI, if clippy_dev
isn't touched. (It will be run by bors anyway)

changelog: none

2 years agoAuto merge of #8313 - flip1995:msrv-internal-lint, r=xFrednet
bors [Tue, 1 Mar 2022 17:40:52 +0000 (17:40 +0000)]
Auto merge of #8313 - flip1995:msrv-internal-lint, r=xFrednet

Implement internal lint for MSRV lints

This internal lint checks if the `extract_msrv_attrs!` macro is used if
a lint has a MSRV. If not, it suggests to add this attribute to the lint
pass implementation.

Following up https://github.com/rust-lang/rust-clippy/pull/8280#discussion_r785226072. This currently doesn't implement the documentation check. But since this is just an extension of this lint, I think this is a good MVP of this lint.

r? `@camsteffen`

cc `@xFrednet`

changelog: none

2 years agoMove testing of cargo dev new_lint to cargo dev workflow
flip1995 [Tue, 1 Mar 2022 10:10:01 +0000 (10:10 +0000)]
Move testing of cargo dev new_lint to cargo dev workflow

This should be placed there. No need to run this in PR CI, if clippy_dev
isn't touched. (It will be run by bors anyway)

2 years agoImplement internal lint for MSRV lints
flip1995 [Wed, 19 Jan 2022 16:35:52 +0000 (17:35 +0100)]
Implement internal lint for MSRV lints

This internal lint checks if the `extract_msrv_attrs!` macro is used if
a lint has a MSRV. If not, it suggests to add this attribute to the lint
pass implementation.

2 years agoAuto merge of #8479 - smoelius:unnecessary-filter-map, r=llogiq
bors [Mon, 28 Feb 2022 20:09:18 +0000 (20:09 +0000)]
Auto merge of #8479 - smoelius:unnecessary-filter-map, r=llogiq

Fix some `unnecessary_filter_map` false positives

This is a proposed fix for #4433.

It moves `clone_or_copy_needed` out of `unnecessary_iter_cloned.rs` and into `methods::utils`. It then adds a check of this function to `unnecessary_filter_map::check`.

Fixes #4433

changelog: none

2 years agoCheck `clone_or_copy_needed` in `unnecessary_filter_map::check`
Samuel E. Moelius III [Mon, 28 Feb 2022 10:00:36 +0000 (05:00 -0500)]
Check `clone_or_copy_needed` in `unnecessary_filter_map::check`

2 years agoAdd tests to tests/ui/unnecessary_filter_map.rs
Samuel E. Moelius III [Mon, 28 Feb 2022 09:59:33 +0000 (04:59 -0500)]
Add tests to tests/ui/unnecessary_filter_map.rs

The tests currently fail, and are fixed by the next commit.

2 years agoAuto merge of #8476 - xFrednet:0000-update-edition-for-rustfmt, r=giraffate
bors [Sun, 27 Feb 2022 13:01:04 +0000 (13:01 +0000)]
Auto merge of #8476 - xFrednet:0000-update-edition-for-rustfmt, r=giraffate

Update edition in rustfmt.toml

I noticed that our `rustfmt.toml` still has the edition 2018 listed. This updates the configuration to use 2021.

This luckily doesn't introduce any formatting changes :upside_down_face:

changelog: none

2 years agoUpdate edition in rustfmt.toml
xFrednet [Sat, 26 Feb 2022 19:33:47 +0000 (20:33 +0100)]
Update edition in rustfmt.toml

2 years agocheck `use_self` in `pat`
Elliot Bobrow [Mon, 21 Feb 2022 22:38:22 +0000 (14:38 -0800)]
check `use_self` in `pat`

2 years agoAuto merge of #8462 - ken-matsui:use-precise-namespace-for-reverse, r=llogiq
bors [Sat, 26 Feb 2022 14:49:39 +0000 (14:49 +0000)]
Auto merge of #8462 - ken-matsui:use-precise-namespace-for-reverse, r=llogiq

Use the precise namespace for `Reverse`

Closes: https://github.com/rust-lang/rust-clippy/issues/8461
changelog: [`unnecessary_sort_by`](https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_sort_by): Use the precise namespace for `Reverse`

2 years agoAuto merge of #8464 - Jarcho:ptr_arg_8463, r=camsteffen
bors [Sat, 26 Feb 2022 03:00:53 +0000 (03:00 +0000)]
Auto merge of #8464 - Jarcho:ptr_arg_8463, r=camsteffen

Fix `ptr_arg`

fixes: #8463

changelog: Fix `ptr_arg` when multiple arguments are being checked in one function

2 years agoAuto merge of #8453 - tamaroning:fix_large_enum_variant, r=camsteffen
bors [Sat, 26 Feb 2022 02:42:43 +0000 (02:42 +0000)]
Auto merge of #8453 - tamaroning:fix_large_enum_variant, r=camsteffen

fix false positives of large_enum_variant

fixes: #8321
The size of enums containing generic type was calculated to be 0.
I changed [large_enum_variant] so that such enums are not linted.

changelog: none

2 years agoAuto merge of #8253 - Alexendoo:print-in-fmt, r=camsteffen
bors [Fri, 25 Feb 2022 21:12:14 +0000 (21:12 +0000)]
Auto merge of #8253 - Alexendoo:print-in-fmt, r=camsteffen

Add `print_in_format_impl` lint

changelog: new lint: [`print_in_format_impl`]

Lints the use of `print`-like macros in manual `Display`/`Debug` impls. I feel like I make this mistake every time I write one 😄

r? `@camsteffen`

2 years agoAdd `print_in_format_impl` lint
Alex Macleod [Thu, 17 Feb 2022 15:33:07 +0000 (15:33 +0000)]
Add `print_in_format_impl` lint

2 years agoRename RecursiveFormatImpl to FormatImpl
Alex Macleod [Thu, 17 Feb 2022 11:20:47 +0000 (11:20 +0000)]
Rename RecursiveFormatImpl to FormatImpl

2 years agoAuto merge of #8474 - Alexendoo:paths, r=Manishearth
bors [Fri, 25 Feb 2022 16:07:59 +0000 (16:07 +0000)]
Auto merge of #8474 - Alexendoo:paths, r=Manishearth

Replace some more paths with diagnostic items

cc #5393

Replaces the macro & mem paths, and catches a couple others that were unused

changelog: none

2 years agoAuto merge of #8472 - Mastermindaxe:#8152_new-without-default_should_not_trigger_on_d...
bors [Fri, 25 Feb 2022 15:51:37 +0000 (15:51 +0000)]
Auto merge of #8472 - Mastermindaxe:#8152_new-without-default_should_not_trigger_on_doc_hidden_items, r=flip1995

Disable ``[`new-without-default`]`` for new() methods that are marked…

… with '#[doc(hidden)]'

Fixes #8152

changelog: Disable ``[`new-without-default`]`` for new() methods that are marked with `#[doc(hidden)]`

2 years agoReplace some more paths with diagnostic items
Alex Macleod [Fri, 25 Feb 2022 15:38:06 +0000 (15:38 +0000)]
Replace some more paths with diagnostic items

2 years agoDisable ``[`new-without-default`]`` for new() methods that are marked with '#[doc...
Florian Nagel [Fri, 25 Feb 2022 13:36:23 +0000 (14:36 +0100)]
Disable ``[`new-without-default`]`` for new() methods that are marked with '#[doc(hidden)]'

Fixes issue #8152

2 years agoAuto merge of #8468 - flip1995:rustup, r=flip1995
bors [Thu, 24 Feb 2022 18:37:57 +0000 (18:37 +0000)]
Auto merge of #8468 - flip1995:rustup, r=flip1995

Rustup

r? `@ghost`

changelog: none

2 years agoBump nightly version -> 2022-02-24
flip1995 [Thu, 24 Feb 2022 18:33:10 +0000 (19:33 +0100)]
Bump nightly version -> 2022-02-24

2 years agoBump Clippy Version -> 0.1.61
flip1995 [Thu, 24 Feb 2022 18:32:47 +0000 (19:32 +0100)]
Bump Clippy Version -> 0.1.61

2 years agoMerge remote-tracking branch 'upstream/master' into rustup
flip1995 [Thu, 24 Feb 2022 18:32:17 +0000 (19:32 +0100)]
Merge remote-tracking branch 'upstream/master' into rustup

2 years agoAuto merge of #8466 - tamaroning:fix_reduntant_closure, r=Manishearth
bors [Wed, 23 Feb 2022 18:26:30 +0000 (18:26 +0000)]
Auto merge of #8466 - tamaroning:fix_reduntant_closure, r=Manishearth

False positive redundant_closure when using ref pattern in closure params

fixes #8460
Fixed [redundant_closure] so that closures of which params bound as `ref` or `ref mut ` doesn't trigger the lint.
(e.g. `|ref x| some_expr` doesn't trigger the lint.)
changelog: none

2 years agofix typo
tamaron [Wed, 23 Feb 2022 15:25:07 +0000 (00:25 +0900)]
fix typo

2 years agofix
tamaron [Wed, 23 Feb 2022 15:16:24 +0000 (00:16 +0900)]
fix

2 years agoFix counting the number of unchangeable arguments in `ptr_arg`
Jason Newcomb [Wed, 23 Feb 2022 06:04:49 +0000 (01:04 -0500)]
Fix counting the number of unchangeable arguments in `ptr_arg`

2 years agoDon't assume DAG
mi_sawa [Wed, 23 Feb 2022 04:38:48 +0000 (13:38 +0900)]
Don't assume DAG

2 years agoAuto merge of #8451 - matthiaskrgr:ui_speedup, r=llogiq
bors [Tue, 22 Feb 2022 21:58:24 +0000 (21:58 +0000)]
Auto merge of #8451 - matthiaskrgr:ui_speedup, r=llogiq

tests: default to more threads for ui-tests

Benchmarks (tested on i5-7200U, 2 cores, 4 threads)

```
master branch:

cargo test // prime caches
cargo --color=always test  70,39s user 21,91s system 180% cpu 51,035 total
cargo --color=always test  70,77s user 22,13s system 180% cpu 51,579 total
cargo --color=always test  70,97s user 22,12s system 180% cpu 51,673 total

cargo --color=always nextest run  78,74s user 22,27s system 220% cpu 45,829 total
cargo --color=always nextest run  78,46s user 21,92s system 224% cpu 44,674 total
cargo --color=always nextest run  78,31s user 22,21s system 228% cpu 43,909 total

Patched (ui_speedup branch):

cargo test // prime cache
cargo --color=always test  97,51s user 32,02s system 288% cpu 44,905 total
cargo --color=always test  99,19s user 31,91s system 276% cpu 47,436 total
cargo --color=always test  98,47s user 31,84s system 284% cpu 45,744 total

cargo --color=always nextest run  102,18s user 30,80s system 350% cpu 37,902 total
cargo --color=always nextest run  99,75s user 29,86s system 350% cpu 36,935 total
cargo --color=always nextest run  100,36s user 29,93s system 351% cpu 37,061 total
```

changelog: use more threads for running clippys ui-tests for ~10% walltime speedup

2 years agoUse the precise namespace for `Reverse`
Ken Matsui [Tue, 22 Feb 2022 21:06:09 +0000 (06:06 +0900)]
Use the precise namespace for `Reverse`

2 years agoAuto merge of #8443 - Jarcho:match_cfg_arm, r=flip1995
bors [Mon, 21 Feb 2022 08:46:42 +0000 (08:46 +0000)]
Auto merge of #8443 - Jarcho:match_cfg_arm, r=flip1995

Don't lint `match` expressions with `cfg`ed arms

Somehow there are no open issues related to this for any of the affected lints. At least none that I could fine from a quick search.

changelog: Don't lint `match` expressions with `cfg`ed arms in many cases

2 years agoupdate clippy
lcnr [Mon, 7 Feb 2022 15:06:55 +0000 (16:06 +0100)]
update clippy

2 years agofix
tamaron [Mon, 21 Feb 2022 04:25:53 +0000 (13:25 +0900)]
fix

2 years agotests: default to more threads for ui-tests
Matthias Krüger [Sun, 20 Feb 2022 12:45:37 +0000 (13:45 +0100)]
tests: default to more threads for ui-tests

Benchmarks (tested on i5-7200U, 2 core 4 threads)

```
master branch:

cargo test // prime caches
cargo --color=always test  70,39s user 21,91s system 180% cpu 51,035 total
cargo --color=always test  70,77s user 22,13s system 180% cpu 51,579 total
cargo --color=always test  70,97s user 22,12s system 180% cpu 51,673 total

cargo --color=always nextest run  78,74s user 22,27s system 220% cpu 45,829 total
cargo --color=always nextest run  78,46s user 21,92s system 224% cpu 44,674 total
cargo --color=always nextest run  78,31s user 22,21s system 228% cpu 43,909 total

Patched (ui_speedup branch)

cargo test // prime cache
cargo --color=always test  97,51s user 32,02s system 288% cpu 44,905 total
cargo --color=always test  99,19s user 31,91s system 276% cpu 47,436 total
cargo --color=always test  98,47s user 31,84s system 284% cpu 45,744 total

cargo --color=always nextest run  102,18s user 30,80s system 350% cpu 37,902 total
cargo --color=always nextest run  99,75s user 29,86s system 350% cpu 36,935 total
cargo --color=always nextest run  100,36s user 29,93s system 351% cpu 37,061 total
```

2 years agoTransmute_undefined_repr to nursery again
David Tolnay [Sat, 12 Feb 2022 03:40:07 +0000 (19:40 -0800)]
Transmute_undefined_repr to nursery again

2 years agoAuto merge of #8440 - Jarcho:transmute_undefined, r=Manishearth
bors [Fri, 18 Feb 2022 22:48:23 +0000 (22:48 +0000)]
Auto merge of #8440 - Jarcho:transmute_undefined, r=Manishearth

Some more fixes for `transmute_undefined_repr`

changelog: Fix transmuting a struct containing a pointer into a pointer in `transmute_undefined_repr`
changelog: Allow various forms of type erasure in `transmute_undefined_repr`

2 years agoClarify `cfg` detection process in `matches.rs`
Jason Newcomb [Fri, 18 Feb 2022 20:41:46 +0000 (15:41 -0500)]
Clarify `cfg` detection process in `matches.rs`

2 years agoFix `transmute_undefined_repr` when converting between a fat pointer and a type conta...
Jason Newcomb [Wed, 16 Feb 2022 19:59:04 +0000 (14:59 -0500)]
Fix `transmute_undefined_repr` when converting between a fat pointer and a type containing a fat pointer

2 years agoAllow transmuting fat pointers to some types in `transmute_undefined_repr`
Jason Newcomb [Wed, 16 Feb 2022 15:45:49 +0000 (10:45 -0500)]
Allow transmuting fat pointers to some types in `transmute_undefined_repr`

2 years agoAllow various type erasure patterns in `transmute_undefined_repr`
Jason Newcomb [Tue, 15 Feb 2022 19:51:57 +0000 (14:51 -0500)]
Allow various type erasure patterns in `transmute_undefined_repr`

2 years agoAdd some comments to `transmute_undefined_repr`
Jason Newcomb [Tue, 15 Feb 2022 16:39:19 +0000 (11:39 -0500)]
Add some comments to `transmute_undefined_repr`

2 years agoFix `transmute_undefined_repr` when converting between a pointer and a type containin...
Jason Newcomb [Tue, 15 Feb 2022 16:29:02 +0000 (11:29 -0500)]
Fix `transmute_undefined_repr` when converting between a pointer and a type containing a pointer

2 years agoAuto merge of #8381 - Jarcho:cast_possible_truncation_542, r=Manishearth
bors [Fri, 18 Feb 2022 19:31:10 +0000 (19:31 +0000)]
Auto merge of #8381 - Jarcho:cast_possible_truncation_542, r=Manishearth

Lint enum-to-int casts with `cast_possible_truncation`

fixes: #542

~~This will not lint casting a specific variant to an integer. That really should be a new lint as it's definitely a truncation (other than `isize`/`usize` values).~~

changelog: Lint enum-to-int casts with `cast_possible_truncation`
changelog: New lint `cast_enum_truncation`

2 years agoExtract some util functions
Jason Newcomb [Fri, 18 Feb 2022 14:10:48 +0000 (09:10 -0500)]
Extract some util functions

2 years agoNew lint `cast_enum_truncation`
Jason Newcomb [Tue, 1 Feb 2022 02:22:47 +0000 (21:22 -0500)]
New lint `cast_enum_truncation`

2 years agoLint enum-to-int casts with `cast_possible_truncation`
Jason Newcomb [Mon, 31 Jan 2022 20:45:49 +0000 (15:45 -0500)]
Lint enum-to-int casts with `cast_possible_truncation`

2 years agoAuto merge of #8419 - flip1995:await_parking_alot, r=llogiq
bors [Fri, 18 Feb 2022 10:55:05 +0000 (10:55 +0000)]
Auto merge of #8419 - flip1995:await_parking_alot, r=llogiq

Fix `await_holding_lock` not linting `parking_lot` Mutex/RwLock

This adds tests for `RwLock` and `parking_lot::{Mutex, RwLock}`, which were added before in https://github.com/rust-lang/rust-clippy/commit/2dc8c083f54454ca87bb09d691577eada2d23539, but never tested in UI tests. I noticed this while reading [fasterthanli.me](https://fasterthanli.me/articles/a-rust-match-made-in-hell) latest blog post, complaining that Clippy doesn't catch this for `parking_lot`. (Too many people read his blog, he's too powerful)

Some more things:
- Adds a test for #6446
- Improves the lint message

changelog: [`await_holding_lock`]: Now also lints for `parking_lot::{Mutex, RwLock}`

2 years agoAuto merge of #94088 - oli-obk:revert, r=jackh726
bors [Fri, 18 Feb 2022 07:35:37 +0000 (07:35 +0000)]
Auto merge of #94088 - oli-obk:revert, r=jackh726

Revert #91403

fixes #94004

r? `@pnkfelix` `@cjgillot`

2 years agoAuto merge of #8442 - rsmantini:issue-8120-fix, r=Manishearth
bors [Thu, 17 Feb 2022 22:57:23 +0000 (22:57 +0000)]
Auto merge of #8442 - rsmantini:issue-8120-fix, r=Manishearth

trigger  `ptr_as_ptr` inside macros

This PR makes `ptr_as_ptr` trigger inside macros

Fixes issue #8120

changelog: ``[`ptr_as_ptr`]`` is now triggered inside macros

r? `@llogiq`

2 years agoRemove hack testing for `cfg` attribute in `match_single_binding`
Jason Newcomb [Thu, 17 Feb 2022 19:16:21 +0000 (14:16 -0500)]
Remove hack testing for `cfg` attribute in `match_single_binding`

2 years agotrigger ptr_as_ptr inside macros
Rodrigo Mantini [Thu, 17 Feb 2022 00:08:53 +0000 (01:08 +0100)]
trigger ptr_as_ptr inside macros

2 years agoCheck for `cfg` attrubutes before linting `match` expressions
Jason Newcomb [Thu, 17 Feb 2022 18:43:59 +0000 (13:43 -0500)]
Check for `cfg` attrubutes before linting `match` expressions

2 years agoMove await_holding_* lints to suspicious and improve doc
flip1995 [Thu, 17 Feb 2022 16:57:39 +0000 (17:57 +0100)]
Move await_holding_* lints to suspicious and improve doc

Even though the FP for that the lints were moved to pedantic isn't fixed
yet, running the lintcheck tool over the most popular 279 crates didn't
trigger this lint once. I would say that this lint is valuable enough,
despite the known FP, to be warn-by-default. Especially since a pretty
nice workaround exists.

2 years agoAdd test for drop-before-await FP
flip1995 [Sat, 12 Feb 2022 10:30:03 +0000 (11:30 +0100)]
Add test for drop-before-await FP

2 years agoActually lint parking_lot in await_holding_lock
flip1995 [Sat, 12 Feb 2022 09:32:44 +0000 (10:32 +0100)]
Actually lint parking_lot in await_holding_lock

This adapts the paths for the parking_lot mutex guards, so that
parking_lot mutexes and RwLocks actually get linted. This is now also
tested.

2 years agoImprove lint message of await_holding_*
flip1995 [Sat, 12 Feb 2022 09:23:07 +0000 (10:23 +0100)]
Improve lint message of await_holding_*

Improves the message of the lints await_holding_lock and
await_holding_refcell_ref. Now also actually tests RwLock.

2 years agoAuto merge of #8218 - Jarcho:redundant_slicing_deref, r=camsteffen
bors [Thu, 17 Feb 2022 16:08:45 +0000 (16:08 +0000)]
Auto merge of #8218 - Jarcho:redundant_slicing_deref, r=camsteffen

Improve `redundant_slicing` lint

fixes #7972
fixes #7257

This can supersede #7976

changelog: Fix suggestion for `redundant_slicing` when re-borrowing for a method call
changelog: New lint `deref_as_slicing`

2 years agoRevert "Auto merge of #91403 - cjgillot:inherit-async, r=oli-obk"
Oli Scherer [Thu, 17 Feb 2022 16:00:04 +0000 (16:00 +0000)]
Revert "Auto merge of #91403 - cjgillot:inherit-async, r=oli-obk"

This reverts commit 3cfa4def7c87d571bd46d92fed608edf8fad236e, reversing
changes made to 5d8767cb229b097fedb1dd4bd9420d463c37774f.

2 years agoAuto merge of #8441 - Jarcho:needless_borrow_temp, r=flip1995
bors [Thu, 17 Feb 2022 15:51:30 +0000 (15:51 +0000)]
Auto merge of #8441 - Jarcho:needless_borrow_temp, r=flip1995

Don't lint `needless_borrow` in method receiver positions

fixes #8408
fixes #8407
fixes #8391
fixes #8367
fixes #8380

This is a temporary fix for `needless_borrow`. The proper fix is included in #8355.

This should probably be merged into rustc before beta branches on Friday. This issue has been reported six or seven times in the past couple of weeks.

changelog: Fix various issues with `needless_borrow` n´. Note to changelog writer: those issues might have been introduced in this release cycle, so this might not matter in the changelog.

2 years agoRemove some redundant checks in various matches lints
Jason Newcomb [Thu, 17 Feb 2022 15:48:24 +0000 (10:48 -0500)]
Remove some redundant checks in various matches lints

2 years agoDon't lint `needless_borrow` in method receiver positions
Jason Newcomb [Thu, 17 Feb 2022 04:14:39 +0000 (23:14 -0500)]
Don't lint `needless_borrow` in method receiver positions

2 years agoAuto merge of #8433 - hellow554:update_default_trait, r=flip1995
bors [Thu, 17 Feb 2022 09:13:30 +0000 (09:13 +0000)]
Auto merge of #8433 - hellow554:update_default_trait, r=flip1995

Don't lint Default::default if it is the udpate syntax base

changelog: Don't lint `Default::default` it is part of the update syntax

Current clippy warns about this:

```
warning: calling `Foo::default()` is more clear than this expression
  --> src/main.rs:12:11
   |
12 |         ..Default::default()
   |           ^^^^^^^^^^^^^^^^^^ help: try: `Foo::default()`
   |
```

With these changes, it will not lint that particular expression anymore.

2 years agoDon't lint Default::default if it is the udpate syntax base
Marcel Hellwig [Mon, 14 Feb 2022 12:22:36 +0000 (13:22 +0100)]
Don't lint Default::default if it is the udpate syntax base

An Update Syntax looks like this:

   Foo {
      a: 3,
      ..Default::default()
    }

Don't lint `Default::default` here

2 years agoRollup merge of #94030 - ChayimFriedman2:issue-94010, r=petrochenkov
Matthias Krüger [Thu, 17 Feb 2022 05:30:02 +0000 (06:30 +0100)]
Rollup merge of #94030 - ChayimFriedman2:issue-94010, r=petrochenkov

Correctly mark the span of captured arguments in `format_args!()`

It should not include the braces, or misspelling suggestions will be wrong.

Fixes #94010.

2 years agoMove some cases from `redundant_slicing` to `deref_by_slicing`
Jason Newcomb [Sun, 13 Feb 2022 23:43:19 +0000 (18:43 -0500)]
Move some cases from `redundant_slicing` to `deref_by_slicing`

2 years agoSplit off new lint `deref_by_slicing` from `redundant_slicing`
Jason Newcomb [Tue, 11 Jan 2022 17:41:15 +0000 (12:41 -0500)]
Split off new lint `deref_by_slicing` from `redundant_slicing`

2 years agoAccount for auto-borrows and precedence in `redundant_slicing` lint
Jason Newcomb [Tue, 4 Jan 2022 01:35:32 +0000 (20:35 -0500)]
Account for auto-borrows and precedence in `redundant_slicing` lint

2 years agoImprove `redundant_slicing` lint
Jason Newcomb [Mon, 3 Jan 2022 20:25:00 +0000 (15:25 -0500)]
Improve `redundant_slicing` lint

* Lint when slicing triggers auto-deref
* Lint when slicing returns the same type as dereferencing

2 years agoDon't lint `needless_borrow` in method receiver positions
Jason Newcomb [Thu, 17 Feb 2022 04:14:39 +0000 (23:14 -0500)]
Don't lint `needless_borrow` in method receiver positions

2 years agoAuto merge of #8188 - jamesmcm:recursive_display_impl, r=camsteffen
bors [Wed, 16 Feb 2022 22:01:49 +0000 (22:01 +0000)]
Auto merge of #8188 - jamesmcm:recursive_display_impl, r=camsteffen

new lint: `recursive_format_impl`

The to_string_in_display lint is renamed to recursive_format_impl
A check is added for the use of self formatted with Display or Debug inside any format string in the same impl
The to_string_in_display check is kept as is - like in the format_in_format_args lint

This is my first contribution so please check it for better / more idiomatic checks + error messages. Note the format macro paths are shared with the `format_in_format_args` lint - maybe those could be moved to clippy utils too.

This relates to issues #2691 and #7830

------

changelog: Renamed `to_string_in_display` lint to [`recursive_format_impl`] with new check for any use of self as Display or Debug inside the same format trait impl.

2 years agoCorrectly mark the span of captured arguments in `format_args!()`
Chayim Refael Friedman [Wed, 16 Feb 2022 00:38:04 +0000 (00:38 +0000)]
Correctly mark the span of captured arguments in `format_args!()`

It should only include the identifier, or misspelling suggestions will be wrong.

2 years agoRollup merge of #94014 - flip1995:clippy_transmute_lint_regroup, r=dtolnay
Matthias Krüger [Tue, 15 Feb 2022 15:02:37 +0000 (16:02 +0100)]
Rollup merge of #94014 - flip1995:clippy_transmute_lint_regroup, r=dtolnay

Move transmute_undefined_repr back to nursery

There's still open discussion if this lint is ready to be enabled by
default. We want to give us more time to figure this out and prevent
this lint from getting to stable as an enabled-by-default lint.

cc https://github.com/rust-lang/rust-clippy/pull/8432

r? `@Manishearth` `@dtolnay`

I think this is the way to go here. We can re-enable this lint with the next sync, if we should decide to do so. But I would hold of for this release.

We have until Friday (beta branching) to decide if we want to merge this.

2 years agoMove transmute_undefined_repr back to nursery
flip1995 [Tue, 15 Feb 2022 09:54:38 +0000 (10:54 +0100)]
Move transmute_undefined_repr back to nursery

There's still open discussion if this lint is ready to be enabled by
default. We want to give us more time to figure this out and prevent
this lint from getting to stable as an enabled-by-default lint.

2 years agoOverhaul `Const`.
Nicholas Nethercote [Wed, 2 Feb 2022 03:24:45 +0000 (14:24 +1100)]
Overhaul `Const`.

Specifically, rename the `Const` struct as `ConstS` and re-introduce `Const` as
this:
```
pub struct Const<'tcx>(&'tcx Interned<ConstS>);
```
This now matches `Ty` and `Predicate` more closely, including using
pointer-based `eq` and `hash`.

Notable changes:
- `mk_const` now takes a `ConstS`.
- `Const` was copy, despite being 48 bytes. Now `ConstS` is not, so need a
  we need separate arena for it, because we can't use the `Dropless` one any
  more.
- Many `&'tcx Const<'tcx>`/`&Const<'tcx>` to `Const<'tcx>` changes
- Many `ct.ty` to `ct.ty()` and `ct.val` to `ct.val()` changes.
- Lots of tedious sigil fiddling.

2 years agoOverhaul `RegionKind` and `Region`.
Nicholas Nethercote [Fri, 28 Jan 2022 00:25:15 +0000 (11:25 +1100)]
Overhaul `RegionKind` and `Region`.

Specifically, change `Region` from this:
```
pub type Region<'tcx> = &'tcx RegionKind;
```
to this:
```
pub struct Region<'tcx>(&'tcx Interned<RegionKind>);
```

This now matches `Ty` and `Predicate` more closely.

Things to note
- Regions have always been interned, but we haven't been using pointer-based
  `Eq` and `Hash`. This is now happening.
- I chose to impl `Deref` for `Region` because it makes pattern matching a lot
  nicer, and `Region` can be viewed as just a smart wrapper for `RegionKind`.
- Various methods are moved from `RegionKind` to `Region`.
- There is a lot of tedious sigil changes.
- A couple of types like `HighlightBuilder`, `RegionHighlightMode` now have a
  `'tcx` lifetime because they hold a `Ty<'tcx>`, so they can call `mk_region`.
- A couple of test outputs change slightly, I'm not sure why, but the new
  outputs are a little better.

2 years agoOverhaul `TyS` and `Ty`.
Nicholas Nethercote [Tue, 25 Jan 2022 03:13:38 +0000 (14:13 +1100)]
Overhaul `TyS` and `Ty`.

Specifically, change `Ty` from this:
```
pub type Ty<'tcx> = &'tcx TyS<'tcx>;
```
to this
```
pub struct Ty<'tcx>(Interned<'tcx, TyS<'tcx>>);
```
There are two benefits to this.
- It's now a first class type, so we can define methods on it. This
  means we can move a lot of methods away from `TyS`, leaving `TyS` as a
  barely-used type, which is appropriate given that it's not meant to
  be used directly.
- The uniqueness requirement is now explicit, via the `Interned` type.
  E.g. the pointer-based `Eq` and `Hash` comes from `Interned`, rather
  than via `TyS`, which wasn't obvious at all.

Much of this commit is boring churn. The interesting changes are in
these files:
- compiler/rustc_middle/src/arena.rs
- compiler/rustc_middle/src/mir/visit.rs
- compiler/rustc_middle/src/ty/context.rs
- compiler/rustc_middle/src/ty/mod.rs

Specifically:
- Most mentions of `TyS` are removed. It's very much a dumb struct now;
  `Ty` has all the smarts.
- `TyS` now has `crate` visibility instead of `pub`.
- `TyS::make_for_test` is removed in favour of the static `BOOL_TY`,
  which just works better with the new structure.
- The `Eq`/`Ord`/`Hash` impls are removed from `TyS`. `Interned`s impls
  of `Eq`/`Hash` now suffice. `Ord` is now partly on `Interned`
  (pointer-based, for the `Equal` case) and partly on `TyS`
  (contents-based, for the other cases).
- There are many tedious sigil adjustments, i.e. adding or removing `*`
  or `&`. They seem to be unavoidable.

2 years agoAdd recursive_format_impl lint
James McMurray [Tue, 28 Dec 2021 18:27:11 +0000 (19:27 +0100)]
Add recursive_format_impl lint

The to_string_in_display lint is renamed to recursive_format_impl
A check is added for the use of self formatted with Display or Debug
inside any format string in the same impl
The to_string_in_display check is kept as is - like in the
format_in_format_args lint

For now only Display and Debug are checked
This could also be extended to other Format traits (Binary, etc.)

2 years agoAuto merge of #93938 - BoxyUwU:fix_res_self_ty, r=lcnr
bors [Mon, 14 Feb 2022 12:26:43 +0000 (12:26 +0000)]
Auto merge of #93938 - BoxyUwU:fix_res_self_ty, r=lcnr

Make `Res::SelfTy` a struct variant and update docs

I found pattern matching on a `(Option<DefId>, Option<(DefId, bool)>)` to not be super readable, additionally the doc comments on the types in a tuple variant aren't visible anywhere at use sites as far as I can tell (using rust analyzer + vscode)

The docs incorrectly assumed that the `DefId` in `Option<(DefId, bool)>` would only ever be for an impl item and I also found the code examples to be somewhat unclear about which `DefId` was being talked about.

r? `@lcnr` since you reviewed the last PR changing these docs

2 years agoAuto merge of #8425 - Jarcho:transmute_8417, r=giraffate
bors [Mon, 14 Feb 2022 06:58:51 +0000 (06:58 +0000)]
Auto merge of #8425 - Jarcho:transmute_8417, r=giraffate

Fix `transmute_undefined_repr` with single field `#[repr(C)]` structs

Fixes: #8417
The description has also been made more precise.

changelog: Fix `transmute_undefined_repr` with single field `#[repr(C)]` structs
changelog: Move `transmute_undefined_repr` back to `correctness`

2 years agoAuto merge of #8427 - Jarcho:merge_cargo_passes, r=llogiq
bors [Mon, 14 Feb 2022 06:14:02 +0000 (06:14 +0000)]
Auto merge of #8427 - Jarcho:merge_cargo_passes, r=llogiq

Merge cargo lints

changelog: None

2 years agoAuto merge of #8429 - nsunderland1:master, r=llogiq
bors [Mon, 14 Feb 2022 05:55:34 +0000 (05:55 +0000)]
Auto merge of #8429 - nsunderland1:master, r=llogiq

Document `pub` requirement for `new_without_default` lint

fixes #8415

Also adds some UI tests that ensure that `pub` is required on both the struct _and_ the field. The only thing I'm not sure about is that the lint actually [checks](https://github.com/rust-lang/rust-clippy/blob/master/clippy_lints/src/new_without_default.rs#L102) if `new` is _reachable_, not _public_. To the best of my understanding, both the struct and the method need to be public for the method to be reachable for external crates (I certainly didn't manage to craft a counterexample).

changelog: Document `pub` requirement for ``[`new_without_default`]`` lint.

2 years agoDocument `pub` requirement for `new_without_default` lint
nsunderland1 [Mon, 14 Feb 2022 01:07:14 +0000 (17:07 -0800)]
Document `pub` requirement for `new_without_default` lint