]> git.lizzy.rs Git - rust.git/log
rust.git
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 agoEnable test no_std_main_recursion
alex-semenyuk [Sat, 15 Oct 2022 20:52:40 +0000 (23:52 +0300)]
Enable test no_std_main_recursion

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 agoFix allow_attributes_without_reason applying to external crate macros
Cody [Tue, 11 Oct 2022 04:37:09 +0000 (23:37 -0500)]
Fix allow_attributes_without_reason applying to external crate macros

Previously the `clippy::allow_attributes_without_reason` lint would
apply to external crate macros. Many macros in the Rust ecosystem
include these `allow` attributes without adding a reason, making this
lint pretty much unusable in any sizable Rust project.

This commit fixes that by adding a check to the lint if the attribute is
from an external crate macro and returning early.

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

21 months agoAuto merge of #9601 - evantypanski:et/issue9575, r=Manishearth
bors [Thu, 6 Oct 2022 21:55:56 +0000 (21:55 +0000)]
Auto merge of #9601 - evantypanski:et/issue9575, r=Manishearth

[`match_single_binding`] Add curlies for more cases to fix suggestion causes error

Fixes #9575

changelog: [`match_single_binding`]: Add curlies for scrutinees with side effects for more cases

21 months agoFix flipped variable that made it through
Evan Typanski [Thu, 6 Oct 2022 19:36:28 +0000 (15:36 -0400)]
Fix flipped variable that made it through

21 months agoAdd curlies to scrutinees with side effects
Evan Typanski [Thu, 6 Oct 2022 19:14:55 +0000 (15:14 -0400)]
Add curlies to scrutinees with side effects

21 months agoChange uninlined_format_args into a style lint
Yuri Astrakhan [Thu, 6 Oct 2022 16:12:55 +0000 (12:12 -0400)]
Change uninlined_format_args into a style lint

21 months agoMerge commit '8f1ebdd18bdecc621f16baaf779898cc08cc2766' into clippyup
Philipp Krones [Thu, 6 Oct 2022 15:41:53 +0000 (17:41 +0200)]
Merge commit '8f1ebdd18bdecc621f16baaf779898cc08cc2766' into clippyup

21 months agoAuto merge of #9593 - Andy-Python-Programmer:master, r=llogiq
bors [Thu, 6 Oct 2022 14:39:26 +0000 (14:39 +0000)]
Auto merge of #9593 - Andy-Python-Programmer:master, r=llogiq

lint::unsafe_removed_from_name: fix false positive result when allowed

changelog: [`unsafe_removed_from_name`] Fix allowing on imports produces a false positive on `useless_attribute`.

Fixes: #9197
Signed-off-by: Andy-Python-Programmer <andypythonappdeveloper@gmail.com>
21 months agoAuto merge of #9599 - nyurik:inline-crash, r=flip1995
bors [Thu, 6 Oct 2022 14:12:29 +0000 (14:12 +0000)]
Auto merge of #9599 - nyurik:inline-crash, r=flip1995

Add a temporary workaround for  multiline formart arg inlining

per suggestion in
https://github.com/rust-lang/rust/pull/102729#discussion_r988990080

workaround for an internal crash when handling multi-line format argument inlining.

changelog: none

(no point for changelog because it is still a new lint being introduced)

21 months agoextend `box-default` lint, add suggestion
Andre Bogus [Mon, 3 Oct 2022 15:29:38 +0000 (17:29 +0200)]
extend `box-default` lint, add suggestion

21 months agoAdd a temporary workaround for multiline formart arg inlining
Yuri Astrakhan [Thu, 6 Oct 2022 13:12:37 +0000 (09:12 -0400)]
Add a temporary workaround for  multiline formart arg inlining

per suggestion in
https://github.com/rust-lang/rust/pull/102729#discussion_r988990080

workaround for an internal crash when handling multi-line format
argument inlining.

21 months agoAuto merge of #9598 - nyurik:fix-comment, r=Alexendoo
bors [Thu, 6 Oct 2022 12:56:27 +0000 (12:56 +0000)]
Auto merge of #9598 - nyurik:fix-comment, r=Alexendoo

lint: fix a few comments

