]> git.lizzy.rs Git - rust.git/log
rust.git
2 years agoAuto merge of #8547 - Jarcho:transmute_8501, r=flip1995
bors [Wed, 16 Mar 2022 09:39:22 +0000 (09:39 +0000)]
Auto merge of #8547 - Jarcho:transmute_8501, r=flip1995

More `transmute_undefined_repr` fixes

fixes: #8498
fixes: #8501
fixes: #8503

changelog: Allow `transumte_undefined_repr` between fat pointers and `(usize, usize)`
changelog: Allow `transumte_undefined_repr` when one side is a union
changelog: Fix `transumte_undefined_repr` on tuples with one non-zero-sized type.

2 years agoAuto merge of #8546 - KisaragiEffective:patch-1, r=llogiq
bors [Wed, 16 Mar 2022 06:20:45 +0000 (06:20 +0000)]
Auto merge of #8546 - KisaragiEffective:patch-1, r=llogiq

[`collapsible_if`] fix typo in code-block kind specifier

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

changelog: [`collapsible_if`] fix typo in code-block kind specifier

2 years agoFix checking transmutes with adjusted types
Jason Newcomb [Wed, 16 Mar 2022 02:47:18 +0000 (22:47 -0400)]
Fix checking transmutes with adjusted types

2 years agoDon't lint `transmute_undefined_repr` on unions.
Jason Newcomb [Wed, 16 Mar 2022 02:38:15 +0000 (22:38 -0400)]
Don't lint `transmute_undefined_repr` on unions.

2 years agoSmall simplification to `transmute_undefined_repr`
Jason Newcomb [Wed, 16 Mar 2022 02:33:26 +0000 (22:33 -0400)]
Small simplification to `transmute_undefined_repr`

2 years agoDon't lint fat pointer to `(usize, usize)` conversion in `transmute_undefined_repr`
Jason Newcomb [Wed, 16 Mar 2022 02:31:07 +0000 (22:31 -0400)]
Don't lint fat pointer to `(usize, usize)` conversion in `transmute_undefined_repr`

2 years agoFix `transmute_undefined_repr` for single element tuples
Jason Newcomb [Wed, 16 Mar 2022 01:51:07 +0000 (21:51 -0400)]
Fix `transmute_undefined_repr` for single element tuples

2 years agofix typo in code-block kind specifier
Kisaragi [Wed, 16 Mar 2022 01:19:19 +0000 (10:19 +0900)]
fix typo in code-block kind specifier

2 years agofix typo in code-block kind specifier
Kisaragi [Tue, 15 Mar 2022 23:50:30 +0000 (08:50 +0900)]
fix typo in code-block kind specifier

2 years agoAuto merge of #8541 - flip1995:iter_with_drain_ambulance, r=giraffate
bors [Tue, 15 Mar 2022 09:02:38 +0000 (09:02 +0000)]
Auto merge of #8541 - flip1995:iter_with_drain_ambulance, r=giraffate

Move iter_with_drain to nursery

cc #8538 #8539

r? `@giraffate`

changelog: Move [`iter_with_drain`] to nursery

2 years agoMove iter_with_drain to nursery
flip1995 [Tue, 15 Mar 2022 08:46:49 +0000 (09:46 +0100)]
Move iter_with_drain to nursery

2 years agoAuto merge of #8509 - smoelius:fix-8507, r=giraffate
bors [Tue, 15 Mar 2022 01:08:47 +0000 (01:08 +0000)]
Auto merge of #8509 - smoelius:fix-8507, r=giraffate

Fix `unncessary_to_owned` false positive

Fix #8507

changelog: none

2 years agoAuto merge of #8537 - xFrednet:7923-single-component-path-imports-for-macros, r=llogiq
bors [Mon, 14 Mar 2022 23:39:50 +0000 (23:39 +0000)]
Auto merge of #8537 - xFrednet:7923-single-component-path-imports-for-macros, r=llogiq

Allow `single_component_path_imports` for all macros

