]> git.lizzy.rs Git - rust.git/log
rust.git
20 months agoAuto merge of #9622 - llogiq:box-dyn-default, r=Alexendoo
bors [Sun, 23 Oct 2022 11:15:19 +0000 (11:15 +0000)]
Auto merge of #9622 - llogiq:box-dyn-default, r=Alexendoo

fix `box-default` ignoring trait objects' types

This avoids removing the turbofish when the `Box` type is a `dyn` or `impl _`.

This fixes #9621.

---

changelog: none

20 months agoAuto merge of #9688 - Alexendoo:msrv-tests, r=Manishearth
bors [Sun, 23 Oct 2022 05:05:23 +0000 (05:05 +0000)]
Auto merge of #9688 - Alexendoo:msrv-tests, r=Manishearth

Move MSRV tests into the lint specific test files

There are currently two ways MSRV tests are done in the ui test suite, adding a case to the `#![clippy::msrv = "1.0"]` `tests/ui/min_rust_version_attr.rs` or adding the two `msrv_1_xx` functions to the test file of the lint in question

This updates the clippy book to suggest the `msrv_1_xx` style, and replaces the tests in `tests/ui/min_rust_version_attr.rs` with ones of that style

Almost the entire diff is just moving stuff around as a result, I made sure to check the line numbers the lints are emitted at correspond with the right `msrv` case, so feel free to only skim that part

changelog: none

20 months agoAuto merge of #9691 - smoelius:lint-lintcheck, r=llogiq
bors [Sat, 22 Oct 2022 18:42:12 +0000 (18:42 +0000)]
Auto merge of #9691 - smoelius:lint-lintcheck, r=llogiq

Add `lintcheck` to packages linted by `dogfood` test

Currently, `lintcheck` is not checked by the `dogfood` test. I assume that is not intentional. If it is intentional, then this PR can be ignored.

changelog: Add `lintcheck` to packages linted by `dogfood` test

20 months agoApply manual fixes
Samuel Moelius [Sat, 22 Oct 2022 11:12:07 +0000 (07:12 -0400)]
Apply manual fixes

20 months agoApply `--fix` fixes
Samuel Moelius [Sat, 22 Oct 2022 11:37:23 +0000 (07:37 -0400)]
Apply `--fix` fixes

20 months agoAdd `lintcheck` to packages linted by `dogfood` test
Samuel Moelius [Sat, 22 Oct 2022 11:37:10 +0000 (07:37 -0400)]
Add `lintcheck` to packages linted by `dogfood` test

20 months agoMove MSRV tests into the lint specific test files
Alex Macleod [Fri, 21 Oct 2022 21:35:39 +0000 (21:35 +0000)]
Move MSRV tests into the lint specific test files

20 months agoAuto merge of #9684 - kraktus:ref_option_ref, r=xFrednet
bors [Fri, 21 Oct 2022 20:19:30 +0000 (20:19 +0000)]
Auto merge of #9684 - kraktus:ref_option_ref, r=xFrednet

`ref_option_ref` do not lint when inner reference is mutable

changelog: FP: [`ref_option_ref`]: No longer lints if the inner reference is mutable

fix https://github.com/rust-lang/rust-clippy/issues/9682

20 months agoAuto merge of #9685 - kraktus:collapsible_match, r=llogiq
bors [Fri, 21 Oct 2022 19:27:35 +0000 (19:27 +0000)]
Auto merge of #9685 - kraktus:collapsible_match, r=llogiq

[`collapsible_match`] specify field name when destructuring structs

changelog: [`collapsible_match`] specify field name when destructuring structs

fix https://github.com/rust-lang/rust-clippy/issues/9647

I wasn't the sure about the best way to convey the message in the lint message since it does not use suggestion. Because I liked the former output highlighting both spans, I've left it as before, only modifying the span label.

20 months ago[`collapsible_match`] specify field name when destructuring structs
kraktus [Fri, 21 Oct 2022 12:51:13 +0000 (14:51 +0200)]
[`collapsible_match`] specify field name when destructuring structs

20 months ago`ref_option_ref` do not lint when inner reference is mutable
kraktus [Fri, 21 Oct 2022 11:48:41 +0000 (13:48 +0200)]
`ref_option_ref` do not lint when inner reference is mutable

As it makes the `Option` Non Copy

20 months agoAuto merge of #9635 - smoelius:fix-9386-bug, r=Jarcho
bors [Thu, 20 Oct 2022 15:18:31 +0000 (15:18 +0000)]
Auto merge of #9635 - smoelius:fix-9386-bug, r=Jarcho

Fix bug introduced by #9386

