Commit graph

18797 commits

Author SHA1 Message Date
J-ZhengLi
0e961cd854 fix suggestion error with attr macros 2024-01-18 18:53:41 +08:00
J-ZhengLi
9fe7c6a7ec finally came up with some repro code 2024-01-18 17:56:35 +08:00
bors
ecb0311fcc Auto merge of #12149 - GuillaumeGomez:core-std-suggestions, r=llogiq
Correctly suggest std or core path depending if this is a `no_std` crate

A few lints emit suggestions using `std` paths whether or not this is a `no_std` crate, which is an issue when running `rustfix` afterwards. So in case this is an item that is defined in both `std` and `core`, we need to check if the crate is `no_std` to emit the right path.

r? `@llogiq`

changelog: Correctly suggest std or core path depending if this is a `no_std` crate
2024-01-16 06:26:29 +00:00
Guillaume Gomez
874f851ac5 Use std_or_core instead of doing check by hand every time 2024-01-15 20:53:00 +01:00
bors
771a2a965c Auto merge of #11926 - edmorley:update-default-doc_valid_idents, r=blyxyas
Add "OpenTelemetry" to default `doc_valid_idents`

The OpenTelemetry project's name is all one word (see https://opentelemetry.io), so currently triggers a false positive in the `doc_markdown` lint.

The project is increasing rapidly in popularity, so it seems like a worthy contender for inclusion in the default `doc_valid_idents` configuration.

I've also moved the existing "OpenDNS" entry earlier in the list, to restore the alphabetical ordering of that "Open*" row.

The docs changes were generated using `cargo collect-metadata`.

changelog: [`doc_markdown`]: Add `OpenTelemetry` to the default configuration as an allowed identifier
2024-01-15 17:38:44 +00:00
Ed Morley
a16a85030c
Add "OpenTelemetry" to default doc_valid_idents
The OpenTelemetry project's name is all one word (see https://opentelemetry.io),
so currently triggers a false positive in the `doc_markdown` lint.

The project is increasing rapidly in popularity, so it seems like a worthy
contender for inclusion in the default `doc_valid_idents` configuration.

I've also moved the existing "OpenDNS" entry earlier in the list, to restore
the alphabetical ordering of that "Open*" row.

The docs changes were generated using `cargo collect-metadata`.

changelog: [`doc_markdown`]: Add `OpenTelemetry` to the default configuration as an allowed identifier
2024-01-15 14:26:41 +00:00
bors
692f53fe8f Auto merge of #12136 - y21:issue12135, r=Jarcho
[`useless_asref`]: check that the clone receiver is the parameter

Fixes #12135

There was no check for the receiver of the `clone` call in the map closure. This makes sure that it's a path to the parameter.

changelog: [`useless_asref`]: check that the clone receiver is the closure parameter
2024-01-15 05:08:16 +00:00
bors
d6ff2d2c2d Auto merge of #12141 - samueltardieu:issue-12138, r=Jarcho
from_over_into: suggest a correct conversion to ()

changelog: [`from_over_into`]: suggest a correct conversion to `()`