Closes: https://github.com/rust-lang/rust-clippy/issues/7923
It can be useful to have `use macro_name` regardless of the visibility. This removes the visibility filter.

changelog: [`single_component_path_imports`]: no longer triggers on macros

2 years agoAuto merge of #8536 - xFrednet:8062-applicability-search-is-some, r=camsteffen
bors [Mon, 14 Mar 2022 22:12:25 +0000 (22:12 +0000)]
Auto merge of #8536 - xFrednet:8062-applicability-search-is-some, r=camsteffen

Make `search_is_some`s suggestion `MachineApplicable`

My biggest PR to date, about 0.3 Lines have been changed!

Closes https://github.com/rust-lang/rust-clippy/issues/8062

The suggestion seems to work well, as we've received no error reports since the implementation in December. This PR therefore promotes the suggestion to `MachineApplicable`. The tests already include `.fixed` files :)

changelog: [`search_is_some`]: Make more suggestions `MachineApplicable`

2 years agoAllow `single_component_path_imports` for all macros
xFrednet [Mon, 14 Mar 2022 21:39:36 +0000 (22:39 +0100)]
Allow `single_component_path_imports` for all macros

2 years agoMake `search_is_some`s suggestion `MachineApplicable`
xFrednet [Mon, 14 Mar 2022 21:02:10 +0000 (22:02 +0100)]
Make `search_is_some`s suggestion `MachineApplicable`

2 years agoAuto merge of #8534 - flip1995:rustup, r=flip1995
bors [Mon, 14 Mar 2022 10:34:17 +0000 (10:34 +0000)]
Auto merge of #8534 - flip1995:rustup, r=flip1995

Rustup

r? `@ghost`

changelog: none

2 years agoBump nightly version -> 2022-03-14
flip1995 [Mon, 14 Mar 2022 10:29:39 +0000 (11:29 +0100)]
Bump nightly version -> 2022-03-14

2 years agoMerge remote-tracking branch 'upstream/master' into rustup
flip1995 [Mon, 14 Mar 2022 10:29:18 +0000 (11:29 +0100)]
Merge remote-tracking branch 'upstream/master' into rustup

2 years agoAuto merge of #8422 - buttercrab:only_used_in_recursion, r=llogiq
bors [Sun, 13 Mar 2022 16:11:25 +0000 (16:11 +0000)]
Auto merge of #8422 - buttercrab:only_used_in_recursion, r=llogiq

new lint: `only_used_in_recursion`

changed:
- added `only_used_in_recursion`.
- fixed code that variables are only used in recursion.
- this would not lint when `unused_variable`

This fixes: #8390

-----

changelog: add lint [`only_used_in_recursion`]

2 years agoadd clearing return vars
Jaeyong Sung [Sun, 13 Mar 2022 15:13:57 +0000 (00:13 +0900)]
add clearing return vars

2 years agoAuto merge of #8471 - J-ZhengLi:master-issue7040, r=llogiq
bors [Sun, 13 Mar 2022 14:49:56 +0000 (14:49 +0000)]
Auto merge of #8471 - J-ZhengLi:master-issue7040, r=llogiq

new lint that detects useless match expression

fixes #7040

changelog: Add new  lint [`needless_match`] under complexity lint group

2 years agoImprove `AdtDef` interning.
Nicholas Nethercote [Fri, 4 Mar 2022 20:28:41 +0000 (07:28 +1100)]
Improve `AdtDef` interning.

This commit makes `AdtDef` use `Interned`. Much the commit is tedious
changes to introduce getter functions. The interesting changes are in
`compiler/rustc_middle/src/ty/adt.rs`.

2 years agoremove parameters that are only used in recursion
Jaeyong Sung [Thu, 10 Mar 2022 07:06:35 +0000 (16:06 +0900)]
remove parameters that are only used in recursion

2 years agofix build error
Jaeyong Sung [Thu, 10 Mar 2022 06:53:53 +0000 (15:53 +0900)]
fix build error

2 years agoadd checking for `x -> x` and `ref x -> x` and related test cases.
J-ZhengLi [Thu, 10 Mar 2022 06:46:58 +0000 (14:46 +0800)]
add checking for `x -> x` and `ref x -> x` and related test cases.

