]> git.lizzy.rs Git - rust.git/log
rust.git
2 years agoremoving unsafe from test fn's && renaming shrink to sugg_span
Marek Downar [Mon, 17 Jan 2022 11:34:03 +0000 (12:34 +0100)]
removing unsafe from test fn's && renaming shrink to sugg_span

2 years agoissue #8239: fix to prev commit && 4 test cases
Marek Downar [Sat, 15 Jan 2022 21:19:01 +0000 (22:19 +0100)]
issue #8239: fix to prev commit && 4 test cases

2 years agoissue #8239: Printed hint for lint or_fun_call is cropped and does not show the solution
Marek Downar [Sat, 15 Jan 2022 14:51:46 +0000 (15:51 +0100)]
issue #8239: Printed hint for lint or_fun_call is cropped and does not show the solution

2 years agoAuto merge of #8273 - SeeSpring:apply_not_unsafe_ptr_arg_deref_to_type_aliases, r...
bors [Thu, 13 Jan 2022 18:51:19 +0000 (18:51 +0000)]
Auto merge of #8273 - SeeSpring:apply_not_unsafe_ptr_arg_deref_to_type_aliases, r=llogiq

Apply `not_unsafe_ptr_arg_deref` to type aliases

changelog: Apply [`not_unsafe_ptr_arg_deref`] to type aliases

2 years agoApply `not_unsafe_ptr_arg_deref` to type aliases
SeeSpring [Thu, 13 Jan 2022 14:27:08 +0000 (09:27 -0500)]
Apply `not_unsafe_ptr_arg_deref` to type aliases

2 years agoAuto merge of #8272 - flip1995:rustup, r=flip1995
bors [Thu, 13 Jan 2022 11:55:36 +0000 (11:55 +0000)]
Auto merge of #8272 - flip1995:rustup, r=flip1995

Rustup

r? `@ghost`

changelog: none

2 years agoBump nightly version -> 2022-01-13
flip1995 [Thu, 13 Jan 2022 11:48:17 +0000 (12:48 +0100)]
Bump nightly version -> 2022-01-13

2 years agoBump Clippy Version -> 0.1.60
flip1995 [Thu, 13 Jan 2022 11:48:08 +0000 (12:48 +0100)]
Bump Clippy Version -> 0.1.60

2 years agoMerge remote-tracking branch 'upstream/master' into rustup
flip1995 [Thu, 13 Jan 2022 11:11:21 +0000 (12:11 +0100)]
Merge remote-tracking branch 'upstream/master' into rustup

2 years agoAuto merge of #8226 - Jarcho:manual_memcpy_8160, r=flip1995
bors [Wed, 12 Jan 2022 18:44:34 +0000 (18:44 +0000)]
Auto merge of #8226 - Jarcho:manual_memcpy_8160, r=flip1995

`manual_memcpy` fix

fixes #8160

Ideally this would work with `VecDeque`, but the current interface is unsuitable for it. At a minimum something like `range_as_slices` would be needed.

changelog: Don't lint `manual_memcpy` on `VecDeque`
changelog: Suggest `copy_from_slice` for `manual_memcpy` when applicable

2 years agoAdd `manual_memcpy_test` for `VecDeque`
Jason Newcomb [Wed, 12 Jan 2022 17:33:47 +0000 (12:33 -0500)]
Add `manual_memcpy_test` for `VecDeque`

2 years agoAuto merge of #8266 - camsteffen:test-tweaks, r=flip1995
bors [Wed, 12 Jan 2022 17:19:58 +0000 (17:19 +0000)]
Auto merge of #8266 - camsteffen:test-tweaks, r=flip1995

Some test code cleanup

changelog: none

Mainly moves /clippy_workspace_tests into /tests and combines the two dogfood tests which can't run concurrently.

2 years agoAuto merge of #8265 - camsteffen:which-rustfmt, r=xFrednet
bors [Wed, 12 Jan 2022 17:03:52 +0000 (17:03 +0000)]
Auto merge of #8265 - camsteffen:which-rustfmt, r=xFrednet

Cache rustfmt path

changelog: none

Call `rustup which rustfmt` and use the output. This shaves off  ~0.7 seconds for `cargo dev fmt` for me.

2 years agoOnly run dogfood on linux in CI
Cameron Steffen [Wed, 12 Jan 2022 16:46:05 +0000 (10:46 -0600)]
Only run dogfood on linux in CI

2 years agoAuto merge of #8112 - Alexendoo:disallowed_methods_primitives, r=flip1995
bors [Wed, 12 Jan 2022 16:47:45 +0000 (16:47 +0000)]
Auto merge of #8112 - Alexendoo:disallowed_methods_primitives, r=flip1995

Allow primitive types in disallowed_methods

Fixes #8079

changelog: `disallowed_methods`: Now can disallow methods of primitive types