Fix #12138
2024-01-15 04:32:22 +00:00
bors
37b8ae7f17 Auto merge of #12114 - talagrand:patch-1, r=Jarcho
['arc_with_non_send_sync`] documentation edits

Arc's documentation uses the term "thread"; aligning to that terminology. Fix casing of "Rc".

changelog: None
2024-01-15 04:21:37 +00:00
bors
a9fa2f5ed1 Auto merge of #12074 - ARandomDev99:12044-include-comments-while-checking-duplicate-code, r=Jarcho
Make `HirEqInterExpr::eq_block` take comments into account while checking if two blocks are equal

This PR:
- now makes `HirEqInterExpr::eq_block` take comments into account. Identical code with varying comments will no longer be considered equal.
- makes necessary adjustments to UI tests.

Closes #12044

**Lintcheck Changes**
- `match_same_arms` 53 => 52
- `if_same_then_else` 3 => 0

changelog: [`if_same_then_else`]: Blocks with different comments will no longer trigger this lint.
changelog: [`match_same_arms`]: Arms with different comments will no longer trigger this lint.
```
2024-01-15 04:06:52 +00:00
Guillaume Gomez
40a45a463f Update and add ui tests for core/std suggestions 2024-01-14 14:45:24 +01:00
Guillaume Gomez
1bcaf29e0b Correctly suggest std or core path depending if this is a no_std crate 2024-01-14 14:45:24 +01:00
y21
be5707ce1b lint on .map(|&x| x.clone()) 2024-01-13 17:46:46 +01:00
Samuel Tardieu
e025356969 from_over_into: suggest a correct conversion to () 2024-01-13 13:19:55 +01:00
bors
a71211d0b5 Auto merge of #12140 - GuillaumeGomez:improve-message-search_is_some, r=llogiq
Improve help message for `search_is_some` lint

Fixes #11681.

Like mentioned in the issue, we tend to use the formulation "consider using", which we didn't in this case. I think it clears both the confusion and also makes help message more coherent overall.

r? `@llogiq`

changelog: Improve help message for `search_is_some` lint
2024-01-12 23:48:39 +00:00
Guillaume Gomez
37947ffc40 Update ui tests for search_is_some lint 2024-01-12 22:48:30 +01:00
Guillaume Gomez
68aceeed03 Improve help message for search_is_some lint 2024-01-12 22:48:30 +01:00
bors
7eca5afd34 Auto merge of #12137 - GuillaumeGomez:fix-unconditional_recursion-false-positive, r=llogiq
Fix false positive in `PartialEq` check in `unconditional_recursion` lint

Fixes https://github.com/rust-lang/rust-clippy/issues/12133.

We needed to check for the type of the previous element <del>in case it's a field</del>.

EDIT: After some extra thoughts, no need to check if it's a field, just if it's the same type as `Self`.

r? `@llogiq`

changelog: Fix false positive in `PartialEq` check in `unconditional_recursion` lint
2024-01-12 18:30:11 +00:00
Guillaume Gomez
132667288a Add regression ui test for unconditional_recursion lint on PartialEq 2024-01-12 17:37:09 +01:00
Guillaume Gomez
c8cd09a8e6 Fix false positive in PartialEq check in unconditional_recursion lint 2024-01-12 17:37:09 +01:00
y21
153b83f61b [useless_asref]: check that the clone receiver is the local 2024-01-12 13:39:42 +01:00
bors
88b5d519a1 Auto merge of #12129 - GuillaumeGomez:map-clone-copy, r=llogiq
Fix suggestion for `map_clone` lint on types implementing `Copy`

Follow-up of https://github.com/rust-lang/rust-clippy/pull/12104.

It was missing this check to suggest the correct method.

r? `@llogiq`

changelog: Fix suggestion for `map_clone` lint on types implementing `Copy`
2024-01-11 23:28:12 +00:00
bors
c5371342c2 Auto merge of #12132 - blyxyas:not-on-vacation-again, r=xFrednet
I'm not on vacation (again)

A few weeks ago I opened #12011 removing me from `users_on_vacation`, it got merged. The subtree sync reverted this change (weirdly)

changelog: none

r? `@xFrednet`
2024-01-11 20:20:32 +00:00
blyxyas
85364e5307
I'm not on vacation (again) 2024-01-11 20:52:07 +01:00
Guillaume Gomez
74db4b7f6d Add new ui tests for map_clone lint on types implementing Copy 2024-01-11 17:44:07 +01:00
Guillaume Gomez
82841aada4 Fix suggestion for map_clone on types implementing Copy 2024-01-11 17:44:07 +01:00
bors
26ac6aab02 Auto merge of #12130 - flip1995:rustup, r=flip1995
Rustup

r? `@ghost`

changelog: none
2024-01-11 16:25:11 +00:00
Philipp Krones
7d8b6e451e
Bump nightly version -> 2024-01-11 2024-01-11 17:20:07 +01:00
Philipp Krones
2c0cea7cbc
Merge remote-tracking branch 'upstream/master' into rustup 2024-01-11 17:19:53 +01:00
bors
87ff58d1eb Auto merge of #12127 - giraffate:remove_giraffate_from_the_reviewer_rotation, r=flip1995
Remove giraffate from the reviewer rotation

I've been less active in Clippy recently because I'm so busy that I don't have time for maintaining Clippy in my spare time. So, I remove myself from the reviewer rotation once. I hope to come back again.

I'll reassign the PRs later.

changelog: none
2024-01-11 14:23:03 +00:00
Takayuki Nakata
31a27ed3c2 Remove giraffate from the reviewer rotation 2024-01-11 18:17:05 +09:00
bors
e899684254 Auto merge of #12105 - GuillaumeGomez:useless-asf-extension, r=llogiq
Extend `useless_asref` lint on `map(clone)`

If you have code like:

```rust
Some(String::new()).as_ref().map(Clone::clone)
```

the `as_ref` call is unneeded.

Interestingly enough, this lint and `map_clone` are starting to share a same "space" where both lints warn about different things for the same code. Not sure what's the policy about such cases though...

r? `@llogiq`

changelog: Extend `useless_asref` lint on `map(clone)`
2024-01-10 01:13:42 +00:00
Nicholas Nethercote
beeaee9785 Rename consuming chaining methods on DiagnosticBuilder.
In #119606 I added them and used a `_mv` suffix, but that wasn't great.

A `with_` prefix has three different existing uses.
- Constructors, e.g. `Vec::with_capacity`.
- Wrappers that provide an environment to execute some code, e.g.
  `with_session_globals`.
- Consuming chaining methods, e.g. `Span::with_{lo,hi,ctxt}`.

The third case is exactly what we want, so this commit changes
`DiagnosticBuilder::foo_mv` to `DiagnosticBuilder::with_foo`.

Thanks to @compiler-errors for the suggestion.
2024-01-10 07:40:00 +11:00
Guillaume Gomez
f7ef9a6f1f Fix dogfood and add code comments 2024-01-09 18:03:55 +01:00
Guillaume Gomez
103e8881c6 Add tests to ensure that map_clone is not emitted if as_ref().clone() is present 2024-01-09 17:39:51 +01:00
Guillaume Gomez
83ae5edd50 Don't lint with map_clone if current type is Option or Result and method call is as_ref. 2024-01-09 17:39:51 +01:00
Guillaume Gomez
e90eea7894 Clean up code in map_clone and useless_asref lints 2024-01-09 17:39:36 +01:00
Guillaume Gomez
8791a28c4a Also handle Result type for map_clone lint 2024-01-09 16:35:40 +01:00
Eugene
c2d071c11c
Documentation edits for arc_with_non_send_sync
Arc's documentation uses the term "thread", aligning to that terminology. Fix typo in "Rc".
2024-01-09 06:50:17 -08:00
Guillaume Gomez
cdd96bc662 Update ui tests for useless_asref lint extension 2024-01-09 14:14:29 +01:00
Guillaume Gomez
4ab6924bca Extend useless_asref lint on map(clone) 2024-01-09 14:09:00 +01:00
Michael Goulet
89f511e4dd Rustdoc and Clippy stop misusing Key for Ty -> (adt) DefId 2024-01-08 20:30:10 +00:00
bors
3b8323d790 Auto merge of #12049 - cocodery:fix/issue#11243, r=Alexendoo
fix/issue#11243: allow 3-digit-grouped binary in non_octal_unix_permissions

fixes [Issue#11243](https://github.com/rust-lang/rust-clippy/issues/11243)

Issue#11243 suggest lint `non_octal_unix_permissions` should not report binary format literal unix permissions as an error, and we think binary format is a good way to understand these permissions.

To solve this problem, we need to add check for binary literal, which is written in function `check_binary_unix_permissions` , only `binary, 3 groups and each group length equals to 3` is a legal format.

changelog: [`non_octal_unix_permissions`]: Add check for binary format literal unix permissions like 0b111_111_111
2024-01-08 19:09:42 +00:00
Nicholas Nethercote
122520d80c Make DiagnosticBuilder::emit consuming.
This works for most of its call sites. This is nice, because `emit` very
much makes sense as a consuming operation -- indeed,
`DiagnosticBuilderState` exists to ensure no diagnostic is emitted
twice, but it uses runtime checks.

For the small number of call sites where a consuming emit doesn't work,
the commit adds `DiagnosticBuilder::emit_without_consuming`. (This will
be removed in subsequent commits.)

Likewise, `emit_unless` becomes consuming. And `delay_as_bug` becomes
consuming, while `delay_as_bug_without_consuming` is added (which will
also be removed in subsequent commits.)

All this requires significant changes to `DiagnosticBuilder`'s chaining
methods. Currently `DiagnosticBuilder` method chaining uses a
non-consuming `&mut self -> &mut Self` style, which allows chaining to
be used when the chain ends in `emit()`, like so:
```
    struct_err(msg).span(span).emit();
```
But it doesn't work when producing a `DiagnosticBuilder` value,
requiring this:
```
    let mut err = self.struct_err(msg);
    err.span(span);
    err
```
This style of chaining won't work with consuming `emit` though. For
that, we need to use to a `self -> Self` style. That also would allow
`DiagnosticBuilder` production to be chained, e.g.:
```
    self.struct_err(msg).span(span)
```
However, removing the `&mut self -> &mut Self` style would require that
individual modifications of a `DiagnosticBuilder` go from this:
```
    err.span(span);
```
to this:
```
    err = err.span(span);
```
There are *many* such places. I have a high tolerance for tedious
refactorings, but even I gave up after a long time trying to convert
them all.

Instead, this commit has it both ways: the existing `&mut self -> Self`
chaining methods are kept, and new `self -> Self` chaining methods are
added, all of which have a `_mv` suffix (short for "move"). Changes to
the existing `forward!` macro lets this happen with very little
additional boilerplate code. I chose to add the suffix to the new
chaining methods rather than the existing ones, because the number of
changes required is much smaller that way.

This doubled chainging is a bit clumsy, but I think it is worthwhile
because it allows a *lot* of good things to subsequently happen. In this
commit, there are many `mut` qualifiers removed in places where
diagnostics are emitted without being modified. In subsequent commits:
- chaining can be used more, making the code more concise;
- more use of chaining also permits the removal of redundant diagnostic
  APIs like `struct_err_with_code`, which can be replaced easily with
  `struct_err` + `code_mv`;
- `emit_without_diagnostic` can be removed, which simplifies a lot of
  machinery, removing the need for `DiagnosticBuilderState`.
2024-01-08 15:24:49 +11:00
bors
7fbaba856b Auto merge of #12080 - PartiallyTyped:12058, r=xFrednet
Fixed ICE introduced in #12004

Issue: in https://github.com/rust-lang/rust-clippy/pull/12004, we emit a lint for `filter(Option::is_some)`. If the
parent expression is a `.map` we don't emit that lint as there exists a
more specialized lint for that.

The ICE introduced in https://github.com/rust-lang/rust-clippy/pull/12004 is a consequence of the assumption that a
parent expression after a filter would be a method call with the filter
call being the receiver. However, it is entirely possible to have a
closure of the form

```
|| { vec![Some(1), None].into_iter().filter(Option::is_some) }
```
The previous implementation looked at the parent expression; namely the
closure, and tried to check the parameters by indexing [0] on an empty
list.

This commit is an overhaul of the lint with significantly more FP tests
and checks.

Impl details:

1. We verify that the filter method we are in is a proper trait method
   to avoid FPs.
2. We check that the parent expression is not a map by checking whether
   it exists; if is a trait method; and then a method call.
3. We check that we don't have comments in the span.
4. We verify that we are in an Iterator of Option and Result.
5. We check the contents of the filter.
   1. For closures we peel it. If it is not a single expression, we don't
     lint. We then try again by checking the peeled expression.
   2. For paths, we do a typecheck to avoid FPs for types that impl
     functions with the same names.
   3. For calls, we verify the type, via the path, and that the param of
     the closure is the single argument to the call.
   4. For method calls we verify that the receiver is the parameter of
     the closure. Since we handle single, non-block exprs, the
     parameter can't be shadowed, so no FP.

This commit also adds additional FP tests.

Fixes: #12058

Adding `@xFrednet` as you've the most context for this as you reviewed it last time.

`@rustbot` r? `@xFrednet`

---

changelog: none
(Will be backported and therefore don't effect stable)
2024-01-07 17:21:28 +00:00
Quinn Sinclair
bbadce9ec0 Fixed ICE introduced in #12004
Issue: in #12004, we emit a lint for `filter(Option::is_some)`. If the
parent expression is a `.map` we don't emit that lint as there exists a
more specialized lint for that.

The ICE introduced in #12004 is a consequence of the assumption that a
parent expression after a filter would be a method call with the filter
call being the receiver. However, it is entirely possible to have a
closure of the form

```
|| { vec![Some(1), None].into_iter().filter(Option::is_some) }
```
The previous implementation looked at the parent expression; namely the
closure, and tried to check the parameters by indexing [0] on an empty
list.

This commit is an overhaul of the lint with significantly more FP tests
and checks.

Impl details:

1. We verify that the filter method we are in is a proper trait method
   to avoid FPs.
2. We check that the parent expression is not a map by checking whether
   it exists; if is a trait method; and then a method call.
3. We check that we don't have comments in the span.
4. We verify that we are in an Iterator of Option and Result.
5. We check the contents of the filter.
  1. For closures we peel it. If it is not a single expression, we don't
     lint.
  2. For paths, we do a typecheck to avoid FPs for types that impl
     functions with the same names.
  3. For calls, we verify the type, via the path, and that the param of
     the closure is the single argument to the call.
  4. For method calls we verify that the receiver is the parameter of
     the closure. Since we handle single, non-block exprs, the
     parameter can't be shadowed, so no FP.

This commit also adds additional FP tests.
2024-01-07 17:11:34 +02:00
cocodery
a843996e81 Simplify check function, weirdly binary format literals happen not often 2024-01-07 22:35:21 +08:00
bors
f37e7f3585 Auto merge of #12109 - GuillaumeGomez:map-clone-call, r=llogiq
Handle "calls" inside the closure as well in `map_clone` lint

Follow-up of https://github.com/rust-lang/rust-clippy/pull/12104.

I just realized that I didn't handle the case where the `clone` method was made as a call and not a method call.

r? `@llogiq`

changelog: Handle "calls" inside the closure as well in `map_clone` lint
2024-01-07 14:23:02 +00:00
bors
adc5bc93fc Auto merge of #12108 - samueltardieu:issue-12103, r=xFrednet
Do not suggest `bool::then()` and `bool::then_some` in `const` contexts

Fix #12103

changelog: [`if_then_some_else_none`]: Do not trigger in `const` contexts
2024-01-07 13:49:58 +00:00
Guillaume Gomez
f66e940c88 Update ui test for map_clone lint 2024-01-07 13:24:52 +01:00