2 years agofix to lint Self::function
Jaeyong Sung [Thu, 10 Mar 2022 06:46:40 +0000 (15:46 +0900)]
fix to lint Self::function

2 years agoAuto merge of #8070 - CrazyRoka:update-gh-pages-checkbox-styles, r=camsteffen
bors [Thu, 10 Mar 2022 03:08:34 +0000 (03:08 +0000)]
Auto merge of #8070 - CrazyRoka:update-gh-pages-checkbox-styles, r=camsteffen

Improve styles of filtering options for Clippy's lint list

Partially solves #7958

Updated styles for filtering options. It now uses dropdown menus.

![image](https://user-images.githubusercontent.com/19844144/144608479-cdd9de0b-f101-4d49-a135-0969efb01a11.png)

changelog: none

2 years agorename lint to `needless_match`
J-ZhengLi [Thu, 10 Mar 2022 01:44:25 +0000 (09:44 +0800)]
rename lint to `needless_match`
and change its lint group to "complexity"

2 years agoadd `#[rustc_pass_by_value]` to more types
lcnr [Tue, 8 Mar 2022 14:39:52 +0000 (15:39 +0100)]
add `#[rustc_pass_by_value]` to more types

2 years agofix a bug that caused internal test fail
J-ZhengLi [Tue, 8 Mar 2022 10:15:11 +0000 (18:15 +0800)]
fix a bug that caused internal test fail

2 years agoadd nop if-let expression check.
J-ZhengLi [Tue, 8 Mar 2022 09:37:53 +0000 (17:37 +0800)]
add nop if-let expression check.
re-design test cases as some of them are not worth the effort to check.

2 years agoAuto merge of #94706 - matthiaskrgr:rollup-l5erynr, r=matthiaskrgr
bors [Mon, 7 Mar 2022 18:06:31 +0000 (18:06 +0000)]
Auto merge of #94706 - matthiaskrgr:rollup-l5erynr, r=matthiaskrgr

Rollup of 4 pull requests

Successful merges:

 - #93350 (libunwind: readd link attrs to _Unwind_Backtrace)
 - #93827 (Stabilize const_fn_fn_ptr_basics, const_fn_trait_bound, and const_impl_trait)
 - #94696 (Remove whitespaces and use CSS to align line numbers to the right instead)
 - #94700 (rustdoc: Update minifier version)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup

2 years agoUpdate and fix clippy tests
Eric Holk [Fri, 11 Feb 2022 03:23:43 +0000 (19:23 -0800)]
Update and fix clippy tests

2 years agoStabilize const_fn_fn_ptr_basics and const_fn_trait_bound
Eric Holk [Wed, 9 Feb 2022 00:33:15 +0000 (16:33 -0800)]
Stabilize const_fn_fn_ptr_basics and const_fn_trait_bound

2 years agoadd basic code to check nop match blocks
J-ZhengLi [Mon, 7 Mar 2022 10:12:35 +0000 (18:12 +0800)]
add basic code to check nop match blocks
modify `manual_map_option` uitest because one test case has confliction.

2 years agoadd test for trait recursion
Jaeyong Sung [Mon, 7 Mar 2022 03:15:00 +0000 (12:15 +0900)]
add test for trait recursion

2 years agoClarify `Layout` interning.
Nicholas Nethercote [Fri, 4 Mar 2022 02:46:56 +0000 (13:46 +1100)]
Clarify `Layout` interning.

`Layout` is another type that is sometimes interned, sometimes not, and
we always use references to refer to it so we can't take any advantage
of the uniqueness properties for hashing or equality checks.

This commit renames `Layout` as `LayoutS`, and then introduces a new
`Layout` that is a newtype around an `Interned<LayoutS>`. It also
interns more layouts than before. Previously layouts within layouts
(via the `variants` field) were never interned, but now they are. Hence
the lifetime on the new `Layout` type.

Unlike other interned types, these ones are in `rustc_target` instead of
`rustc_middle`. This reflects the existing structure of the code, which
does layout-specific stuff in `rustc_target` while `TyAndLayout` is
generic over the `Ty`, allowing the type-specific stuff to occur in
`rustc_middle`.

The commit also adds a `HashStable` impl for `Interned`, which was
needed. It hashes the contents, unlike the `Hash` impl which hashes the
pointer.

2 years agoIntroduce `ConstAllocation`.
Nicholas Nethercote [Tue, 1 Mar 2022 20:15:04 +0000 (07:15 +1100)]
Introduce `ConstAllocation`.

Currently some `Allocation`s are interned, some are not, and it's very
hard to tell at a use point which is which.

This commit introduces `ConstAllocation` for the known-interned ones,
which makes the division much clearer. `ConstAllocation::inner()` is
used to get the underlying `Allocation`.

In some places it's natural to use an `Allocation`, in some it's natural
to use a `ConstAllocation`, and in some places there's no clear choice.
I've tried to make things look as nice as possible, while generally
favouring `ConstAllocation`, which is the type that embodies more
information. This does require quite a few calls to `inner()`.

The commit also tweaks how `PartialOrd` works for `Interned`. The
previous code was too clever by half, building on `T: Ord` to make the
code shorter. That caused problems with deriving `PartialOrd` and `Ord`
for `ConstAllocation`, so I changed it to build on `T: PartialOrd`,
which is slightly more verbose but much more standard and avoided the
problems.

2 years agoRollup merge of #94617 - pierwill:update-itertools, r=Mark-Simulacrum
Matthias Krüger [Sun, 6 Mar 2022 14:41:26 +0000 (15:41 +0100)]
Rollup merge of #94617 - pierwill:update-itertools, r=Mark-Simulacrum

Update `itertools`

Update to 0.10.1

2 years agoAuto merge of #8445 - asquared31415:slice_ptr_cast, r=llogiq
bors [Sun, 6 Mar 2022 07:46:56 +0000 (07:46 +0000)]
Auto merge of #8445 - asquared31415:slice_ptr_cast, r=llogiq

Llint for casting between raw slice pointers with different element sizes

This lint disallows using `as` to convert from a raw pointer to a slice (e.g. `*const [i32]`, `*mut [Foo]`) to any other raw pointer to a slice if the element types have different sizes.  When a raw slice pointer is cast, the data pointer and count metadata are preserved.  This means that when the size of the inner slice's element type changes, the total number of bytes pointed to by the count changes.  For example a `*const [i32]` with length 4 (four `i32` elements) is cast `as *const [u8]` the resulting pointer points to four `u8` elements at the same address, losing most of the data.  When the size *increases* the resulting pointer will point to *more* data, and accessing that data will be UB.

On its own, *producing* the pointer isn't actually a problem, but because any use of the pointer as a slice will either produce surprising behavior or cause UB I believe this is a correctness lint.  If the pointer is not intended to be used as a slice, the user should instead use any of a number of methods to produce just a data pointer including an `as` cast to a thin pointer (e.g. `p as *const i32`) or if the pointer is being created from a slice, the `as_ptr` method on slices.  Detecting the intended use of the pointer is outside the scope of this lint, but I believe this lint will also lead users to realize that a slice pointer is only for slices.

There is an exception to this lint when either of the slice element types are zero sized (e.g `*mut [()]`).  The total number of bytes pointed to by the slice with a zero sized element is zero.  In that case preserving the length metadata is likely intended as a workaround to get the length metadata of a slice pointer though a zero sized slice.

The lint does not forbid casting pointers to slices with the *same* element size as the cast was likely intended to reinterpret the data in the slice as some equivalently sized data and the resulting pointer will behave as intended.

---

changelog: Added ``[`cast_slice_different_sizes`]``, a lint that disallows using `as`-casts to convert between raw pointers to slices when the elements have different sizes.

2 years agoFix #8507
Samuel E. Moelius III [Sun, 6 Mar 2022 02:18:44 +0000 (21:18 -0500)]
Fix #8507

2 years agoFormat with `rustfmt_if_chain`
Samuel E. Moelius III [Sat, 5 Mar 2022 23:35:58 +0000 (18:35 -0500)]
Format with `rustfmt_if_chain`

2 years agoChange syntax for TyAlias where clauses
Jack Huey [Tue, 19 Oct 2021 22:45:48 +0000 (18:45 -0400)]
Change syntax for TyAlias where clauses

2 years agofix lint errors
Jaeyong Sung [Sat, 5 Mar 2022 12:49:36 +0000 (21:49 +0900)]
fix lint errors

2 years agodon't lint when implementing trait
Jaeyong Sung [Sat, 5 Mar 2022 12:39:00 +0000 (21:39 +0900)]
don't lint when implementing trait

2 years agoDo not point at whole file missing `fn main`
Esteban Kuber [Fri, 21 Jan 2022 00:15:39 +0000 (00:15 +0000)]
Do not point at whole file missing `fn main`

Only point at the end of the crate. We could try making it point at the
beginning of the crate, but that is confused with `DUMMY_SP`, causing
the output to be *worse*.

This change will make it so that VSCode will *not* underline the whole
file when `main` is missing, so other errors will be visible.

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 agolint for casting raw pointers to slices with different element sizes
asquared31415 [Fri, 18 Feb 2022 10:17:07 +0000 (05:17 -0500)]
lint for casting raw pointers to slices with different element sizes

2 years agoUpdate `itertools`
pierwill [Fri, 4 Mar 2022 17:54:28 +0000 (11:54 -0600)]
Update `itertools`

Update to 0.10.1

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 #94512 - RalfJung:sdiv-ub, r=oli-obk
bors [Thu, 3 Mar 2022 12:56:24 +0000 (12:56 +0000)]
Auto merge of #94512 - RalfJung:sdiv-ub, r=oli-obk

Miri/CTFE: properly treat overflow in (signed) division/rem as UB

To my surprise, it looks like LLVM treats overflow of signed div/rem as UB. From what I can tell, MIR `Div`/`Rem` directly lowers to the corresponding LLVM operation, so to make that correct we also have to consider these overflows UB in the CTFE/Miri interpreter engine.

r? `@oli-obk`

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 agobless clippy
Ralf Jung [Thu, 3 Mar 2022 00:20:27 +0000 (19:20 -0500)]
bless clippy

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 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 agoMerge commit 'e329249b6a3a98830d860c74c8234a8dd9407436' into clippyup
flip1995 [Sat, 26 Feb 2022 13:26:21 +0000 (14:26 +0100)]
Merge commit 'e329249b6a3a98830d860c74c8234a8dd9407436' into clippyup

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 agoSwitch bootstrap cfgs
Mark Rousskov [Wed, 23 Feb 2022 13:06:22 +0000 (08:06 -0500)]
Switch bootstrap cfgs

2 years agoadd tests, add base bone for the new lint
J-ZhengLi [Fri, 25 Feb 2022 10:08:52 +0000 (18:08 +0800)]
add tests, add base bone for the new lint

2 years agoAuto merge of #93368 - eddyb:diagbld-guarantee, r=estebank
bors [Fri, 25 Feb 2022 00:46:04 +0000 (00:46 +0000)]
Auto merge of #93368 - eddyb:diagbld-guarantee, r=estebank

rustc_errors: let `DiagnosticBuilder::emit` return a "guarantee of emission".

That is, `DiagnosticBuilder` is now generic over the return type of `.emit()`, so we'll now have:
* `DiagnosticBuilder<ErrorReported>` for error (incl. fatal/bug) diagnostics
  * can only be created via a `const L: Level`-generic constructor, that limits allowed variants via a `where` clause, so not even `rustc_errors` can accidentally bypass this limitation
  * asserts `diagnostic.is_error()` on emission, just in case the construction restriction was bypassed (e.g. by replacing the whole `Diagnostic` inside `DiagnosticBuilder`)
  * `.emit()` returns `ErrorReported`, as a "proof" token that `.emit()` was called
    (though note that this isn't a real guarantee until after completing the work on
     #69426)
* `DiagnosticBuilder<()>` for everything else (warnings, notes, etc.)
  * can also be obtained from other `DiagnosticBuilder`s by calling `.forget_guarantee()`

This PR is a companion to other ongoing work, namely:
* #69426
  and it's ongoing implementation:
  #93222
  the API changes in this PR are needed to get statically-checked "only errors produce `ErrorReported` from `.emit()`", but doesn't itself provide any really strong guarantees without those other `ErrorReported` changes
* #93244
  would make the choices of API changes (esp. naming) in this PR fit better overall

In order to be able to let `.emit()` return anything trustable, several changes had to be made:
* `Diagnostic`'s `level` field is now private to `rustc_errors`, to disallow arbitrary "downgrade"s from "some kind of error" to "warning" (or anything else that doesn't cause compilation to fail)
  * it's still possible to replace the whole `Diagnostic` inside the `DiagnosticBuilder`, sadly, that's harder to fix, but it's unlikely enough that we can paper over it with asserts on `.emit()`
* `.cancel()` now consumes `DiagnosticBuilder`, preventing `.emit()` calls on a cancelled diagnostic
  * it's also now done internally, through `DiagnosticBuilder`-private state, instead of having a `Level::Cancelled` variant that can be read (or worse, written) by the user
  * this removes a hazard of calling `.cancel()` on an error then continuing to attach details to it, and even expect to be able to `.emit()` it
  * warnings were switched to *only* `can_emit_warnings` on emission (instead of pre-cancelling early)
  * `struct_dummy` was removed (as it relied on a pre-`Cancelled` `Diagnostic`)
* since `.emit()` doesn't consume the `DiagnosticBuilder` <sub>(I tried and gave up, it's much more work than this PR)</sub>,
  we have to make `.emit()` idempotent wrt the guarantees it returns
  * thankfully, `err.emit(); err.emit();` can return `ErrorReported` both times, as the second `.emit()` call has no side-effects *only* because the first one did do the appropriate emission