2 years agoUse method name from conf::DisallowedMethod
Alex Macleod [Thu, 9 Dec 2021 20:42:44 +0000 (20:42 +0000)]
Use method name from conf::DisallowedMethod

Since def_path_str returns e.g. "core::f32::<impl f32>::clamp" for
"f32::clamp"

2 years agoAuto merge of #8213 - paolobarbolini:size-of-as-bits, r=flip1995
bors [Wed, 12 Jan 2022 16:21:14 +0000 (16:21 +0000)]
Auto merge of #8213 - paolobarbolini:size-of-as-bits, r=flip1995

Add `manual_bits` lint

Closes #6670

---

changelog: new lint: [`manual_bits`]

2 years agoResolve primitive impls in clippy_utils::path_to_res
Alex Macleod [Thu, 9 Dec 2021 19:11:40 +0000 (19:11 +0000)]
Resolve primitive impls in clippy_utils::path_to_res

2 years agoAdd manual_bits lint
Paolo Barbolini [Sun, 2 Jan 2022 22:34:10 +0000 (23:34 +0100)]
Add manual_bits lint

2 years agoAuto merge of #8037 - ojeda:doc-codegen-change, r=camsteffen
bors [Wed, 12 Jan 2022 15:11:08 +0000 (15:11 +0000)]
Auto merge of #8037 - ojeda:doc-codegen-change, r=camsteffen

`README`: document that Clippy may change codegen

Currently, Clippy does not guarantee the same codegen will be produced.
Therefore, it should not be used as an universal replacement for `rustc`.

See https://github.com/rust-lang/rust-clippy/issues/8035.

Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
fixes #8035
changelog: document that Clippy may change codegen

2 years agoAuto merge of #8190 - camsteffen:no-in-band-liftetimes, r=flip1995
bors [Wed, 12 Jan 2022 14:25:11 +0000 (14:25 +0000)]
Auto merge of #8190 - camsteffen:no-in-band-liftetimes, r=flip1995

Stop using `in_band_lifetimes`

Per rust-lang/rust#91867

changelog: none

2 years agoAuto merge of #8198 - camsteffen:no-method-call-macro, r=flip1995
bors [Wed, 12 Jan 2022 13:59:12 +0000 (13:59 +0000)]
Auto merge of #8198 - camsteffen:no-method-call-macro, r=flip1995

Remove method_call! macro

This is possible now that `SymbolStr` is removed from rustc.

changelog: none

2 years agoAuto merge of #8268 - Jarcho:deref_addrof_8247, r=flip1995
bors [Wed, 12 Jan 2022 13:25:58 +0000 (13:25 +0000)]
Auto merge of #8268 - Jarcho:deref_addrof_8247, r=flip1995

Fix `deref_addrof`

fixes #8247

This would supersede #8259

changelog: Don't lint `deref_addrof` when the dereference and the borrow occur in different contexts

2 years agoDon't lint `deref_addrof` when the two operations occur in different expansions
Jason Newcomb [Wed, 12 Jan 2022 05:25:42 +0000 (00:25 -0500)]
Don't lint `deref_addrof` when the two operations occur in different expansions

2 years agoAuto merge of #8262 - 1nF0rmed:chore-update-borrowed-box-doc, r=camsteffen
bors [Tue, 11 Jan 2022 17:07:50 +0000 (17:07 +0000)]
Auto merge of #8262 - 1nF0rmed:chore-update-borrowed-box-doc, r=camsteffen

Improve documentation for `borrowed-box` lint

fixes #8161

Updates documentation to elaborate more on how removing Box from a function parameter can generalize the function.

changelog: none

2 years agoImprove documentation for `borrowed-box` lint
Pradyumna Rahul [Mon, 10 Jan 2022 16:14:10 +0000 (21:44 +0530)]
Improve documentation for `borrowed-box` lint

2 years agoStop using in_band_lifetimes
Cameron Steffen [Tue, 11 Jan 2022 15:52:23 +0000 (09:52 -0600)]
Stop using in_band_lifetimes

2 years agoAuto merge of #8210 - guerinoni:master, r=Manishearth
bors [Tue, 11 Jan 2022 15:45:50 +0000 (15:45 +0000)]
Auto merge of #8210 - guerinoni:master, r=Manishearth

Add borrow_as_ptr lint