#9386 introduced a potential out-of-bounds array access. Specifically, a location returned by `local_assignments` could have  [`location.statement_index` equal to `mir.basic_blocks[location.block].statements.len()`](https://github.com/rust-lang/rust-clippy/blob/b8a9a507bf9e3149d287841454842116c72d66c4/clippy_utils/src/mir/mod.rs#L129), in which case the location would refer to the block terminator:
https://github.com/rust-lang/rust-clippy/blob/b8a9a507bf9e3149d287841454842116c72d66c4/clippy_lints/src/dereference.rs#L1204-L1206
I suspect the bug is not triggerable now, because of checks leading up to where it occurs. But a future code change could make it triggerable. Hence, it should be fixed.

r? `@Jarcho`

changelog: none

20 months agoAuto merge of #9670 - Alexendoo:missing-trait-methods, r=Jarcho
bors [Thu, 20 Oct 2022 15:05:06 +0000 (15:05 +0000)]
Auto merge of #9670 - Alexendoo:missing-trait-methods, r=Jarcho

Add `missing_trait_methods` lint

Closes #9661

changelog: new lint: [`missing_trait_methods`]

20 months agoAuto merge of #9680 - flip1995:rustup, r=flip1995
bors [Thu, 20 Oct 2022 14:43:03 +0000 (14:43 +0000)]
Auto merge of #9680 - flip1995:rustup, r=flip1995

Rustup

r? `@ghost`

I ran out of time and will have to do the Clippy->Rust sync tomorrow.

changelog: none

20 months agoBump nightly version -> 2022-10-20
Philipp Krones [Thu, 20 Oct 2022 14:39:44 +0000 (16:39 +0200)]
Bump nightly version -> 2022-10-20

20 months agoMerge remote-tracking branch 'upstream/master' into rustup
Philipp Krones [Thu, 20 Oct 2022 14:39:27 +0000 (16:39 +0200)]
Merge remote-tracking branch 'upstream/master' into rustup

20 months agoAdd `missing_trait_methods` lint
Alex Macleod [Mon, 17 Oct 2022 21:59:27 +0000 (21:59 +0000)]
Add `missing_trait_methods` lint

20 months agoAuto merge of #9634 - royrustdev:fix_redundant_allocation, r=Manishearth
bors [Wed, 19 Oct 2022 13:58:48 +0000 (13:58 +0000)]
Auto merge of #9634 - royrustdev:fix_redundant_allocation, r=Manishearth

Update Applicability of `redundant_allocation` lint from `MachineApplicable` to `MaybeIncorrect`

This changes `redundant_allocation` lint from MachineApplicable to MaybeIncorrect

```
changelog: [`redundant_allocation]: Change Applicability from MachineApplicable to MaybeIncorrect