* `&mut Diagnostic` is now used in a lot of function signatures, which used to take `&mut DiagnosticBuilder` (in the interest of not having to make those functions generic)
  * the APIs were already mostly identical, allowing for low-effort porting to this new setup
  * only some of the suggestion methods needed some rework, to have the extra `DiagnosticBuilder` functionality on the `Diagnostic` methods themselves (that change is also present in #93259)
  * `.emit()`/`.cancel()` aren't available, but IMO calling them from an "error decorator/annotator" function isn't a good practice, and can lead to strange behavior (from the caller's perspective)
  * `.downgrade_to_delayed_bug()` was added, letting you convert any `.is_error()` diagnostic into a `delay_span_bug` one (which works because in both cases the guarantees available are the same)

This PR should ideally be reviewed commit-by-commit, since there is a lot of fallout in each.

r? `@estebank` cc `@Manishearth` `@nikomatsakis` `@mark-i-m`

2 years agoRollup merge of #93714 - compiler-errors:can-type-impl-copy-error-span, r=jackh726
Dylan DPC [Thu, 24 Feb 2022 20:42:12 +0000 (21:42 +0100)]
Rollup merge of #93714 - compiler-errors:can-type-impl-copy-error-span, r=jackh726

better ObligationCause for normalization errors in `can_type_implement_copy`

Some logic is needed so we can point to the field when given totally nonsense types like `struct Foo(<u32 as Iterator>::Item);`

Fixes #93687

2 years agoUpdate clippy tests
Vadim Petrochenkov [Sat, 5 Feb 2022 02:07:13 +0000 (10:07 +0800)]
Update clippy tests

2 years agoresolve: Fix incorrect results of `opt_def_kind` query for some built-in macros
Vadim Petrochenkov [Sat, 11 Dec 2021 11:52:23 +0000 (19:52 +0800)]
resolve: Fix incorrect results of `opt_def_kind` query for some built-in macros

Previously it always returned `MacroKind::Bang` while some of those macros are actually attributes and derives

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