minor cleanup per `@Alexendoo` [comment](https://github.com/rust-lang/rust-clippy/pull/9586#discussion_r988991976)

changelog: none

21 months agolint: fix a few comments
Yuri Astrakhan [Thu, 6 Oct 2022 12:54:07 +0000 (08:54 -0400)]
lint: fix a few comments

21 months agoRemove `mir::CastKind::Misc`
ouz-a [Tue, 4 Oct 2022 18:39:43 +0000 (21:39 +0300)]
Remove `mir::CastKind::Misc`

21 months agoMerge commit 'ac0e10aa68325235069a842f47499852b2dee79e' into clippyup
Philipp Krones [Thu, 6 Oct 2022 07:44:38 +0000 (09:44 +0200)]
Merge commit 'ac0e10aa68325235069a842f47499852b2dee79e' into clippyup

21 months agoAuto merge of #9596 - flip1995:rustup, r=flip1995
bors [Thu, 6 Oct 2022 07:23:08 +0000 (07:23 +0000)]
Auto merge of #9596 - flip1995:rustup, r=flip1995

Rustup

r? `@ghost`

changelog: none

21 months agoBump nightly version -> 2022-10-06
Philipp Krones [Thu, 6 Oct 2022 07:19:51 +0000 (09:19 +0200)]
Bump nightly version -> 2022-10-06

21 months agoMerge remote-tracking branch 'upstream/master' into rustup
Philipp Krones [Thu, 6 Oct 2022 07:19:29 +0000 (09:19 +0200)]
Merge remote-tracking branch 'upstream/master' into rustup

21 months agoReplace if_chain with let chains in `clippy::author` output
Alex Macleod [Wed, 5 Oct 2022 17:17:57 +0000 (17:17 +0000)]
Replace if_chain with let chains in `clippy::author` output

21 months agoAuto merge of #9586 - Alexendoo:format-args-commas, r=Manishearth
bors [Wed, 5 Oct 2022 16:27:03 +0000 (16:27 +0000)]
Auto merge of #9586 - Alexendoo:format-args-commas, r=Manishearth

FormatArgsExpn: Find comma spans and ignore weird proc macro spans

Fixes the following cases:

A missing `, 1` from the `expect_fun_call` suggestion:

```rust
Some(()).expect(&format!("{x} {}", 1));
```
```
warning: use of `expect` followed by a function call
 --> t.rs:7:14
  |
7 |     Some(()).expect(&format!("{x} {}", 1));
  |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| panic!("{x} {}"))`
```

The suggestion removing from the comma in the comment rather than the one after the format string:

```rust
println!(
    "{}",
    // a comment, with a comma in it
    x
);
```
```
warning: variables can be used directly in the `format!` string
  --> t.rs:9:5
   |
9  | /     println!(
10 | |         "{}",
11 | |         // a comment, with a comma in it
12 | |         x
13 | |     );
   | |_____^
   |
help: change this to
   |
10 ~         "{x}",
11 ~         // a comment
   |
```

It also no longer accepts expansions where a format string or argument has a "weird" proc macro span, that is one where the literal/expression it outputs has the span of one of its inputs. Kind of like a `format_args` specific `clippy_utils::is_from_proc_macro`, e.g. `format!(indoc! {" ... "})`

changelog: [`expect_fun_call`]: Fix suggestion for `format!` using captured variables
changelog: [`print_literal`], [`write_literal`], [`uninlined_format_args`]: Fix suggestion when following a comment including a comma

21 months agoFormatArgsExpn: Find comma spans and ignore weird proc macro spans
Alex Macleod [Wed, 5 Oct 2022 16:10:52 +0000 (16:10 +0000)]
FormatArgsExpn: Find comma spans and ignore weird proc macro spans

21 months agoAuto merge of #9495 - Alexendoo:disallowed-macros, r=Jarcho
bors [Wed, 5 Oct 2022 14:49:31 +0000 (14:49 +0000)]
Auto merge of #9495 - Alexendoo:disallowed-macros, r=Jarcho

Add `disallowed_macros` lint

Closes #7790
Fixes #9558

`clippy_utils::def_path_res` already resolved macro definitions which is nice, it just needed a tweak to be able to disambiguate e.g. `std::vec` the module & `std::vec` the macro, and `serde::Serialize` the trait & `serde::Serialize` the derive macro

changelog: new lint: [`disallowed_macros`]
changelog: [`disallowed_methods`], [`disallowed_types`]: Fix false negative when a type/fn/macro share the same path

21 months agoAdd `disallowed_macros` lint
Alex Macleod [Wed, 5 Oct 2022 13:44:01 +0000 (13:44 +0000)]
Add `disallowed_macros` lint