```

fixes #6243

---
changelog: [`redundant_allocation`]: Change Applicability from MachineApplicable to MaybeIncorrect

20 months agoUpdate Applicability of `redundant_allocation` lint from
royrustdev [Wed, 12 Oct 2022 12:31:08 +0000 (18:01 +0530)]
Update Applicability of `redundant_allocation` lint from
`MachineApplicable` to `Unspecified`

21 months agoAuto merge of #9637 - Alexendoo:unused-format-specs, r=xFrednet
bors [Mon, 17 Oct 2022 11:51:32 +0000 (11:51 +0000)]
Auto merge of #9637 - Alexendoo:unused-format-specs, r=xFrednet

Add `unused_format_specs` lint

Currently catches two cases:

An empty precision specifier:

```rust
// the same as {}
println!("{:.}", x);
```

And using formatting specs on `format_args!()`:

```rust
// prints `x.`, not `x    .`
println("{:5}.", format_args!("x"));
```

changelog: new lint: [`unused_format_specs`]

21 months agoAdd `unused_format_specs` lint
Alex Macleod [Thu, 13 Oct 2022 12:13:54 +0000 (12:13 +0000)]
Add `unused_format_specs` lint

21 months agoAuto merge of #9609 - kraktus:hexa_f32, r=giraffate
bors [Mon, 17 Oct 2022 00:46:36 +0000 (00:46 +0000)]
Auto merge of #9609 - kraktus:hexa_f32, r=giraffate

[`unnecessary_cast`] Do not lint negative hexadecimal literals when cast as floats

fix https://github.com/rust-lang/rust-clippy/issues/9603

changelog: [`unnecessary_cast`] Do not lint negative hexadecimal literals when cast as floats

21 months agoAuto merge of #9652 - kraktus:octo_89, r=xFrednet
bors [Sun, 16 Oct 2022 21:18:54 +0000 (21:18 +0000)]
Auto merge of #9652 - kraktus:octo_89, r=xFrednet

[`zero_prefixed_literal`] Do not advise to use octal form if not possible

fix https://github.com/rust-lang/rust-clippy/issues/9651

changelog: [`zero_prefixed_literal`] Do not advise to use octal form if not possible

21 months agoAuto merge of #9658 - TennyZhuang:partial-pub-fields, r=llogiq
bors [Sun, 16 Oct 2022 14:06:56 +0000 (14:06 +0000)]
Auto merge of #9658 - TennyZhuang:partial-pub-fields, r=llogiq

Add new lint `partial_pub_fields`

Signed-off-by: TennyZhuang <zty0826@gmail.com>
*Please write a short comment explaining your change (or "none" for internal only changes)*

changelog: `partial_pub_fields`: new lint to disallow partial fields of a struct be pub

Resolve #9604

21 months agofix a doctest
TennyZhuang [Sun, 16 Oct 2022 09:10:27 +0000 (17:10 +0800)]
fix a doctest

Signed-off-by: TennyZhuang <zty0826@gmail.com>
21 months agoadd many tests
TennyZhuang [Sun, 16 Oct 2022 08:57:31 +0000 (16:57 +0800)]
add many tests

Signed-off-by: TennyZhuang <zty0826@gmail.com>
21 months agofix dogfood
TennyZhuang [Sun, 16 Oct 2022 08:21:48 +0000 (16:21 +0800)]
fix dogfood

Signed-off-by: TennyZhuang <zty0826@gmail.com>
21 months agoAdd new lint `partial_pub_fields`
TennyZhuang [Sun, 16 Oct 2022 08:02:23 +0000 (16:02 +0800)]
Add new lint `partial_pub_fields`

Signed-off-by: TennyZhuang <zty0826@gmail.com>
21 months agoAuto merge of #9566 - smoelius:diagnostic-item-path, r=dswij
bors [Sun, 16 Oct 2022 05:56:19 +0000 (05:56 +0000)]
Auto merge of #9566 - smoelius:diagnostic-item-path, r=dswij

Expand internal lint `unnecessary_def_path`

This PR does essentially two things:
* Separates the internal lints into modules by pass. (`internal_lints.rs` was over 1400 lines, which is a little unruly IMHO.)
* ~Adds a new~ Expands the `unnecessary_def_path` internal lint to flag hardcoded paths to diagnostic and language items.

My understanding is that the latter is currently done by reviewers. Automating this process should make things easier for both reviewers and contributors.

I could make the first bullet a separate PR, or remove it entirely, if desired.

changelog: Add internal lint `diagnostic_item_path`

21 months agoAuto merge of #9636 - kraktus:numeric-fallback, r=dswij
bors [Sun, 16 Oct 2022 05:32:19 +0000 (05:32 +0000)]
Auto merge of #9636 - kraktus:numeric-fallback, r=dswij

[`default_numeric_fallback`] do not lint on constants

fix https://github.com/rust-lang/rust-clippy/issues/9632

changelog:[`default_numeric_fallback`] do not lint on constants

21 months agoAuto merge of #9655 - llogiq:unbox-default, r=dswij
bors [Sun, 16 Oct 2022 03:11:06 +0000 (03:11 +0000)]
Auto merge of #9655 - llogiq:unbox-default, r=dswij

fix `box-default` linting `no_std` non-boxes

This fixes #9653 by doing the check against the `Box` type correctly even if `Box` isn't there, as in `no_std` code. Thanks to `@lukas-code` for opening the issue and supplying a reproducer!

---

changelog: none

21 months agofix `box-default` linting `no_std` non-boxes
Andre Bogus [Sat, 15 Oct 2022 21:19:43 +0000 (23:19 +0200)]
fix `box-default` linting `no_std` non-boxes

21 months ago[`zero_prefixed_literal`] Do not advise to use octal form if not possible
kraktus [Sat, 15 Oct 2022 13:10:50 +0000 (15:10 +0200)]
[`zero_prefixed_literal`] Do not advise to use octal form if not possible

21 months ago`explicit_ty_bound` code golf
kraktus [Sat, 15 Oct 2022 12:57:08 +0000 (14:57 +0200)]
`explicit_ty_bound` code golf

21 months agoFormat affected files
Samuel Moelius [Sun, 9 Oct 2022 11:01:49 +0000 (07:01 -0400)]
Format affected files

21 months agoFix adjacent code
Samuel Moelius [Sat, 1 Oct 2022 08:56:55 +0000 (04:56 -0400)]
Fix adjacent code

21 months agoExpand `unnecessary_def_path` lint
Samuel Moelius [Sat, 1 Oct 2022 08:48:01 +0000 (04:48 -0400)]
Expand `unnecessary_def_path` lint

21 months agoMove some things around
Samuel Moelius [Sat, 1 Oct 2022 01:10:10 +0000 (21:10 -0400)]
Move some things around

21 months agoSeparate internal lints by pass
Samuel Moelius [Sat, 1 Oct 2022 01:10:10 +0000 (21:10 -0400)]
Separate internal lints by pass

21 months agoAuto merge of #9649 - Alexendoo:from-over-into-suggestion, r=llogiq
bors [Sat, 15 Oct 2022 08:37:11 +0000 (08:37 +0000)]
Auto merge of #9649 - Alexendoo:from-over-into-suggestion, r=llogiq

Add a suggestion and a note about orphan rules for `from_over_into`

Adds a machine applicable suggestion to convert the `Into` impl into a `From` one to `from_over_into`

Also adds a note explaining that `impl From<Local> for Foreign` is fine if the `Into` type is foreign

Closes #7444
Addresses half of #9638

changelog: [`from_over_into`] Add a suggestion and a note about orphan rules

21 months agoAdd a suggestion and a note about orphan rules for `from_over_into`
Alex Macleod [Fri, 14 Oct 2022 22:50:23 +0000 (22:50 +0000)]
Add a suggestion and a note about orphan rules for `from_over_into`

21 months agoAuto merge of #9645 - Jarcho:ptr_arg_9542, r=llogiq
bors [Fri, 14 Oct 2022 17:44:03 +0000 (17:44 +0000)]
Auto merge of #9645 - Jarcho:ptr_arg_9542, r=llogiq

Don't lint `ptr_arg` when used as an incompatible trait object

fixes #9542
changelog: [`ptr_arg`](https://rust-lang.github.io/rust-clippy/master/#ptr_arg): Don't lint when used as an incompatible trait object

21 months agoDon't lint `ptr_arg` when used as an incompatible trait object
Jason Newcomb [Fri, 14 Oct 2022 17:21:59 +0000 (13:21 -0400)]
Don't lint `ptr_arg` when used as an incompatible trait object

21 months agoAuto merge of #9643 - icecream17:patch-1, r=flip1995
bors [Fri, 14 Oct 2022 16:28:57 +0000 (16:28 +0000)]
Auto merge of #9643 - icecream17:patch-1, r=flip1995

Book: Small grammar + link a11y change

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

changelog: none

---

Very minor

For the link accessibility change, `here` and related don't provide context for screen readers who are reading a list of links.
(Random supporting google links)
https://www.w3.org/QA/Tips/noClickHere
https://usability.yale.edu/web-accessibility/articles/links

21 months agoAuto merge of #9644 - hkBst:patch-1, r=flip1995
bors [Fri, 14 Oct 2022 16:15:19 +0000 (16:15 +0000)]
Auto merge of #9644 - hkBst:patch-1, r=flip1995

add missing comma

changelog: none

21 months agoadd missing comma
Marijn Schouten [Fri, 14 Oct 2022 14:57:06 +0000 (16:57 +0200)]
add missing comma

21 months agoRemove CastCheckResult since it's unused
Michael Goulet [Wed, 14 Sep 2022 23:42:25 +0000 (23:42 +0000)]
Remove CastCheckResult since it's unused

21 months agoBook: Small grammar + link a11y change
Steven Nguyen [Fri, 14 Oct 2022 04:48:05 +0000 (23:48 -0500)]
Book: Small grammar + link a11y change

21 months agoAuto merge of #9641 - Alexendoo:sparse-registry, r=flip1995
bors [Thu, 13 Oct 2022 12:58:31 +0000 (12:58 +0000)]
Auto merge of #9641 - Alexendoo:sparse-registry, r=flip1995

Enable cargo sparse registry in CI

https://blog.rust-lang.org/2022/06/22/sparse-registry-testing.html

The initial registry update takes around 1 minute currently, so this gives quite a nice speed boost to CI build times

r? `@flip1995`

changelog: none

21 months agoEnable cargo sparse registry in CI
Alex Macleod [Thu, 13 Oct 2022 12:33:04 +0000 (12:33 +0000)]
Enable cargo sparse registry in CI

21 months agoAuto merge of #9640 - Alexendoo:edition-revisions, r=llogiq
bors [Thu, 13 Oct 2022 12:18:20 +0000 (12:18 +0000)]
Auto merge of #9640 - Alexendoo:edition-revisions, r=llogiq

Fix edition revision ui tests

#9605 had me wondering how the edition revision tests were working for `manual_assert` but not for `@nyurik,` but it turns out `manual_assert`'s tests weren't working either. I checked how `rust-lang/rust` does it and apparently it comes down to whitespace, `//[rev] edition:X` works 😬