Closes: #6995
- \[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`

---

changelog: new lint: [`borrow_as_ptr`]

2 years agoStore a `Symbol` instead of an `Ident` in `VariantDef`/`FieldDef`
Aaron Hill [Mon, 3 Jan 2022 03:37:05 +0000 (22:37 -0500)]
Store a `Symbol` instead of an `Ident` in `VariantDef`/`FieldDef`

The field is also renamed from `ident` to `name. In most cases,
we don't actually need the `Span`. A new `ident` method is added
to `VariantDef` and `FieldDef`, which constructs the full `Ident`
using `tcx.def_ident_span()`. This method is used in the cases
where we actually need an `Ident`.

This makes incremental compilation properly track changes
to the `Span`, without all of the invalidations caused by storing
a `Span` directly via an `Ident`.

2 years ago`README`: mention `clippy-driver` on usage list
Miguel Ojeda [Tue, 14 Dec 2021 17:13:14 +0000 (18:13 +0100)]
`README`: mention `clippy-driver` on usage list

Removes the "compiled from source" bit, which is confusing.

Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2 years ago`README`: `clippy-driver` is not a replacement for `rustc`
Miguel Ojeda [Sat, 27 Nov 2021 16:10:19 +0000 (17:10 +0100)]
`README`: `clippy-driver` is not a replacement for `rustc`

Currently, `clippy-driver` may run codegen, but this is an
implementation detail.

See https://github.com/rust-lang/rust-clippy/issues/8035.

Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2 years agoAdd borrow_as_ptr lint
Federico Guerinoni [Sun, 2 Jan 2022 13:26:44 +0000 (14:26 +0100)]
Add borrow_as_ptr lint

Closes: #6995
Signed-off-by: Federico Guerinoni <guerinoni.federico@gmail.com>
Co-authored-by: Paolo Barbolini <paolo@paolo565.org>
2 years agoAuto merge of #8260 - taiki-e:mutex_atomic, r=llogiq
bors [Tue, 11 Jan 2022 08:09:11 +0000 (08:09 +0000)]
Auto merge of #8260 - taiki-e:mutex_atomic, r=llogiq

Downgrade mutex_atomic to nursery

See #1516 and #4295.

There are suggestions about removing this lint from the default warned lints in both issues.
Also, [`mutex_integer`](https://rust-lang.github.io/rust-clippy/master/index.html#mutex_integer) lint that has the same problems as this lint is in `nursery` group.

changelog: Moved [`mutex_atomic`] to `nursery`

2 years agoFix dogfood
Cameron Steffen [Mon, 10 Jan 2022 23:47:56 +0000 (17:47 -0600)]
Fix dogfood

2 years agoAuto merge of #8261 - taiki-e:disallowed, r=giraffate
bors [Mon, 10 Jan 2022 23:51:39 +0000 (23:51 +0000)]
Auto merge of #8261 - taiki-e:disallowed, r=giraffate

Warn disallowed_methods and disallowed_types by default

Closes #7841

changelog: Moved [`disallowed_methods`] and [`disallowed_types`] to `style`

2 years agoRemove rustfmt component check
Cameron Steffen [Mon, 10 Jan 2022 20:05:38 +0000 (14:05 -0600)]
Remove rustfmt component check

This was more valuable when we used the latest nightly without
specifying the toolchain version.

2 years agoMerge dogfood tests
Cameron Steffen [Mon, 10 Jan 2022 20:03:55 +0000 (14:03 -0600)]
Merge dogfood tests

The two dogfood tests cannot be run concurrently since they use the same
target directory.

2 years agoMove workspace test
Cameron Steffen [Mon, 10 Jan 2022 21:27:00 +0000 (15:27 -0600)]
Move workspace test

2 years agoUse `rustup which rustfmt`
Cameron Steffen [Mon, 10 Jan 2022 19:53:02 +0000 (13:53 -0600)]
Use `rustup which rustfmt`

2 years agoRefactor test utils
Cameron Steffen [Mon, 10 Jan 2022 19:20:46 +0000 (13:20 -0600)]
Refactor test utils

2 years agoFix output capturing
Cameron Steffen [Mon, 10 Jan 2022 20:30:45 +0000 (14:30 -0600)]
Fix output capturing

2 years agoRun dogfood on windows
Cameron Steffen [Mon, 10 Jan 2022 17:05:05 +0000 (11:05 -0600)]
Run dogfood on windows

I believe this is possible as of rust-lang/rust-clippy#7631

2 years agoWarn disallowed_methods and disallowed_types by default
Taiki Endo [Mon, 10 Jan 2022 17:17:14 +0000 (02:17 +0900)]
Warn disallowed_methods and disallowed_types by default

2 years agoDowngrade mutex_atomic to nursery
Taiki Endo [Mon, 10 Jan 2022 14:36:13 +0000 (23:36 +0900)]
Downgrade mutex_atomic to nursery

2 years agoAuto merge of #8228 - Jarcho:iter_not_returning_iterator_8225, r=giraffate
bors [Mon, 10 Jan 2022 12:34:15 +0000 (12:34 +0000)]
Auto merge of #8228 - Jarcho:iter_not_returning_iterator_8225, r=giraffate

fix `iter_not_returning_iterator`

fixes #8225

changelog: Handle type projections in `iter_not_returning_iterator`
changelog: Don't lint `iter_not_returning_iterator` in trait implementations
changelog: Lint `iter_not_returning_iterator` in trait definitions

2 years agoAuto merge of #8257 - camsteffen:internal-features, r=giraffate
bors [Mon, 10 Jan 2022 12:18:05 +0000 (12:18 +0000)]
Auto merge of #8257 - camsteffen:internal-features, r=giraffate

Combine internal cargo features

changelog: none

This is just simpler and I don't see any downsides.

2 years agoAuto merge of #8252 - dswij:8229, r=xFrednet
bors [Mon, 10 Jan 2022 10:31:59 +0000 (10:31 +0000)]
Auto merge of #8252 - dswij:8229, r=xFrednet

cover trait for `trait_duplication_in_bounds`

closes #8229

changelog: [`trait_duplication_in_bounds`] covers trait functions with `Self` bounds

2 years ago`trait_duplication_in_bounds` Update description and add test
dswij [Mon, 10 Jan 2022 04:45:01 +0000 (12:45 +0800)]
`trait_duplication_in_bounds` Update description and add test

2 years agoCombine internal features in clippy_lints
Cameron Steffen [Mon, 10 Jan 2022 00:22:38 +0000 (18:22 -0600)]
Combine internal features in clippy_lints

2 years agoCombine internal features in clippy_utils
Cameron Steffen [Mon, 10 Jan 2022 00:16:05 +0000 (18:16 -0600)]
Combine internal features in clippy_utils

2 years agoAuto merge of #8236 - PatchMixolydic:single_char_lifetime_names, r=llogiq
bors [Sun, 9 Jan 2022 14:27:36 +0000 (14:27 +0000)]
Auto merge of #8236 - PatchMixolydic:single_char_lifetime_names, r=llogiq

new lint: `single_char_lifetime_names`

This pull request adds a lint against single character lifetime names, as they might not divulge enough information about the purpose of the lifetime. This can make code harder to understand. I placed this in `restriction` rather than `pedantic` (as suggested in #8233) since most of the Rust ecosystem already uses single character lifetime names (to my knowledge, at least) and since single character lifetime names aren't incorrect. I'd be happy to change this upon request, however. Fixes #8233.

- [x] Followed lint naming conventions
- [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`

changelog: new lint: [`single_char_lifetime_names`]

2 years agonew lint: `single_char_lifetime_names`
bors [Sun, 9 Jan 2022 14:27:36 +0000 (14:27 +0000)]
new lint: `single_char_lifetime_names`

This pull request adds a lint against single character lifetime names, as they might not divulge enough information about the purpose of the lifetime. This can make code harder to understand. I placed this in `restriction` rather than `pedantic` (as suggested in #8233) since most of the Rust ecosystem already uses single character lifetime names (to my knowledge, at least) and since single character lifetime names aren't incorrect. I'd be happy to change this upon request, however. Fixes #8233.

- [x] Followed lint naming conventions
- [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`

changelog: new lint: [`single_char_lifetime_names`]

2 years agocover trait for `trait_duplication_in_bounds`
dswij [Thu, 6 Jan 2022 10:43:44 +0000 (18:43 +0800)]
cover trait for `trait_duplication_in_bounds`

2 years agorustc_metadata: Rename `item_children(_untracked)` to `module_children(_untracked)`
Vadim Petrochenkov [Thu, 23 Dec 2021 08:12:34 +0000 (16:12 +0800)]
rustc_metadata: Rename `item_children(_untracked)` to `module_children(_untracked)`

And `each_child_of_item` to `for_each_module_child`

2 years agorustc_metadata: Optimize and document module children decoding
Vadim Petrochenkov [Sat, 18 Dec 2021 12:07:58 +0000 (20:07 +0800)]
rustc_metadata: Optimize and document module children decoding

2 years agoAuto merge of #8249 - sourcefrog:depinfo, r=Manishearth
bors [Sun, 9 Jan 2022 00:19:19 +0000 (00:19 +0000)]
Auto merge of #8249 - sourcefrog:depinfo, r=Manishearth

Set binary-dep-depinfo in .cargo/config.toml

Fixes #8248

According to https://doc.rust-lang.org/cargo/reference/unstable this
seems to be the right place to set it, and it does fix the build for me.

I haven't removed the other `rustflags` because perhaps it's needed on
different cargo/rust versions?

---

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

changelog: none

2 years agoSet binary-dep-depinfo in .cargo/config.toml
Martin Pool [Sat, 8 Jan 2022 22:12:53 +0000 (14:12 -0800)]
Set binary-dep-depinfo in .cargo/config.toml

Fixes #8248

According to https://doc.rust-lang.org/cargo/reference/unstable this
seems to be the right place to set it, and it does fix the build for me.

I haven't removed the other `rustflags` because perhaps it's needed on
different cargo/rust versions?

2 years agoAuto merge of #8201 - smoelius:master, r=camsteffen
bors [Sat, 8 Jan 2022 16:33:48 +0000 (16:33 +0000)]
Auto merge of #8201 - smoelius:master, r=camsteffen

Change `unnecessary_to_owned` `into_iter` suggestions to `MaybeIncorrect`

I am having a hard time finding a good solution for #8148, so I am wondering if is enough to just change the suggestion's applicability to `MaybeIncorrect`?

I apologize, as I realize this is a bit of a cop out.

changelog: none

2 years agoAdd `unnecessary_to_owned` "Known problems" section
Samuel E. Moelius III [Sat, 8 Jan 2022 14:09:52 +0000 (09:09 -0500)]
Add `unnecessary_to_owned` "Known problems" section

2 years agoUpdate clippy for associated item changes
Matthew Jasper [Thu, 18 Nov 2021 22:33:49 +0000 (22:33 +0000)]
Update clippy for associated item changes

2 years agoAuto merge of #8234 - Alexendoo:lintcheck-allow-renamed-dir, r=xFrednet
bors [Fri, 7 Jan 2022 20:31:24 +0000 (20:31 +0000)]
Auto merge of #8234 - Alexendoo:lintcheck-allow-renamed-dir, r=xFrednet

Allow running lintcheck with a renamed rust-clippy dir

I have Clippy checked out in `rust/clippy` rather than `rust/rust-clippy`, this allows lintcheck to still run in that case

changelog: none

2 years agoAllow running lintcheck with a renamed rust-clippy dir
Alex Macleod [Thu, 6 Jan 2022 13:06:24 +0000 (13:06 +0000)]
Allow running lintcheck with a renamed rust-clippy dir

2 years agoHandle type projections in `iter_not_returning_iterator`
Jason Newcomb [Wed, 5 Jan 2022 18:57:45 +0000 (13:57 -0500)]
Handle type projections in `iter_not_returning_iterator`

2 years agoLint `iter_not_returning_iterator` on the trait definition rather than the implementation
Jason Newcomb [Wed, 5 Jan 2022 18:46:35 +0000 (13:46 -0500)]
Lint `iter_not_returning_iterator` on the trait definition rather than the implementation

2 years agoSuggest `copy_from_slice` for `manual_memcpy` when possible
Jason Newcomb [Wed, 5 Jan 2022 17:35:35 +0000 (12:35 -0500)]
Suggest `copy_from_slice` for `manual_memcpy` when possible

2 years agoDon't lint `DequeVec` in `manual_memcpy`
Jason Newcomb [Wed, 5 Jan 2022 17:15:10 +0000 (12:15 -0500)]
Don't lint `DequeVec` in `manual_memcpy`

2 years agoChange `unnecessary_to_owned` `into_iter` suggestions to `MaybeIncorrect`
Samuel E. Moelius III [Thu, 30 Dec 2021 23:43:34 +0000 (18:43 -0500)]
Change `unnecessary_to_owned` `into_iter` suggestions to `MaybeIncorrect`

2 years agoAuto merge of #8221 - Jarcho:while_let_on_iterator_8113, r=llogiq
bors [Wed, 5 Jan 2022 06:45:58 +0000 (06:45 +0000)]
Auto merge of #8221 - Jarcho:while_let_on_iterator_8113, r=llogiq

Better detect when a field can be moved from in `while_let_on_iterator`

fixes #8113

changelog: Better detect when a field can be moved from in `while_let_on_iterator`

2 years agoAuto merge of #8224 - Jarcho:type_repetition_in_bounds_8162, r=llogiq
bors [Wed, 5 Jan 2022 01:05:18 +0000 (01:05 +0000)]
Auto merge of #8224 - Jarcho:type_repetition_in_bounds_8162, r=llogiq

Fix `type_repetition_in_bounds`

fixes #7360
fixes #8162
fixes #8056

changelog: Check for full equality in `type_repetition_in_bounds` rather than just equal hashes

2 years agoAuto merge of #8223 - camsteffen:remove-in-macro, r=llogiq
bors [Wed, 5 Jan 2022 00:49:23 +0000 (00:49 +0000)]
Auto merge of #8223 - camsteffen:remove-in-macro, r=llogiq

Remove in_macro from clippy_utils

changelog: none

Previously done in #7897 but reverted in #8170. I'd like to keep `in_macro` out of utils because if a span is from expansion in any way (desugaring or macro), we should not proceed without understanding the nature of the expansion IMO.

r? `@llogiq`

2 years agoAuto merge of #8219 - camsteffen:macro-decoupling, r=llogiq
bors [Tue, 4 Jan 2022 22:32:02 +0000 (22:32 +0000)]
Auto merge of #8219 - camsteffen:macro-decoupling, r=llogiq

New macro utils

changelog: none

Sorry, this is a big one. A lot of interrelated changes and I wanted to put the new utils to use to make sure they are somewhat battle-tested. We may want to divide some of the lint-specific refactoring commits into batches for smaller reviewing tasks. I could also split into more PRs.

Introduces a bunch of new utils at `clippy_utils::macros::...`. Please read through the docs and give any feedback! I'm happy to introduce `MacroCall` and various functions to retrieve an instance. It feels like the missing puzzle piece. I'm also introducing `ExpnId` from rustc as "useful for Clippy too". `@rust-lang/clippy`

Fixes #7843 by not parsing every node of macro implementations, at least the major offenders.

I probably want to get rid of `is_expn_of` at some point.

2 years agoNew macro utils
bors [Tue, 4 Jan 2022 22:32:02 +0000 (22:32 +0000)]
New macro utils

changelog: none

Sorry, this is a big one. A lot of interrelated changes and I wanted to put the new utils to use to make sure they are somewhat battle-tested. We may want to divide some of the lint-specific refactoring commits into batches for smaller reviewing tasks. I could also split into more PRs.

Introduces a bunch of new utils at `clippy_utils::macros::...`. Please read through the docs and give any feedback! I'm happy to introduce `MacroCall` and various functions to retrieve an instance. It feels like the missing puzzle piece. I'm also introducing `ExpnId` from rustc as "useful for Clippy too". `@rust-lang/clippy`

Fixes #7843 by not parsing every node of macro implementations, at least the major offenders.

I probably want to get rid of `is_expn_of` at some point.

2 years agoRollup merge of #91907 - lcnr:const-arg-infer, r=BoxyUwU
Matthias Krüger [Tue, 4 Jan 2022 20:23:06 +0000 (21:23 +0100)]
Rollup merge of #91907 - lcnr:const-arg-infer, r=BoxyUwU

Allow `_` as the length of array types and repeat expressions

r? `@BoxyUwU` cc `@varkor`

2 years agoCheck for full equality in `type_repetition_in_bounds` rather than just equal hashes
Jason Newcomb [Tue, 4 Jan 2022 19:20:27 +0000 (14:20 -0500)]
Check for full equality in `type_repetition_in_bounds` rather than just equal hashes

2 years agoAuto merge of #8220 - Jarcho:manual_swap_8154, r=camsteffen
bors [Tue, 4 Jan 2022 18:23:39 +0000 (18:23 +0000)]
Auto merge of #8220 - Jarcho:manual_swap_8154, r=camsteffen

Consider auto-deref when linting `manual_swap`

fixes #8154

changelog: Don't lint `manual_swap` when a field access involves auto-deref

2 years agoConsider auto-deref when linting `manual_swap`
Jason Newcomb [Tue, 4 Jan 2022 03:13:52 +0000 (22:13 -0500)]
Consider auto-deref when linting `manual_swap`

2 years agoRemove in_macro from utils
Cameron Steffen [Tue, 4 Jan 2022 17:58:39 +0000 (11:58 -0600)]
Remove in_macro from utils

2 years agoBetter detect when a field can be moved from in `while_let_on_iterator`
Jason Newcomb [Tue, 4 Jan 2022 04:13:31 +0000 (23:13 -0500)]
Better detect when a field can be moved from in `while_let_on_iterator`

2 years agoAuto merge of #8216 - pmnoxx:piotr-fix-clippy-warnings, r=xFrednet
bors [Mon, 3 Jan 2022 16:54:39 +0000 (16:54 +0000)]
Auto merge of #8216 - pmnoxx:piotr-fix-clippy-warnings, r=xFrednet

Fix `clippy::use-self`` warning in ` src/main.rs`

`ClippyCmd` warnings gets generated due to addition of `clippy::use-self`. This PR fixes that.

```
warning: unnecessary structure name repetition
  --> src/main.rs:99:9
   |
99 |         ClippyCmd {
   |         ^^^^^^^^^ help: use the applicable keyword: `Self`
   |
   = note: `-W clippy::use-self` implied by `-W clippy::nursery`
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#use_self
```

---

changelog: none

2 years agoFix clippy warnings
Piotr Mikulski [Mon, 3 Jan 2022 14:11:11 +0000 (06:11 -0800)]
Fix clippy warnings

2 years agoRollup merge of #90102 - nbdd0121:box3, r=jonas-schievink
Matthias Krüger [Mon, 3 Jan 2022 13:44:15 +0000 (14:44 +0100)]
Rollup merge of #90102 - nbdd0121:box3, r=jonas-schievink

Remove `NullOp::Box`

Follow up of #89030 and MCP rust-lang/compiler-team#460.

~1 month later nothing seems to be broken, apart from a small regression that #89332 (1aac85bb716c09304b313d69d30d74fe7e8e1a8e) shows could be regained by remvoing the diverging path, so it shall be safe to continue and remove `NullOp::Box` completely.

r? `@jonas-schievink`
`@rustbot` label T-compiler

2 years agoAuto merge of #8204 - wigy-opensource-developer:fix-7210, r=xFrednet
bors [Sun, 2 Jan 2022 18:50:44 +0000 (18:50 +0000)]
Auto merge of #8204 - wigy-opensource-developer:fix-7210, r=xFrednet

[`erasing_op`] lint ignored when operation `Output` type is different from the type of constant `0`

fixes #7210

changelog: [`erasing_op`] lint ignored when operation `Output` type is different from the type of constant `0`

2 years agoerasing_op lint ignored when output type is different from the non-const one
Wigy [Fri, 31 Dec 2021 08:37:39 +0000 (09:37 +0100)]
erasing_op lint ignored when output type is different from the non-const one

2 years agoAuto merge of #8208 - nmathewson:selfkind_no_fix, r=xFrednet
bors [Sun, 2 Jan 2022 17:14:18 +0000 (17:14 +0000)]
Auto merge of #8208 - nmathewson:selfkind_no_fix, r=xFrednet

wrong_self_convention: Match `SelfKind::No` more restrictively

The `wrong_self_convention` lint uses a `SelfKind` type to decide
whether a method has the right kind of "self" for its name, or whether
the kind of "self" it has makes its name confusable for a method in
a common trait.  One possibility is `SelfKind::No`, which is supposed
to mean "No `self`".

Previously, SelfKind::No matched everything _except_ Self, including
references to Self.  This patch changes it to match Self, &Self, &mut
Self, Box<Self>, and so on.

For example, this kind of method was allowed before:

```
impl S {
    // Should trigger the lint, because
    // "methods called `is_*` usually take `self` by reference or no `self`"
    fn is_foo(&mut self) -> bool { todo!() }
}
```

But since SelfKind::No matched "&mut self", no lint was triggered
(see #8142).

With this patch, the code above now gives a lint as expected.

fixes #8142

changelog: [`wrong_self_convention`] rejects `self` references in more cases

2 years agoAuto merge of #8209 - xFrednet:8197-mention-attribute-on-struct, r=llogiq
bors [Sat, 1 Jan 2022 13:16:49 +0000 (13:16 +0000)]
Auto merge of #8209 - xFrednet:8197-mention-attribute-on-struct, r=llogiq

return_self_not_must_use document `#[must_use]` on the type

Inspired by a discussion in rust-lang/rust-clippy#8197

---

r? `@llogiq`

changelog: none

The lint is this on nightly, therefore no changelog entry for you xD

2 years agoreturn_self_not_must_use document `#[must_use]` on the type
bors [Sat, 1 Jan 2022 13:16:49 +0000 (13:16 +0000)]
return_self_not_must_use document `#[must_use]` on the type

Inspired by a discussion in rust-lang/rust-clippy#8197

---

r? `@llogiq`

changelog: none

The lint is this on nightly, therefore no changelog entry for you xD

2 years agoMake tidy check for magic numbers that spell things
Josh Triplett [Sat, 1 Jan 2022 05:13:07 +0000 (21:13 -0800)]
Make tidy check for magic numbers that spell things

Remove existing problematic cases.

2 years agowrong_self_convention: Match `SelfKind::No` more restrictively
Nick Mathewson [Sat, 1 Jan 2022 04:39:40 +0000 (23:39 -0500)]
wrong_self_convention: Match `SelfKind::No` more restrictively

The `wrong_self_convention` lint uses a `SelfKind` type to decide
whether a method has the right kind of "self" for its name, or whether
the kind of "self" it has makes its name confusable for a method in
a common trait.  One possibility is `SelfKind::No`, which is supposed
to mean "No `self`".

Previously, SelfKind::No matched everything _except_ Self, including
references to Self.  This patch changes it to match Self, &Self, &mut
Self, Box<Self>, and so on.

For example, this kind of method was allowed before:

```
impl S {
    // Should trigger the lint, because
    // "methods called `is_*` usually take `self` by reference or no `self`"
    fn is_foo(&mut self) -> bool { todo!() }
}
```

But since SelfKind::No matched "&mut self", no lint was triggered
(see #8142).

With this patch, the code above now gives a lint as expected.

Fixes #8142

changelog: [`wrong_self_convention`] rejects `self` references in more cases

2 years agoAuto merge of #8193 - ebobrow:redundant_closure_fp, r=Manishearth
bors [Fri, 31 Dec 2021 19:01:42 +0000 (19:01 +0000)]
Auto merge of #8193 - ebobrow:redundant_closure_fp, r=Manishearth

fix [`redundant_closure`] fp with `Rc<F>`/`Arc<F>`

fixes #8073

changelog: don't trigger [`redundant_closure`] on `Arc<F>` or `Rc<F>`

2 years agoAuto merge of #8179 - nmathewson:unused_async_io_amount, r=xFrednet
bors [Fri, 31 Dec 2021 17:36:04 +0000 (17:36 +0000)]
Auto merge of #8179 - nmathewson:unused_async_io_amount, r=xFrednet

Extend unused_io_amount to cover async io.

Clippy helpfully warns about code like this, telling you that you
probably meant "write_all":

    fn say_hi<W:Write>(w: &mut W) {
       w.write(b"hello").unwrap();
    }

This patch attempts to extend the lint so it also covers this
case:

    async fn say_hi<W:AsyncWrite>(w: &mut W) {
       w.write(b"hello").await.unwrap();
    }

(I've run into this second case several times in my own programming,
and so have my coworkers, so unless we're especially accident-prone
in this area, it's probably worth addressing?)

Since this is my first attempt at a clippy patch, I've probably
made all kinds of mistakes: please help me fix them?  I'd like
to learn more here.

Open questions I have:

  * Should this be a separate lint from unused_io_amount?  Maybe
    unused_async_io_amount?  If so, how should I structure their
    shared code?
  * Should this cover tokio's AsyncWrite too?
  * Is it okay to write lints for stuff that isn't part of
    the standard library?  I see that "regex" also has lints,
    and I figure that "futures" is probably okay too, since it's
    an official rust-lang repository.
  * What other tests are needed?
  * How should I improve the code?

Thanks for your time!

---

changelog: [`unused_io_amount`] now supports async read and write traits

2 years agounused_io_amount: Use span_lint_and_help.
Nick Mathewson [Fri, 31 Dec 2021 17:20:02 +0000 (12:20 -0500)]
unused_io_amount: Use span_lint_and_help.

This improves the quality of the genrated output and makes it
more in line with other lint messages.

changelog: [`unused_io_amount`]: Improve help text

2 years agoExtend [`unused_io_amount`] to cover AsyncRead and AsyncWrite.
Nick Mathewson [Mon, 27 Dec 2021 16:17:17 +0000 (11:17 -0500)]
Extend [`unused_io_amount`] to cover AsyncRead and AsyncWrite.

Clippy helpfully warns about code like this, telling you that you
probably meant "write_all":

    fn say_hi<W:Write>(w: &mut W) {
       w.write(b"hello").unwrap();
    }

This patch attempts to extend the lint so it also covers this
case:

    async fn say_hi<W:AsyncWrite>(w: &mut W) {
       w.write(b"hello").await.unwrap();
    }

(I've run into this second case several times in my own programming,
and so have my coworkers, so unless we're especially accident-prone
in this area, it's probably worth addressing?)

This patch covers the Async{Read,Write}Ext traits in futures-rs,
and in tokio, since both are quite widely used.

changelog: [`unused_io_amount`] now supports AsyncReadExt and AsyncWriteExt.

2 years agoAuto merge of #92252 - GuillaumeGomez:update-pulldown, r=camelid,xFrednet
bors [Fri, 31 Dec 2021 12:46:38 +0000 (12:46 +0000)]
Auto merge of #92252 - GuillaumeGomez:update-pulldown, r=camelid,xFrednet

Update pulldown-cmark version to 0.9

Fixes https://github.com/rust-lang/rust/issues/92206.

r? `@camelid`

2 years agoRemove method_call! macro
Cameron Steffen [Thu, 30 Dec 2021 19:37:14 +0000 (13:37 -0600)]
Remove method_call! macro

2 years agoMerge commit '0eff589afc83e21a03a168497bbab6b4dfbb4ef6' into clippyup
flip1995 [Thu, 30 Dec 2021 14:10:43 +0000 (15:10 +0100)]
Merge commit '0eff589afc83e21a03a168497bbab6b4dfbb4ef6' into clippyup

2 years agoAuto merge of #8196 - flip1995:rustup, r=flip1995
bors [Thu, 30 Dec 2021 13:22:47 +0000 (13:22 +0000)]
Auto merge of #8196 - flip1995:rustup, r=flip1995

Rustup

r? `@ghost`

changelog: none

2 years agoBump nightly version -> 2021-12-30
flip1995 [Thu, 30 Dec 2021 13:18:01 +0000 (14:18 +0100)]
Bump nightly version -> 2021-12-30

2 years agoMerge remote-tracking branch 'upstream/master' into rustup
flip1995 [Thu, 30 Dec 2021 13:04:13 +0000 (14:04 +0100)]
Merge remote-tracking branch 'upstream/master' into rustup

2 years agofix [`redundant_closure`] fp with `Arc`
Elliot Bobrow [Wed, 29 Dec 2021 16:52:40 +0000 (08:52 -0800)]
fix [`redundant_closure`] fp with `Arc`

2 years agoAuto merge of #8117 - hotate29:issue7320, r=camsteffen
bors [Tue, 28 Dec 2021 22:15:53 +0000 (22:15 +0000)]
Auto merge of #8117 - hotate29:issue7320, r=camsteffen

update: ```Sugg::not()``` replacing the comparison operator. #7320

fixes #7320

changelog: ```needless_bool```: Changed to make a smart suggestion.