]> git.lizzy.rs Git - rust.git/log
rust.git
2 years agoAuto merge of #96825 - kckeiks:remove-item-like-visitor-trait, r=cjgillot
bors [Tue, 17 May 2022 06:51:45 +0000 (06:51 +0000)]
Auto merge of #96825 - kckeiks:remove-item-like-visitor-trait, r=cjgillot

 Retire `ItemLikeVisitor` trait

Issue #95004
cc `@cjgillot`

2 years agoAuto merge of #8814 - yonip23:add-suggestion-to-rc-clone-in-vec-init, r=xFrednet
bors [Tue, 17 May 2022 05:46:00 +0000 (05:46 +0000)]
Auto merge of #8814 - yonip23:add-suggestion-to-rc-clone-in-vec-init, r=xFrednet

add suggestions to rc_clone_in_vec_init

A followup to https://github.com/rust-lang/rust-clippy/pull/8769
I also switch the order of the 2 suggestions, since the loop initialization one is probably the common case.

`@xFrednet` I'm not letting you guys rest for a minute ðŸ˜…
changelog: add suggestions to [`rc_clone_in_vec_init`]

2 years agoChange `Successors` to `impl Iterator<Item = BasicBlock>`
SparrowLii [Tue, 17 May 2022 00:41:01 +0000 (08:41 +0800)]
Change `Successors` to `impl Iterator<Item = BasicBlock>`

2 years agoAuto merge of #8835 - Jarcho:let_unit_ice, r=llogiq
bors [Mon, 16 May 2022 19:20:44 +0000 (19:20 +0000)]
Auto merge of #8835 - Jarcho:let_unit_ice, r=llogiq

Fix ICE in `let_unit_value` when calling a static or const callable type

fixes #8821

changelog: Fix ICE in `let_unit_value` when calling a static or const callable type

2 years agoAuto merge of #8752 - Serial-ATA:improve-filtering, r=xFrednet
bors [Mon, 16 May 2022 17:49:00 +0000 (17:49 +0000)]
Auto merge of #8752 - Serial-ATA:improve-filtering, r=xFrednet

Add version filtering option to the lint list

I'm no web dev, so I don't know if this is the best execution :smile:.

Here's how it looks:

![Desktop](https://user-images.githubusercontent.com/69764315/165403602-9e39fe0f-6a96-46cb-ba51-8b035e74cce4.gif)

And on mobile:

![Mobile](https://user-images.githubusercontent.com/69764315/165403908-fc4a0051-2ed4-48a3-b45b-b261f49ce259.png)

I've split this into two commits, in the second one I moved the JS into its own file to make it easier to work on. Is that alright? And if so, could the same thing be done to the css?

changelog: none
cc: #7958, `@repi`
r? `@xFrednet`

2 years agoFix ICE in `let_unit_value` when calling a static or const callable type
Jason Newcomb [Mon, 16 May 2022 14:00:32 +0000 (10:00 -0400)]
Fix ICE in `let_unit_value` when calling a static or const callable type

2 years agoAdd a query for checking whether a function is an intrinsic.
Oli Scherer [Fri, 13 May 2022 13:50:21 +0000 (13:50 +0000)]
Add a query for checking whether a function is an intrinsic.

2 years agoAuto merge of #8761 - tamaroning:fix_8505, r=Jarcho
bors [Mon, 16 May 2022 00:47:10 +0000 (00:47 +0000)]
Auto merge of #8761 - tamaroning:fix_8505, r=Jarcho

`undocumented_unsafe_blocks` does not trigger on unsafe trait impls

Closes #8505

changelog: This lint checks unsafe impls NOT from macro expansions and checks ones in macro declarations.
~~`unsafe impl`s from macro invocations don't trigger the lint for now.~~
~~This lint checks unsafe impls from/not from macro expansions~~

2 years agoAuto merge of #8699 - Jarcho:vec_init_then_push_7071, r=dswij,xFrednet
bors [Sun, 15 May 2022 21:51:24 +0000 (21:51 +0000)]
Auto merge of #8699 - Jarcho:vec_init_then_push_7071, r=dswij,xFrednet

Don't lint `vec_init_then_push` when further extended

fixes #7071

This will still lint when a larger number of pushes are done (four currently). The exact number could be debated, but this is more readable then a sequence of pushes so it shouldn't be too large.

changelog: Don't lint `vec_init_then_push` when further extended.
changelog: Remove `mut` binding from `vec_init_then_push` when possible.

2 years agoUpdate `vec_init_then_push` docs
Jason Newcomb [Sun, 24 Apr 2022 13:46:17 +0000 (09:46 -0400)]
Update `vec_init_then_push` docs

2 years agoAuto merge of #8621 - Jarcho:eval_order_dependence_4637, r=Jarcho
bors [Sun, 15 May 2022 21:36:24 +0000 (21:36 +0000)]
Auto merge of #8621 - Jarcho:eval_order_dependence_4637, r=Jarcho

Rename `eval_order_dependence` to `mixed_read_write_expression`, move to nursery

As per the [reference](https://doc.rust-lang.org/1.51.0/reference/expressions.html#evaluation-order-of-operands) evaluation order is now defined.

I'm pretty sure rust always compiled with this evaluation order anyways so there's no reason the put an msrv limit on the lint.

changelog: Rename `eval_order_dependence` to `mixed_read_write_expression`, move to nursery

2 years agoAdd renamed lints to the changelog link list
Jason Newcomb [Tue, 3 May 2022 15:03:08 +0000 (11:03 -0400)]
Add renamed lints to the changelog link list

2 years agoMove `mixed_read_write_in_expression` into `restriction`
Jason Newcomb [Tue, 3 May 2022 14:58:53 +0000 (10:58 -0400)]
Move `mixed_read_write_in_expression` into `restriction`

2 years agoRename `eval_order_dependence` to `mixed_read_write_in_expression`
Jason Newcomb [Tue, 3 May 2022 14:56:59 +0000 (10:56 -0400)]
Rename `eval_order_dependence` to `mixed_read_write_in_expression`

2 years agoImprove appearance on smaller screens
Serial [Sun, 15 May 2022 16:43:35 +0000 (12:43 -0400)]
Improve appearance on smaller screens

2 years agoUse early returns
Serial [Sun, 15 May 2022 15:30:00 +0000 (11:30 -0400)]
Use early returns

2 years agoAuto merge of #8832 - Alexendoo:duplicate-mod, r=Manishearth
bors [Sun, 15 May 2022 03:52:37 +0000 (03:52 +0000)]
Auto merge of #8832 - Alexendoo:duplicate-mod, r=Manishearth

Add `duplicate_mod` lint

Inspired by #8827, warns if there's a single file that is loaded by more than one `mod` item

```rust,ignore
// lib.rs
mod a;
mod b;
```
```rust,ignore
// a.rs
#[path = "./b.rs"]
mod b;
```

It adds a `canonicalize` call per `mod file;` encountered, which I don't think should be too heavy

Integration tests with common modules, e.g. [`test_utils`](https://github.com/rust-lang/rust-clippy/tree/2038084cf2253b57cf8b405ab000a92b68346f43/tests/test_utils) doesn't trigger it as each test is compiled separately, however I couldn't figure out a good way to add a test for that

changelog: Add [`duplicate_mod`] lint

2 years agoSwitch input to `type=number`; Separate version validation out of `byVersion`
Serial [Sun, 15 May 2022 00:08:10 +0000 (20:08 -0400)]
Switch input to `type=number`; Separate version validation out of `byVersion`

2 years agoAuto merge of #96883 - jackh726:early-binder-2, r=oli-obk
bors [Sat, 14 May 2022 23:53:11 +0000 (23:53 +0000)]
Auto merge of #96883 - jackh726:early-binder-2, r=oli-obk

Add EarlyBinder

Chalk has no concept of `Param` (https://github.com/rust-lang/chalk/blob/e0ade19d139bc784384acc6736cd960c91dd55a1/chalk-ir/src/lib.rs#L579) or `ReEarlyBound` (https://github.com/rust-lang/chalk/blob/e0ade19d139bc784384acc6736cd960c91dd55a1/chalk-ir/src/lib.rs#L1308). Everything  is just "bound" - the equivalent of rustc's late-bound. It's not completely clear yet whether to move everything to the same time of binder in rustc or add `Param` and `ReEarlyBound` in Chalk.

Either way, tracking when we have or haven't already substituted out these in rustc can be helpful.

As a first step, I'm just adding a `EarlyBinder` newtype that is required to call `subst`. I also add a couple "transparent" `bound_*` wrappers around a couple query that are often immediately substituted.

r? `@nikomatsakis`

2 years agoAdd `duplicate_mod` lint
Alex Macleod [Sat, 14 May 2022 18:35:16 +0000 (19:35 +0100)]
Add `duplicate_mod` lint

2 years agoAdd bound_fn_sig
Jack Huey [Sun, 8 May 2022 19:43:18 +0000 (15:43 -0400)]
Add bound_fn_sig

2 years agoAdd bound_type_of
Jack Huey [Sun, 8 May 2022 19:12:56 +0000 (15:12 -0400)]
Add bound_type_of

2 years agoremove TestItemNamesVisitor
Miguel Guarniz [Sat, 7 May 2022 18:51:05 +0000 (14:51 -0400)]
remove TestItemNamesVisitor

Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
2 years agoAuto merge of #8813 - evantypanski:redundant_alloc_fat_ptr, r=Alexendoo
bors [Fri, 13 May 2022 15:02:58 +0000 (15:02 +0000)]
Auto merge of #8813 - evantypanski:redundant_alloc_fat_ptr, r=Alexendoo

Fix redundant_allocation warning for Rc<Box<str>>

changelog: [`redundant_allocation`] Fixes #8604

Fixes false positives where a fat pointer with `str` type was made thin by another allocation, but that thinning allocation was marked as redundant

2 years agoComment why `hir_ty_to_ty` is safe in `check_ty`
Evan Typanski [Fri, 13 May 2022 09:55:50 +0000 (05:55 -0400)]
Comment why `hir_ty_to_ty` is safe in `check_ty`

2 years agoAuto merge of #8825 - ydah:fix_spelling, r=giraffate
bors [Fri, 13 May 2022 06:03:39 +0000 (06:03 +0000)]
Auto merge of #8825 - ydah:fix_spelling, r=giraffate

Tweak some words improved representation

Hello! Thank you for this awesome project!

This PR has implemented improved representation.

- Use "lib" instead of "lifb"
- Use "triggered" instead of "triggere"
- Use "blacklisted_name" instead of "blackisted_name"
- Use "stabilization" instead of "stabilisation"
- Use "behavior" instead of "behaviour"
- Use "target" instead of "tartet"
- Use "checked_add" instead of "chcked_add"
- Use "anti-pattern" instead of "antipattern"
- Use "suggestion" instead of "suggesttion"
- Use "example" instead of "exampel"
- Use "Cheat Sheet" instead of "Cheatsheet"

---

changelog: none

2 years agoTweak some words improved representation
ydah [Fri, 13 May 2022 05:20:25 +0000 (14:20 +0900)]
Tweak some words improved representation

This PR has implemented improved representation.

- Use "lib" instead of "lifb"
- Use "triggered" instead of "triggere"
- Use "blacklisted_name" instead of "blackisted_name"
- Use "stabilization" instead of "stabilisation"
- Use "behavior" instead of "behaviour"
- Use "target" instead of "tartet"
- Use "checked_add" instead of "chcked_add"
- Use "anti-pattern" instead of "antipattern"
- Use "suggestion" instead of "suggesttion"
- Use "example" instead of "exampel"
- Use "Cheat Sheet" instead of "Cheatsheet"

2 years agoAuto merge of #8799 - Alexendoo:lintcheck-common, r=giraffate
bors [Thu, 12 May 2022 23:56:31 +0000 (23:56 +0000)]
Auto merge of #8799 - Alexendoo:lintcheck-common, r=giraffate

Some lintcheck cleanup

A grab bag of smaller changes:

Panics if a crate source isn't valid, and fixes the `ryu` crate entry so it's picked up. Took me a while to realise why I couldn't do `cargo lintcheck --only ryu` ðŸ˜…

Parses messages with `cargo_metadata`, this catches a few more lints that were ignored because the message had an [expansion field](https://docs.rs/cargo_metadata/latest/cargo_metadata/diagnostic/struct.DiagnosticSpanMacroExpansion.html) that contained a path pointing into `.../.toolchains/...`. It also no longer emits some log lines with `null` as the column

It also merges the `run_clippy_lint` invocations and splits `LintcheckConfig` out into its own file

changelog: none

2 years agoinline construct_lint_suggestions
yonip23 [Thu, 12 May 2022 23:20:28 +0000 (02:20 +0300)]
inline construct_lint_suggestions

2 years agoCatch other thinning allocations using Ty
Evan Typanski [Thu, 12 May 2022 23:06:23 +0000 (19:06 -0400)]
Catch other thinning allocations using Ty

2 years agoAuto merge of #95562 - lcnr:attr-no-encode, r=davidtwco
bors [Thu, 12 May 2022 12:48:30 +0000 (12:48 +0000)]
Auto merge of #95562 - lcnr:attr-no-encode, r=davidtwco

don't encode only locally used attrs

Part of https://github.com/rust-lang/compiler-team/issues/505.

We now filter builtin attributes before encoding them in the crate metadata in case they should only be used in the local crate. To prevent accidental misuse `get_attrs` now requires the caller to state which attribute they are interested in. For places where that isn't trivially possible, I've added a method `fn get_attrs_unchecked` which I intend to remove in a followup PR.

After this pull request landed, we can then slowly move all attributes to only be used in the local crate while being certain that we don't accidentally try to access them from extern crates.

cc https://github.com/rust-lang/rust/pull/94963#issuecomment-1082924289

2 years agoSome lintcheck cleanup
Alex Macleod [Sat, 7 May 2022 21:10:56 +0000 (22:10 +0100)]
Some lintcheck cleanup

2 years agofix indentation + test
yonip23 [Thu, 12 May 2022 07:06:15 +0000 (10:06 +0300)]
fix indentation + test

2 years agofix
tamaron [Thu, 12 May 2022 03:33:05 +0000 (12:33 +0900)]
fix

2 years agofix clippy warning
yonip23 [Wed, 11 May 2022 20:16:49 +0000 (23:16 +0300)]
fix clippy warning

2 years agoAuto merge of #8818 - koic:use_rust_2021_prelude, r=flip1995
bors [Wed, 11 May 2022 20:16:42 +0000 (20:16 +0000)]
Auto merge of #8818 - koic:use_rust_2021_prelude, r=flip1995

Use the traits added to the Rust 2021 Edition prelude

Follow up https://github.com/rust-lang/rust/pull/96861.

This PR uses the traits added to the Rust 2021 Edition prelude.

> The `TryInto`, `TryFrom` and `FromIterator` traits are now part of the prelude.

https://doc.rust-lang.org/edition-guide/rust-2021/prelude.html

---

changelog: none

2 years agofix review comments
yonip23 [Wed, 11 May 2022 20:11:52 +0000 (23:11 +0300)]
fix review comments

2 years agoAuto merge of #8726 - Serial-ATA:issue-8723, r=dswij,xFrednet
bors [Wed, 11 May 2022 17:39:25 +0000 (17:39 +0000)]
Auto merge of #8726 - Serial-ATA:issue-8723, r=dswij,xFrednet

Fix `match_single_binding` suggestion for assign expressions

changelog: Fix suggestion for assign expressions in [`match_single_binding`]
closes: #8723

2 years agoBless clippy.
Camille GILLOT [Wed, 11 May 2022 16:51:14 +0000 (18:51 +0200)]
Bless clippy.

2 years agoUse the traits added to the Rust 2021 Edition prelude
Koichi ITO [Tue, 10 May 2022 16:03:52 +0000 (01:03 +0900)]
Use the traits added to the Rust 2021 Edition prelude

Follow up https://github.com/rust-lang/rust/pull/96861.

This PR uses the traits added to the Rust 2021 Edition prelude.

> The `TryInto`, `TryFrom` and `FromIterator` traits are now part of the prelude.

https://doc.rust-lang.org/edition-guide/rust-2021/prelude.html

2 years agoIntroduce EarlyBinder
Jack Huey [Sun, 8 May 2022 05:17:58 +0000 (01:17 -0400)]
Introduce EarlyBinder

2 years agoFix `match_single_binding` for assign expressions
Serial [Wed, 20 Apr 2022 14:14:11 +0000 (10:14 -0400)]
Fix `match_single_binding` for assign expressions

2 years agoadd suggestions to rc_clone_in_vec_init
yonip23 [Tue, 10 May 2022 21:46:20 +0000 (00:46 +0300)]
add suggestions to rc_clone_in_vec_init

2 years agoFix redundant_allocation warning for Rc<Box<str>>
Evan Typanski [Tue, 10 May 2022 18:21:51 +0000 (14:21 -0400)]
Fix redundant_allocation warning for Rc<Box<str>>

2 years agochore
tamaron [Tue, 10 May 2022 15:27:12 +0000 (00:27 +0900)]
chore

2 years agofix
tamaron [Tue, 10 May 2022 14:08:18 +0000 (23:08 +0900)]
fix

2 years agoAuto merge of #8796 - nsunderland1:master, r=giraffate
bors [Tue, 10 May 2022 13:25:27 +0000 (13:25 +0000)]
Auto merge of #8796 - nsunderland1:master, r=giraffate

New lint: [`derive_partial_eq_without_eq`]

Introduces a new lint, [`derive_partial_eq_without_eq`].

See: #1781 (doesn't close it though).

changelog: add lint [`derive_partial_eq_without_eq`]

2 years agoAuto merge of #8769 - yonip23:8719, r=xFrednet
bors [Tue, 10 May 2022 12:21:12 +0000 (12:21 +0000)]
Auto merge of #8769 - yonip23:8719, r=xFrednet

introduce rc_clone_in_vec_init lint

Closes #8719

changelog: Introduce [`rc_clone_in_vec_init`] lint

2 years agointroduce rc_clone_in_vec_init lint
yonip23 [Sun, 8 May 2022 19:20:25 +0000 (22:20 +0300)]
introduce rc_clone_in_vec_init lint

2 years agoupdate clippy
lcnr [Tue, 26 Apr 2022 12:04:23 +0000 (14:04 +0200)]
update clippy

2 years agoNew lint: [`derive_partial_eq_without_eq`]
nsunderland1 [Fri, 6 May 2022 07:10:11 +0000 (00:10 -0700)]
New lint: [`derive_partial_eq_without_eq`]

2 years agoAuto merge of #8809 - Alexendoo:metadata-collection-expect, r=xFrednet
bors [Mon, 9 May 2022 19:55:37 +0000 (19:55 +0000)]
Auto merge of #8809 - Alexendoo:metadata-collection-expect, r=xFrednet

Ignore unfulfilled_lint_expectations in metadata collection

r? `@xFrednet`

When metadata collection is enabled the regular early/late pass registrations are skipped, which the `#[expect()]`s were no fan of: https://github.com/rust-lang/rust-clippy/runs/6356675328?check_suite_focus=true

changelog: none

2 years agoIgnore unfulfilled_lint_expectations in metadata collection
Alex Macleod [Mon, 9 May 2022 19:30:06 +0000 (20:30 +0100)]
Ignore unfulfilled_lint_expectations in metadata collection

2 years agoAuto merge of #8797 - xFrednet:0000-expect-a-playground, r=flip1995
bors [Mon, 9 May 2022 17:14:43 +0000 (17:14 +0000)]
Auto merge of #8797 - xFrednet:0000-expect-a-playground, r=flip1995

Replace `#[allow]` with `#[expect]` in Clippy

Hey `@rust-lang/clippy,` `@Alexendoo,` `@dswij,` I'm currently working on the expect attribute as defined in [Rust RFC 2383](https://rust-lang.github.io/rfcs/2383-lint-reasons.html). With that, an `#[allow]` attribute can be replaced with a `#[expect]` attribute that suppresses the lint, but also emits a warning, if the lint isn't emitted in the expected scope.

With this PR I would like to test the attribute on a project scale and Clippy obviously came to mind. This PR replaces (almost) all `#[allow]` attributes in `clippy_utils` and `clippy_lints` with the `#[expect]` attribute. I was also able to remove some allows since, the related FPs have been fixed :tada:.

My question is now, are there any concerns regarding this? It's still okay to add normal `#[allow]` attributes, I see the need to nit-pick about that in new PRs, unless it's actually a FP. Also, I would not recommend using `#[expect]` in tests, as changes to a lint could the trigger the expect attribute in other files.

Additionally, I've noticed that Clippy has a bunch of `#[allow(clippy::too_many_lines)]` attributes. Should we maybe allow the lint all together or increase the threshold setting? To me, it seems like we mostly just ignore it in our code. :sweat_smile: :upside_down_face:

---

changelog: none

r? `@flip1995` (I've requested you for now, since you're also helping with reviewing the expect implementation. You are welcome to delegate this PR, even if it should be a simple review :upside_down_face: )

2 years agoDon't lint `cmp_owned` when `From::from` results in a copy type.
Jason Newcomb [Mon, 9 May 2022 16:29:31 +0000 (12:29 -0400)]
Don't lint `cmp_owned` when `From::from` results in a copy type.

2 years agoReduce unnecessary work in `cmp_owned`
Jason Newcomb [Mon, 9 May 2022 15:41:25 +0000 (11:41 -0400)]
Reduce unnecessary work in `cmp_owned`

2 years agoAuto merge of #8805 - Alexendoo:let-chain-docs, r=flip1995
bors [Mon, 9 May 2022 13:56:53 +0000 (13:56 +0000)]
Auto merge of #8805 - Alexendoo:let-chain-docs, r=flip1995

Recommend let chains over if_chain in docs

Switches over bit_mask.rs to let chains in order to create a nice example

While the rustfmt thing isn't resolved yet, my rust-analyzer isn't a fan of large `if_chains!`s, it stops giving me hover info and such after some number of if statements

changelog: none

2 years agofix clippy
SparrowLii [Mon, 9 May 2022 13:48:57 +0000 (21:48 +0800)]
fix clippy

2 years agoRecommend let chains over if_chain in docs
Alex Macleod [Mon, 9 May 2022 13:23:16 +0000 (14:23 +0100)]
Recommend let chains over if_chain in docs

2 years agouse let chains in bit_mask.rs
Alex Macleod [Mon, 9 May 2022 13:06:46 +0000 (14:06 +0100)]
use let chains in bit_mask.rs

2 years agoAuto merge of #95542 - xFrednet:rfc-2383-expect-query, r=wesleywiser
bors [Mon, 9 May 2022 00:02:55 +0000 (00:02 +0000)]
Auto merge of #95542 - xFrednet:rfc-2383-expect-query, r=wesleywiser

Support tool lints with the `#[expect]` attribute (RFC 2383)

This PR fixes the ICE https://github.com/rust-lang/rust/issues/94953 by making the assert for converted expectation IDs conditional.

Additionally, it moves the lint expectation check into a separate query to support rustdoc and other tools. On the way, I've also added some tests to ensure that the attribute works for Clippy and rustdoc lints.

The number of changes comes from the long test file. This may look like a monster PR, this may smell like a monster PR and this may be a monster PR, but it's a harmless monster. :sauropod:

---

Closes: https://github.com/rust-lang/rust/issues/94953
cc: https://github.com/rust-lang/rust/issues/85549

r? `@wesleywiser`

cc: `@rust-lang/rustdoc`

2 years agoAuto merge of #8802 - smoelius:allow-expect-unwrap-in-tests, r=llogiq
bors [Sun, 8 May 2022 15:00:30 +0000 (15:00 +0000)]
Auto merge of #8802 - smoelius:allow-expect-unwrap-in-tests, r=llogiq

Optionally allow `expect` and `unwrap` in tests

This addresses #1015, except it makes the new behavior optional.

The reason for the msrv-related changes is as follows.

Rather than expand `check_methods` list of arguments, it seemed easier to make `check_methods` a method of `Methods`, so that `check_methods` could access `Methods`' fields.

`check_methods` had an `msrv` parameter, which I consequently made a field of `Methods`. But, to avoid adding a lifetime parameter to `Methods`, I made the field type `Option<RustcVersion>` instead of the parameter's existing type, `Option<&RustcVersion>`. This seemed sensible since `RustcVersion` implements `Copy`. But this broke a lot of code that expected an `Option<&RustcVersion>` or `&Option<RustcVersion>`. I changed all of those occurrences to `Option<RustcVersion>`. IMHO, the code is better as a result of these changes, though.

The msrv-related changes are in their own commit to (hopefully) ease review.

Closes #1015

changelog: optionally allow `expect` and `unwrap` in tests

r? `@llogiq`

2 years agoAuto merge of #96770 - flip1995:fix-trait-type-in-bounds, r=cjgillot
bors [Sun, 8 May 2022 14:10:12 +0000 (14:10 +0000)]
Auto merge of #96770 - flip1995:fix-trait-type-in-bounds, r=cjgillot

Track if a where bound comes from a impl Trait desugar

With https://github.com/rust-lang/rust/pull/93803 `impl Trait` function arguments get desugared to hidden where bounds. However, Clippy needs to know if a bound was originally a `impl Trait` or an actual bound. This adds a field to the `WhereBoundPredicate` struct to keep track of this information during AST->HIR lowering.

r? `@cjgillot`

cc `@estebank` (as the reviewer of #93803)

2 years agoTest `expect` attribute for tool lints, clippy edition (RFC 2383)
xFrednet [Thu, 31 Mar 2022 19:49:50 +0000 (21:49 +0200)]
Test `expect` attribute for tool lints, clippy edition (RFC 2383)

2 years agoOptionally allow `expect` and `unwrap` in tests
Samuel E. Moelius III [Sun, 8 May 2022 10:44:58 +0000 (06:44 -0400)]
Optionally allow `expect` and `unwrap` in tests

2 years agoPass msrvs by copy
Samuel E. Moelius III [Sun, 8 May 2022 11:13:14 +0000 (07:13 -0400)]
Pass msrvs by copy

2 years agoAuto merge of #94206 - PrestonFrom:significant_drop, r=flip1995
bors [Sun, 8 May 2022 00:57:08 +0000 (00:57 +0000)]
Auto merge of #94206 - PrestonFrom:significant_drop, r=flip1995

Create clippy lint against unexpectedly late drop for temporaries in match scrutinee expressions

A new clippy lint for issue 93883 (https://github.com/rust-lang/rust/issues/93883). Relies on a new trait in `marker` (called `SignificantDrop` to enable linting), which is why this PR is for the rust-lang repo and not the clippy repo.

changelog: new lint [`significant_drop_in_scrutinee`]

2 years agoReplace `#[allow]` with `#[expect]` in Clippy
xFrednet [Sat, 7 May 2022 14:49:19 +0000 (16:49 +0200)]
Replace `#[allow]` with `#[expect]` in Clippy

2 years agoTrack if a where bound comes from a impl Trait desugar
flip1995 [Thu, 5 May 2022 14:50:11 +0000 (15:50 +0100)]
Track if a where bound comes from a impl Trait desugar

With #93803 `impl Trait` function arguments get desugared to hidden
where bounds. However, Clippy needs to know if a bound was originally a
impl Trait or an actual bound. This adds a field to the
`WhereBoundPredicate` struct to keep track of this information during
HIR lowering.

2 years agoAuto merge of #8794 - smoelius:fix-8759, r=llogiq
bors [Sat, 7 May 2022 12:31:47 +0000 (12:31 +0000)]
Auto merge of #8794 - smoelius:fix-8759, r=llogiq

Address `unnecessary_to_owned` false positive

My proposed fix for #8759 is to revise the conditions that delineate `redundant_clone` and `unnecessary_to_owned`:
```rust
        // Only flag cases satisfying at least one of the following three conditions:
        // * the referent and receiver types are distinct
        // * the referent/receiver type is a copyable array
        // * the method is `Cow::into_owned`
        // This restriction is to ensure there is no overlap between `redundant_clone` and this
        // lint. It also avoids the following false positive:
        //  https://github.com/rust-lang/rust-clippy/issues/8759
        //   Arrays are a bit of a corner case. Non-copyable arrays are handled by
        // `redundant_clone`, but copyable arrays are not.
```
This change causes a few cases that were previously flagged by `unnecessary_to_owned` to no longer be flagged. But one could argue those cases would be better handled by `redundant_clone`.

Closes #8759

changelog: none

2 years agofix
tamaron [Sat, 7 May 2022 09:18:57 +0000 (18:18 +0900)]
fix

2 years agoLint for significant drops who may have surprising lifetimes #1
Preston From [Fri, 18 Feb 2022 06:02:22 +0000 (00:02 -0600)]
Lint for significant drops who may have surprising lifetimes #1

author Preston From <prestonfrom@gmail.com> 1645164142 -0600
committer Preston From <prestonfrom@gmail.com> 1650005351 -0600

2 years agoAuto merge of #96531 - kckeiks:remove-item-like-visitor-from-rustc-typeck, r=cjgillot
bors [Sat, 7 May 2022 01:59:11 +0000 (01:59 +0000)]
Auto merge of #96531 - kckeiks:remove-item-like-visitor-from-rustc-typeck, r=cjgillot

Remove ItemLikeVisitor impls from rustc_typeck

Issue #95004
cc `@cjgillot`

2 years agoRollup merge of #96557 - nbdd0121:const, r=oli-obk
Guillaume Gomez [Fri, 6 May 2022 18:05:37 +0000 (20:05 +0200)]
Rollup merge of #96557 - nbdd0121:const, r=oli-obk

Allow inline consts to reference generic params

Tracking issue: #76001

The RFC says that inline consts cannot reference to generic parameters (for now), same as array length expressions. And expresses that it's desirable for it to reference in-scope generics, when array length expressions gain that feature as well.

However it is possible to implement this for inline consts before doing this for all anon consts, because inline consts are only used as values and they won't be used in the type system. So we can have:
```rust
fn foo<T>() {
    let x = [4i32; std::mem::size_of::<T>()];   // NOT ALLOWED (for now)
    let x = const { std::mem::size_of::<T>() }; // ALLOWED with this PR!
    let x = [4i32; const { std::mem::size_of::<T>() }];   // NOT ALLOWED (for now)
}
```

This would make inline consts super useful for compile-time checks and assertions:
```rust
fn assert_zst<T>() {
    const { assert!(std::mem::size_of::<T>() == 0) };
}
```

This would create an error during monomorphization when `assert_zst` is instantiated with non-ZST `T`s. A error during mono might sound scary, but this is exactly what a "desugared" inline const would do:
```rust
fn assert_zst<T>() {
    struct F<T>(T);
    impl<T> F<T> {
        const V: () = assert!(std::mem::size_of::<T>() == 0);
    }
    let _ = F::<T>::V;
}
```

It should also be noted that the current inline const implementation can already reference the type params via type inference, so this resolver-level restriction is not any useful either:
```rust
fn foo<T>() -> usize {
    let (_, size): (PhantomData<T>, usize) = const {
        const fn my_size_of<T>() -> (PhantomData<T>, usize) {
            (PhantomData, std::mem::size_of::<T>())
        }
        my_size_of()
    };
    size
}
```

```@rustbot``` label: F-inline_const

2 years agoAuto merge of #8793 - Alexendoo:dev-lint-extra-args, r=xFrednet
bors [Fri, 6 May 2022 16:14:11 +0000 (16:14 +0000)]
Auto merge of #8793 - Alexendoo:dev-lint-extra-args, r=xFrednet

Pass through extra args in `cargo dev lint`

changelog: Pass through extra args in `cargo dev lint`

Lets you pass some useful flags through, like `-A/W/etc`, `--fix`, `--force-warn`

2 years agouse def_span and def_kind queries instead of calling tcx.hir() methods
Miguel Guarniz [Fri, 29 Apr 2022 17:11:22 +0000 (13:11 -0400)]
use def_span and def_kind queries instead of calling tcx.hir() methods

Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
2 years agoResolved conflicts
tamaron [Fri, 29 Apr 2022 09:34:58 +0000 (18:34 +0900)]
Resolved conflicts

2 years agoPass through extra args in `cargo dev lint`
Alex Macleod [Fri, 6 May 2022 12:21:08 +0000 (13:21 +0100)]
Pass through extra args in `cargo dev lint`

2 years agoAddress `unnecessary_to_owned` false positive
Samuel E. Moelius III [Fri, 6 May 2022 01:39:54 +0000 (21:39 -0400)]
Address `unnecessary_to_owned` false positive

2 years agoAuto merge of #8763 - arieluy:manual_range_contains, r=xFrednet
bors [Fri, 6 May 2022 11:33:47 +0000 (11:33 +0000)]
Auto merge of #8763 - arieluy:manual_range_contains, r=xFrednet

Support negative ints in manual_range_contains

fixes: #8721
changelog: Fixes issue where ranges containing ints with different signs would be
incorrect due to comparing as unsigned.

2 years agoAuto merge of #8792 - jyn514:remove-ast-json, r=flip1995
bors [Fri, 6 May 2022 09:44:19 +0000 (09:44 +0000)]
Auto merge of #8792 - jyn514:remove-ast-json, r=flip1995

Suggest -Zunpretty=ast-tree instead of -Zast-json

-Zast-json is being removed shortly: https://github.com/rust-lang/rust/pull/85993.
ast-tree does essentially the same thing, and still works today even before that PR lands.

changelog: none

2 years agoCreate RangeBounds struct
Ariel Uy [Fri, 6 May 2022 04:13:17 +0000 (21:13 -0700)]
Create RangeBounds struct

For check_range_bounds return type.

2 years agoSuggest -Zunpretty=ast-tree instead of -Zast-json
Joshua Nelson [Fri, 6 May 2022 01:11:41 +0000 (20:11 -0500)]
Suggest -Zunpretty=ast-tree instead of -Zast-json

-Zast-json is being removed shortly: https://github.com/rust-lang/rust/pull/85993.
ast-tree does essentially the same thing, and still works today even before that PR lands.

2 years agoAuto merge of #8778 - sunfishcode:main, r=giraffate
bors [Fri, 6 May 2022 00:26:18 +0000 (00:26 +0000)]
Auto merge of #8778 - sunfishcode:main, r=giraffate

Fix `cast_lossless` to avoid warning on `usize` to `f64` conversion.

Previously, the `cast_lossless` lint would issue a warning on code that
converted a `usize` value to `f64`, on 32-bit targets.

`usize` to `f64` is a lossless cast on 32-bit targets, however there is
no corresponding `f64::from` that takes a `usize`, so `cast_lossless`'s
suggested replacement does not compile.

This PR disables the lint in the case of casting from `usize` or `isize`.

Fixes #3689.

changelog: [`cast_lossless`] no longer gives wrong suggestion on usize,isize->f64

2 years agoUse CamelCase; Fix filter ranges
Serial [Thu, 5 May 2022 22:27:56 +0000 (18:27 -0400)]
Use CamelCase; Fix filter ranges

2 years agoAuto merge of #8790 - Jarcho:attribute_line, r=flip1995
bors [Thu, 5 May 2022 21:39:11 +0000 (21:39 +0000)]
Auto merge of #8790 - Jarcho:attribute_line, r=flip1995

Lint `empty_lint_after_outer_attr` on argumentless macros

Reverts the change from 034c81b76145a0514916f34713671b16f26988df as it's no longer needed. The test is left just in case. Original issue is #2475.

changelog: Lint `empty_lint_after_outer_attr` on argumentless macros again

2 years agoRevert hack fixing #2475 added in commit 034c81b76145a0514916f34713671b16f26988df...
Jason Newcomb [Thu, 5 May 2022 17:24:38 +0000 (13:24 -0400)]
Revert hack fixing #2475 added in commit 034c81b76145a0514916f34713671b16f26988df. It's no longer needed.

2 years agoAuto merge of #8789 - fedemartinezdev:master, r=flip1995
bors [Thu, 5 May 2022 17:11:06 +0000 (17:11 +0000)]
Auto merge of #8789 - fedemartinezdev:master, r=flip1995

Added missing `### What it does`

Adds the missing line to ``[`cast-slice-different-sizes`]`` lint documentation
fixes #8781

changelog: none

2 years agoAdded missing `### What it does`
Federico Martinez [Thu, 5 May 2022 16:50:34 +0000 (18:50 +0200)]
Added missing `### What it does`

Adds the missing line to cast-slice-different-sizes lint documentation
/closes 8781

2 years ago(Partially) Revert "HACK: Move buggy lints to nursery"
flip1995 [Thu, 5 May 2022 14:20:07 +0000 (15:20 +0100)]
(Partially) Revert "HACK: Move buggy lints to nursery"

This reverts commit bb01aca86f66954b80798213711e8eadc4b26902.

Partial: Keep regression tests

2 years agoMerge commit '7c21f91b15b7604f818565646b686d90f99d1baf' into clippyup
flip1995 [Thu, 5 May 2022 14:12:52 +0000 (15:12 +0100)]
Merge commit '7c21f91b15b7604f818565646b686d90f99d1baf' into clippyup

2 years agoBless clippy error msg
Gary Guo [Thu, 5 May 2022 13:27:11 +0000 (14:27 +0100)]
Bless clippy error msg

2 years agoAuto merge of #8788 - flip1995:rustup, r=xFrednet,flip1995
bors [Thu, 5 May 2022 13:12:09 +0000 (13:12 +0000)]
Auto merge of #8788 - flip1995:rustup, r=xFrednet,flip1995

Rustup

r? `@ghost`

changelog: move trait_duplication_in_bounds and type_repetition_in_bounds to nursery temporarily. This could already be reverted before the release. Check the Clippy in the Rust repo beta branch when writing this changelog.

2 years agoFix ICE in EarlyAttribtues lints
flip1995 [Thu, 5 May 2022 13:10:06 +0000 (14:10 +0100)]
Fix ICE in EarlyAttribtues lints

2 years agoHACK: Move buggy lints to nursery
flip1995 [Thu, 5 May 2022 12:32:31 +0000 (13:32 +0100)]
HACK: Move buggy lints to nursery

Those lints are trait_duplication_in_bounds and
type_repetition_in_bounds. I don't think those can be fixed on the
Clippy side alone, but need changes in the compiler. So let's move them
to nursery to get the sync through and then fix them on the rustc side.

Also adds a regression test that has to be fixed before they can be
moved back to pedantic.

2 years agoBump nightly version -> 2022-05-05
flip1995 [Thu, 5 May 2022 12:32:18 +0000 (13:32 +0100)]
Bump nightly version -> 2022-05-05

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

2 years agoChange input placeholder
Serial [Thu, 5 May 2022 00:43:08 +0000 (20:43 -0400)]
Change input placeholder

2 years agoAuto merge of #96546 - nnethercote:overhaul-MacArgs, r=petrochenkov
bors [Wed, 4 May 2022 21:16:28 +0000 (21:16 +0000)]
Auto merge of #96546 - nnethercote:overhaul-MacArgs, r=petrochenkov

Overhaul `MacArgs`

Motivation:
- Clarify some code that I found hard to understand.
- Eliminate one use of three places where `TokenKind::Interpolated` values are created.

r? `@petrochenkov`

2 years agoOverhaul `MacArgs::Eq`.
Nicholas Nethercote [Thu, 28 Apr 2022 20:52:01 +0000 (06:52 +1000)]
Overhaul `MacArgs::Eq`.

The value in `MacArgs::Eq` is currently represented as a `Token`.
Because of `TokenKind::Interpolated`, `Token` can be either a token or
an arbitrary AST fragment. In practice, a `MacArgs::Eq` starts out as a
literal or macro call AST fragment, and then is later lowered to a
literal token. But this is very non-obvious. `Token` is a much more
general type than what is needed.

This commit restricts things, by introducing a new type `MacArgsEqKind`
that is either an AST expression (pre-lowering) or an AST literal
(post-lowering). The downside is that the code is a bit more verbose in
a few places. The benefit is that makes it much clearer what the
possibilities are (though also shorter in some other places). Also, it
removes one use of `TokenKind::Interpolated`, taking us a step closer to
removing that variant, which will let us make `Token` impl `Copy` and
remove many "handle Interpolated" code paths in the parser.

Things to note:
- Error messages have improved. Messages like this:
  ```
  unexpected token: `"bug" + "found"`
  ```
  now say "unexpected expression", which makes more sense. Although
  arbitrary expressions can exist within tokens thanks to
  `TokenKind::Interpolated`, that's not obvious to anyone who doesn't
  know compiler internals.
- In `parse_mac_args_common`, we no longer need to collect tokens for
  the value expression.