Removes the revisions from `match_wild_err_arm` as I couldn't find any edition dependant behaviour there

r? `@llogiq`

changelog: none

21 months agoAuto merge of #9584 - royrustdev:implicit_saturating_sub, r=llogiq
bors [Thu, 13 Oct 2022 12:04:23 +0000 (12:04 +0000)]
Auto merge of #9584 - royrustdev:implicit_saturating_sub, r=llogiq

add tests in `implicit_saturating_sub` lint

This adds more tests to the `implicit_saturating_sub` lint to rule out certain false positives that have appeared in the past.

Now with those false positives out of the equation, we can move the lint to `style`.

---

changelog: promote [`implicit-saturating-sub`] to the `style` category

21 months agoAuto merge of #9600 - nyurik:inline-fmt-style, r=llogiq
bors [Thu, 13 Oct 2022 11:51:20 +0000 (11:51 +0000)]
Auto merge of #9600 - nyurik:inline-fmt-style, r=llogiq

Change uninlined_format_args into a style lint

As [previously discussed](https://github.com/rust-lang/rust-clippy/pull/9233#issuecomment-1256361205), the `uninlined_format_args` should probably be a part of the default style because `println!("{}", foo)` is not as concise or easy to understand as `println!("{foo}")`

changelog: [`uninlined_format_args`]: change to be the default `style`

21 months agoFix edition revision ui tests
Alex Macleod [Thu, 13 Oct 2022 11:40:13 +0000 (11:40 +0000)]
Fix edition revision ui tests

21 months agoAuto merge of #9590 - nyurik:fix-parens, r=Alexendoo
bors [Wed, 12 Oct 2022 22:53:48 +0000 (22:53 +0000)]
Auto merge of #9590 - nyurik:fix-parens, r=Alexendoo

Fix to_string_in_format_args in parens

Fix suggestions like

```
print!("error: something failed at {}", (Location::caller().to_string()));
```

where the parenthesis enclose some portion of the value.

Fixes #9540

changelog: [`to_string_in_format_args`]: fix incorrect fix when value is enclosed in parenthesis

21 months agoFix to_string_in_format_args in parens
Yuri Astrakhan [Tue, 4 Oct 2022 04:07:12 +0000 (00:07 -0400)]
Fix to_string_in_format_args in parens

Fix suggestions like

```
print!("error: something failed at {}", (Location::caller().to_string()));
```

where the parenthesis enclose some portion of the value.

21 months agorefactor `default_numeric_fallback`
kraktus [Wed, 12 Oct 2022 21:00:52 +0000 (23:00 +0200)]
refactor `default_numeric_fallback`

We only need to store if the literal binding has an explicit type bound or not

21 months ago`default_numeric_fallback` do not lint on constants
kraktus [Wed, 12 Oct 2022 10:04:41 +0000 (12:04 +0200)]
`default_numeric_fallback` do not lint on constants

21 months agoAuto merge of #9627 - Jarcho:ice-9625, r=xFrednet
bors [Wed, 12 Oct 2022 18:49:34 +0000 (18:49 +0000)]
Auto merge of #9627 - Jarcho:ice-9625, r=xFrednet

Use the correct type when comparing nested constants.

fixes #9625

changelog: `manual_range_contains`: fix ICE when the values are behind a reference

21 months agoFix bug in `referent_used_exactly_once`
Samuel Moelius [Tue, 11 Oct 2022 23:41:44 +0000 (19:41 -0400)]
Fix bug in `referent_used_exactly_once`

21 months agoAuto merge of #9617 - llogiq:cast-nan-to-int, r=Alexendoo
bors [Wed, 12 Oct 2022 11:48:30 +0000 (11:48 +0000)]
Auto merge of #9617 - llogiq:cast-nan-to-int, r=Alexendoo

add `cast-nan-to-int` lint

This fixes #371.

r? `@Alexendoo`

---

changelog: add [`cast-nan-to-int`] lint

21 months agoAuto merge of #9633 - royrustdev:fix_rc_buffer, r=llogiq
bors [Wed, 12 Oct 2022 11:31:38 +0000 (11:31 +0000)]
Auto merge of #9633 - royrustdev:fix_rc_buffer, r=llogiq

update Applicability of `rc_buffer` lint from `MachineApplicable` to `Unspecified`

`Unspecified`

This changes `rc_buffer` from MachineApplicable to Unspecified

```
changelog: change [`rc_buffer`] to Unspecified.
```

fixes #6241

---

changelog: change [`rc_buffer`] to Unspecified.

21 months agoadd `cast-nan-to-int` lint
Andre Bogus [Sat, 8 Oct 2022 21:33:23 +0000 (23:33 +0200)]
add `cast-nan-to-int` lint

21 months agoupdate Applicability of `rc_buffer` from `MachineApplicable` to
royrustdev [Wed, 12 Oct 2022 11:11:48 +0000 (16:41 +0530)]
update Applicability of `rc_buffer` from `MachineApplicable` to
`Unspecified`

21 months agoAuto merge of #9605 - nyurik:fix-inline-edition, r=llogiq
bors [Wed, 12 Oct 2022 07:16:23 +0000 (07:16 +0000)]
Auto merge of #9605 - nyurik:fix-inline-edition, r=llogiq

fix: uninlined_format_args shouldn't inline panic! before 2021ed

Before 2021 edition, `panic!("...")` was not treated as a format string.
Clippy autofix of `panic!("{}", foo)` into `panic!("{foo}")` is incorrect.

changelog: [`uninlined_format_args`]: Do not inline panic! macros before 2021 edition

21 months agoadd tests in `implicit_saturating_sub` lint
royrustdev [Mon, 3 Oct 2022 14:59:59 +0000 (20:29 +0530)]
add tests in `implicit_saturating_sub` lint

21 months agoHandle panic! inline_format-arg before ed2021
Yuri Astrakhan [Sat, 8 Oct 2022 08:49:00 +0000 (04:49 -0400)]
Handle panic! inline_format-arg before ed2021

21 months agoAuto merge of #9629 - est31:let_else, r=Jarcho
bors [Tue, 11 Oct 2022 14:26:04 +0000 (14:26 +0000)]
Auto merge of #9629 - est31:let_else, r=Jarcho

Replace manual let else patterns with let else

Clears the codebase from places where the lint added by #8437 is firing, by adopting let else.

changelog: none

21 months agoAuto merge of #9616 - unvalley:add-default-to-lint-groups, r=xFrednet
bors [Tue, 11 Oct 2022 08:35:12 +0000 (08:35 +0000)]
Auto merge of #9616 - unvalley:add-default-to-lint-groups, r=xFrednet

Add Default to Clippy Lints Lint groups

- related to #7958

This PR adds a default (reset) button to Clippy Lints Lint groups. (change for website)
[The page](https://rust-lang.github.io/rust-clippy/master/index.html) sets only `Deprecated` to false by default.
Certainly it is easy to set only `deprecated` to false, but it may be a bit lazy for beginners.

https://user-images.githubusercontent.com/38400669/194831117-3ade7e0d-c4de-4189-9daf-3be8ea3cdd18.mov

changelog: none

21 months agoAuto merge of #9572 - Nilstrieb:as-ptr-cast-mut, r=dswij
bors [Tue, 11 Oct 2022 08:08:17 +0000 (08:08 +0000)]
Auto merge of #9572 - Nilstrieb:as-ptr-cast-mut, r=dswij

Add `as_ptr_cast_mut` lint

This lint detects calls to a `&self`-taking `as_ptr` method, where the result is then immediately cast to a `*mut T`. Code like this is probably invalid, as that pointer will not have write permissions, and `*mut T` is usually used to write through.

Examples of broken code with this pattern:
https://miri.saethlin.dev/ub?crate=lol_alloc&version=0.1.3
https://miri.saethlin.dev/ub?crate=sophon-wasm&version=0.19.0
https://miri.saethlin.dev/ub?crate=polars-core&version=0.24.2
https://miri.saethlin.dev/ub?crate=ach-cell&version=0.1.17

changelog: Add [`as_ptr_cast_mut`]

21 months agoReplace manual let else patterns with let else
est31 [Mon, 10 Oct 2022 20:37:42 +0000 (22:37 +0200)]
Replace manual let else patterns with let else

21 months agoUse the correct type when comparing nested constants.
Jason Newcomb [Mon, 10 Oct 2022 19:33:49 +0000 (15:33 -0400)]
Use the correct type when comparing nested constants.

21 months agofix `box-default` ignoring trait objects' types
Andre Bogus [Mon, 10 Oct 2022 11:05:07 +0000 (13:05 +0200)]
fix `box-default` ignoring trait objects' types

21 months agoFix unclosed HTML tag in clippy doc
Guillaume Gomez [Mon, 10 Oct 2022 18:45:04 +0000 (20:45 +0200)]
Fix unclosed HTML tag in clippy doc

21 months agoAuto merge of #9610 - Jarcho:fix-9608, r=Alexendoo
bors [Mon, 10 Oct 2022 12:29:15 +0000 (12:29 +0000)]
Auto merge of #9610 - Jarcho:fix-9608, r=Alexendoo

Don't suggest moving tuple structs with a significant drop to late evaluation

fixes #9608

changelog: Don't suggest moving tuple structs with a significant drop to late evaluation

21 months agofix: change command order and remove waste condition
unvalley [Mon, 10 Oct 2022 09:00:15 +0000 (18:00 +0900)]
fix: change command order and remove waste condition

21 months agoRollup merge of #102868 - compiler-errors:rename-assoc-tyalias-to-ty, r=TaKO8Ki
Dylan DPC [Mon, 10 Oct 2022 08:13:43 +0000 (13:43 +0530)]
Rollup merge of #102868 - compiler-errors:rename-assoc-tyalias-to-ty, r=TaKO8Ki

Rename `AssocItemKind::TyAlias` to `AssocItemKind::Type`

Thanks `@camsteffen` for catching this in ast too, cc https://github.com/rust-lang/rust/pull/102829#issuecomment-1272649247

21 months agoRollup merge of #99696 - WaffleLapkin:uplift, r=fee1-dead
Dylan DPC [Mon, 10 Oct 2022 08:13:40 +0000 (13:43 +0530)]
Rollup merge of #99696 - WaffleLapkin:uplift, r=fee1-dead

Uplift `clippy::for_loops_over_fallibles` lint into rustc

This PR, as the title suggests, uplifts [`clippy::for_loops_over_fallibles`] lint into rustc. This lint warns for code like this:
```rust
for _ in Some(1) {}
for _ in Ok::<_, ()>(1) {}
```
i.e. directly iterating over `Option` and `Result` using `for` loop.

There are a number of suggestions that this PR adds (on top of what clippy suggested):
1. If the argument (? is there a better name for that expression) of a `for` loop is a `.next()` call, then we can suggest removing it (or rather replacing with `.by_ref()` to allow iterator being used later)
   ```rust
    for _ in iter.next() {}
    // turns into
    for _ in iter.by_ref() {}
    ```
2. (otherwise) We can suggest using `while let`, this is useful for non-iterator, iterator-like things like [async] channels
   ```rust
   for _ in rx.recv() {}
   // turns into
   while let Some(_) = rx.recv() {}
   ```
3. If the argument type is `Result<impl IntoIterator, _>` and the body has a `Result<_, _>` type, we can suggest using `?`
   ```rust
   for _ in f() {}
   // turns into
   for _ in f()? {}
   ```
4. To preserve the original behavior and clear intent, we can suggest using `if let`
   ```rust
   for _ in f() {}
   // turns into
   if let Some(_) = f() {}
   ```
(P.S. `Some` and `Ok` are interchangeable depending on the type)

I still feel that the lint wording/look is somewhat off, so I'll be happy to hear suggestions (on how to improve suggestions :D)!

Resolves #99272

[`clippy::for_loops_over_fallibles`]: https://rust-lang.github.io/rust-clippy/master/index.html#for_loops_over_fallibles

21 months agoRename AssocItemKind::TyAlias to AssocItemKind::Type
Michael Goulet [Mon, 10 Oct 2022 02:05:24 +0000 (02:05 +0000)]
Rename AssocItemKind::TyAlias to AssocItemKind::Type

21 months agoRollup merge of #102275 - Urgau:stabilize-half_open_range_patterns, r=cjgillot
Yuki Okushi [Mon, 10 Oct 2022 01:23:03 +0000 (10:23 +0900)]
Rollup merge of #102275 - Urgau:stabilize-half_open_range_patterns, r=cjgillot

Stabilize `half_open_range_patterns`

This PR stabilize `feature(half_open_range_patterns)`:
```
Allows using `..=X` as a pattern.
```

And adds a new `feature(half_open_range_patterns_in_slices)` for the slice part, https://github.com/rust-lang/rust/pull/102275#issuecomment-1267422806.

The FCP was completed in https://github.com/rust-lang/rust/issues/67264.

21 months agoRollup merge of #102829 - compiler-errors:rename-impl-item-kind, r=TaKO8Ki
Yuki Okushi [Sun, 9 Oct 2022 15:09:42 +0000 (00:09 +0900)]
Rollup merge of #102829 - compiler-errors:rename-impl-item-kind, r=TaKO8Ki

rename `ImplItemKind::TyAlias` to `ImplItemKind::Type`

The naming of this variant seems inconsistent given that this is not really a "type alias", and the associated type variant for `TraitItemKind` is just called `Type`.

21 months agofeat: add Default to Lint groups
unvalley [Sun, 9 Oct 2022 14:35:52 +0000 (23:35 +0900)]
feat: add Default to Lint groups

21 months agodeprecate `clippy::for_loops_over_fallibles`
Maybe Waffle [Fri, 7 Oct 2022 17:08:29 +0000 (17:08 +0000)]
deprecate `clippy::for_loops_over_fallibles`

21 months agofixup lint name
Maybe Waffle [Fri, 7 Oct 2022 15:59:39 +0000 (15:59 +0000)]
fixup lint name

21 months agoFix clippy tests that trigger `for_loop_over_fallibles` lint
Maybe Waffle [Thu, 25 Aug 2022 10:03:13 +0000 (14:03 +0400)]
Fix clippy tests that trigger `for_loop_over_fallibles` lint

21 months agoImplItemKind::TyAlias => ImplItemKind::Type
Michael Goulet [Sun, 9 Oct 2022 07:09:57 +0000 (07:09 +0000)]
ImplItemKind::TyAlias => ImplItemKind::Type

21 months agoAuto merge of #9386 - smoelius:further-enhance-needless-borrow, r=Jarcho
bors [Sat, 8 Oct 2022 21:24:54 +0000 (21:24 +0000)]
Auto merge of #9386 - smoelius:further-enhance-needless-borrow, r=Jarcho

Further enhance `needless_borrow`, mildly refactor `redundant_clone`

This PR does the following:
* Moves some code from `redundant_clone` into a new `clippy_utils` module called `mir`, and wraps that code in a function called `dropped_without_further_use`.
* Relaxes the "is copyable" condition condition from #9136 by also suggesting to remove borrows from values dropped without further use. The changes involve the just mentioned function.
* Separates `redundant_clone` into modules.

Strictly speaking, the last bullet is independent of the others. `redundant_clone` is somewhat hairy, IMO. Separating it into modules makes it slightly less so, by helping to delineate what depends upon what.

I've tried to break everything up into digestible commits.

r? `@Jarcho`

(`@Jarcho` I hope you don't mind.)

changelog: continuation of #9136

21 months agoAuto merge of #9451 - kraktus:manual_filter2, r=dswij
bors [Sat, 8 Oct 2022 15:58:51 +0000 (15:58 +0000)]
Auto merge of #9451 - kraktus:manual_filter2, r=dswij

Add `manual_filter` lint for `Option`

Share much of its implementation with `manual_map` and should greatly benefit from its previous feedback.
I'm sure it's possible to even more refactor both and would gladly take input on that as well as any clippy idiomatic usage, since this is my first lint addition.

I've added the lint to the complexity section for now, I don't know if every new lint needs to go in nursery first.

The matching could be expanded to more than `Some(<value>)` to lint on arbitrary struct matching inside the `Some` but I've left it like it was for `manual_map` for now. `needless_match::pat_same_as_expr` provides a more generic match example.

close https://github.com/rust-lang/rust-clippy/issues/8822

changelog: Add lint [`manual_filter`] for `Option`

21 months agoDon't suggest moving tuple structs with a significant drop to late evaluation.
Jason Newcomb [Sat, 8 Oct 2022 15:23:05 +0000 (11:23 -0400)]
Don't suggest moving tuple structs with a significant drop to late evaluation.

21 months ago[`unnecessary_cast`] Do not lint negative hexadecimal literals when cast as float
kraktus [Sat, 8 Oct 2022 14:15:18 +0000 (16:15 +0200)]
[`unnecessary_cast`] Do not lint negative hexadecimal literals when cast as float

Floats cannot be expressed as hexadecimal literals

21 months agoRollup merge of #102675 - ouz-a:mir-technical-debt, r=oli-obk
Matthias Krüger [Sat, 8 Oct 2022 12:38:18 +0000 (14:38 +0200)]
Rollup merge of #102675 - ouz-a:mir-technical-debt, r=oli-obk

Remove `mir::CastKind::Misc`

As discussed in #97649 `mir::CastKind::Misc` is not clear, this PR addresses that by creating a new enum variant for every valid cast.

r? ````@oli-obk````

21 months agoStabilize half_open_range_patterns
Urgau [Sat, 24 Sep 2022 15:22:04 +0000 (17:22 +0200)]
Stabilize half_open_range_patterns

21 months agoAuto merge of #102091 - RalfJung:const_err, r=oli-obk
bors [Fri, 7 Oct 2022 20:50:51 +0000 (20:50 +0000)]
Auto merge of #102091 - RalfJung:const_err, r=oli-obk

make const_err a hard error

This lint has been deny-by-default with future incompat wording since [Rust 1.51](https://github.com/rust-lang/rust/pull/80394) and the stable release of this week starts showing it in cargo's future compat reports. I can't wait to finally get rid of at least some of the mess in our const-err-reporting-code. ;)

r? `@oli-obk`
Fixes https://github.com/rust-lang/rust/issues/71800
Fixes https://github.com/rust-lang/rust/issues/100114

21 months agomake const_err a hard error
Ralf Jung [Wed, 21 Sep 2022 11:05:20 +0000 (13:05 +0200)]
make const_err a hard error

21 months agoAuto merge of #9585 - rust-lang:extend-box-default, r=Alexendoo
bors [Fri, 7 Oct 2022 14:49:54 +0000 (14:49 +0000)]
Auto merge of #9585 - rust-lang:extend-box-default, r=Alexendoo

extend `box-default` lint, add suggestion

This extends the recently added `box-default` lint to also cover `Box::new(vec![])`, `Box::new(String::from(""))` and `Box::new(Vec::from([]))`. Also the lint now suggests a suitable replacement. I did not find a simple way to check whether the type is fully determined by the outside, so I at least checked for some variations to remove the turbofish in those cases.

---

changelog: none

21 months agoChange InferCtxtBuilder from enter to build
Cameron Steffen [Tue, 20 Sep 2022 03:03:59 +0000 (22:03 -0500)]
Change InferCtxtBuilder from enter to build

21 months agoIntroduce TypeErrCtxt
Cameron Steffen [Fri, 9 Sep 2022 20:08:06 +0000 (15:08 -0500)]
Introduce TypeErrCtxt

TypeErrCtxt optionally has a TypeckResults so that InferCtxt doesn't
need to.

21 months agoFix adjacent code
Samuel Moelius [Fri, 7 Oct 2022 09:07:09 +0000 (05:07 -0400)]
Fix adjacent code

21 months ago`needless_borrow` uses `used_exactly_once`
Samuel Moelius [Thu, 25 Aug 2022 00:14:21 +0000 (00:14 +0000)]
`needless_borrow` uses `used_exactly_once`

21 months agoAuto merge of #9595 - Alexendoo:author-let-chains, r=Jarcho
bors [Fri, 7 Oct 2022 02:52:47 +0000 (02:52 +0000)]
Auto merge of #9595 - Alexendoo:author-let-chains, r=Jarcho

Replace if_chain with let chains in `clippy::author` output

Should help nudge new contributors towards let chains

changelog: none