Commit graph

8238 commits

Author SHA1 Message Date
y21
6807977153 also check for coroutines 2024-02-05 15:41:59 +01:00
Matthias Krüger
d13ce192c9 Rollup merge of #116284 - RalfJung:no-nan-match, r=cjgillot
make matching on NaN a hard error, and remove the rest of illegal_floating_point_literal_pattern

These arms would never be hit anyway, so the pattern makes little sense. We have had a future-compat lint against float matches in general for a *long* time, so I hope we can get away with immediately making this a hard error.

This is part of implementing https://github.com/rust-lang/rfcs/pull/3535.

Closes https://github.com/rust-lang/rust/issues/41620 by removing the lint.

https://github.com/rust-lang/reference/pull/1456 updates the reference to match.
2024-02-05 11:07:26 +01:00
y21
7c3908f86c [redundant_locals]: take by-value closure captures into account 2024-02-04 20:19:27 +01:00
bors
34e4c9fa4a Auto merge of #12087 - marcin-serwin:ref_as_ptr_cast, r=blyxyas
Add new lint: `ref_as_ptr`

Fixes #10130

Added new lint `ref_as_ptr` that checks for conversions from references to pointers and suggests using `std::ptr::from_{ref, mut}` instead.

The name is different than suggested in the issue (`as_ptr_cast`) since there were some other lints with similar names (`ptr_as_ptr`, `borrow_as_ptr`) and I wanted to follow the convention.

Note that this lint conflicts with the `borrow_as_ptr` lint in the sense that it recommends changing `&foo as *const _` to `std::ptr::from_ref(&foo)` instead of `std::ptr::addr_of!(foo)`. Personally, I think the former is more readable and, in contrast to `addr_of` macro, can be also applied to temporaries (cf. #9884).

---

changelog: New lint: [`ref_as_ptr`]
[#12087](https://github.com/rust-lang/rust-clippy/pull/12087)
2024-02-04 17:07:18 +00:00
Marcin Serwin
a3baebcb31
Add ref_as_ptr lint
Author:    Marcin Serwin <marcin.serwin0@protonmail.com>
2024-02-04 17:38:09 +01:00
bors
9fb41079ca Auto merge of #12219 - sanxiyn:labeled-block, r=blyxyas
Avoid deleting labeled blocks

Fix #11575.

changelog: [`unnecessary_operation`]: skip labeled blocks
2024-02-03 22:48:46 +00:00
Seo Sanghyeon
abced206d7
Avoid deleting labeled blocks 2024-02-03 22:35:14 +01:00
bors
c82162eb71 Auto merge of #11979 - J-ZhengLi:issue11428, r=Alexendoo
add configuration for [`wildcard_imports`] to ignore certain imports

fixes: #11428

changelog: add configuration `ignored-wildcard-imports` for lint [`wildcard_imports`]
2024-02-02 21:28:49 +00:00
bors
9b6f86643f Auto merge of #12217 - PartiallyTyped:12208, r=blyxyas
Fixed FP in `unused_io_amount` for Ok(lit), unrachable! and unwrap de…

…sugar

Fixes fp caused by linting on Ok(_) for all cases outside binding.

We introduce the following rules for match exprs.
- `panic!` and `unreachable!` are treated as consumed.
- `Ok( )` patterns outside `DotDot` and `Wild` are treated as consuming.

changelog: FP [`unused_io_amount`] when matching Ok(literal) or unreachable

fixes #12208

r? `@blyxyas`
2024-02-02 19:43:01 +00:00
J-ZhengLi
46dd8263a0 rename conf option to allowed_wildcard_imports 2024-02-02 09:22:42 +08:00
Quinn Sinclair
fe8c2e24bd Fixed FP in unused_io_amount for Ok(lit), unrachable!
We introduce the following rules for match exprs.
- `panic!` and `unreachable!` are treated as consumption.
- guard expressions in any arm imply consumption.

For match exprs:
- Lint only if exacrtly 2 non-consuming arms exist
- Lint only if one arm is an `Ok(_)` and the other is `Err(_)`

Added additional requirement that for a block return expression
that is a match, the source must be `Normal`.

changelog: FP [`unused_io_amount`] when matching Ok(literal)
2024-02-01 17:05:12 +01:00
Alex Macleod
6619e8c27d Add lint_groups_priority lint
Warns when a lint group in Cargo.toml's `[lints]` section shares the
same priority as a lint
2024-01-31 18:33:41 +00:00
Nicholas Nethercote
ae0f0fd655 Don't hash lints differently to non-lints.
`Diagnostic::keys`, which is used for hashing and equating diagnostics,
has a surprising behaviour: it ignores children, but only for lints.
This was added in #88493 to fix some duplicated diagnostics, but it
doesn't seem necessary any more.

This commit removes the special case and only four tests have changed
output, with additional errors. And those additional errors aren't
exact duplicates, they're just similar. For example, in
src/tools/clippy/tests/ui/same_name_method.rs we currently have this
error:
```
error: method's name is the same as an existing method in a trait
  --> $DIR/same_name_method.rs:75:13
   |
LL |             fn foo() {}
   |             ^^^^^^^^^^^
   |
note: existing `foo` defined here
  --> $DIR/same_name_method.rs:79:9
   |
LL |         impl T1 for S {}
   |         ^^^^^^^^^^^^^^^^
```
and with this change we also get this error:
```
error: method's name is the same as an existing method in a trait
  --> $DIR/same_name_method.rs:75:13
   |
LL |             fn foo() {}
   |             ^^^^^^^^^^^
   |
note: existing `foo` defined here
  --> $DIR/same_name_method.rs:81:9
   |
LL |         impl T2 for S {}
   |         ^^^^^^^^^^^^^^^^
```
I think printing this second argument is reasonable, possibly even
preferable to hiding it. And the other cases are similar.
2024-01-31 08:25:29 +11:00
Bruno Andreotti
3106219e24
Don't lint slice type annotations for byte strings 2024-01-30 16:17:02 -03:00
J-ZhengLi
314bddee95 add more test cases & improve docs & replace Vec with FxHashSet for segments 2024-01-30 09:38:14 +08:00
J-ZhengLi
d02df12bd5 add configuration for [wildcard_imports] to ignore certain imports 2024-01-30 09:38:14 +08:00
bors
455c07b7cc Auto merge of #12210 - GuillaumeGomez:add-regression-test-2371, r=blyxyas
Add regression ui test for #2371

Fixes #2371.

#2371 seems to already be handled correctly in the lint. This PR adds a ui regression test so we can close it.

r? `@blyxyas`

changelog: Add regression ui test for #2371
2024-01-29 22:06:58 +00:00
bors
3cd713a9f8 Auto merge of #11370 - modelflat:suggest-relpath-in-redundant-closure-for-method-calls, r=blyxyas
[fix] [`redundant_closure_for_method_calls`] Suggest relative paths for local modules

Fixes #10854.

Currently, `redundant_closure_for_method_calls` suggest incorrect paths when a method defined on a struct within inline mod is referenced (see the description in the aforementioned issue for an example; also see [this playground link](https://play.rust-lang.org/?version=stable&mode=release&edition=2021&gist=f7d3c5b2663c9bd3ab7abdb0bd38ee43) for the current-version output for the test cases added in this PR). It will now try to construct a relative path path to the module and suggest it instead.

changelog: [`redundant_closure_for_method_calls`] Fix incorrect path suggestions for types within local modules
2024-01-29 14:53:54 +00:00
Guillaume Gomez
b2f2080942 Add regression test for #2371 2024-01-29 14:53:29 +01:00
modelflat
b3d53774e7 Make redundant_closure_for_method_calls suggest relative paths
Fixes #10854.

Co-authored-by: Alejandra González <blyxyas@gmail.com>
2024-01-29 12:34:59 +01:00
bors
e7a3cb7ab0 Auto merge of #12021 - PartiallyTyped:11982, r=flip1995
FP: `needless_return_with_question_mark` with implicit Error Conversion

Return with a question mark was triggered in situations where the `?` desuraging was performing error conversion via `Into`/`From`.

The desugared `?` produces a match over an expression with type `std::ops::ControlFlow<B,C>` with `B:Result<Infallible, E:Error>` and `C:Result<_, E':Error>`, and the arms perform the conversion. The patch adds another check in the lint that checks that `E == E'`. If `E == E'`, then the `?` is indeed unnecessary.

changelog: False Positive: [`needless_return_with_question_mark`] when implicit Error Conversion occurs.

fixes: #11982
2024-01-29 09:10:02 +00:00
Quinn Sinclair
3aa2c279c8 rewrote to match only Result::err cons 2024-01-28 22:43:40 +01:00
bors
8ccf6a61ee Auto merge of #12084 - yuxqiu:manual_retain, r=Alexendoo
fix: incorrect suggestions generated by `manual_retain` lint

fixes #10393, fixes #11457, fixes #12081

#10393: In the current implementation of `manual_retain`, if the argument to the closure is matched using tuple, they are all treated as the result of a call to `map.into_iter().filter(<f>)`. However, such tuple pattern matching can also occur in many different containers that stores tuples internally. The correct approach is to apply different lint policies depending on whether the receiver of `into_iter` is a map or not.

#11457 and #12081: In the current implementation of `manual_retain`, if the argument to the closure is `Binding`, the closure will be used directly in the `retain` method, which will result in incorrect suggestion because the first argument to the `retain` closure may be of a different type. In addition, if the argument to the closure is `Ref + Binding`, the lint will simply remove the `Ref` part and use the `Binding` part as the argument to the new closure, which will lead to bad suggestion for the same reason. The correct approach is to detect each of these cases and apply lint suggestions conservatively.

changelog: [`manual_retain`] refactor and add check for various patterns
2024-01-27 18:20:06 +00:00
bors
276ce3936b Auto merge of #12083 - cocodery:fix/issue11932, r=Alexendoo
Fix/Issue11932: assert* in multi-condition after unrolling will cause lint `nonminimal_bool` emit warning

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

After `assert`, `assert_eq`, `assert_ne`, etc, assert family marcos unrolling in multi-condition expressions, lint `nonminimal_bool` will recognize whole expression as a entirety, analyze each simple condition expr of them, and check whether can simplify them.

But `assert` itself is a entirety to programmers, we don't need to lint on `assert`. This commit add check whether lint snippet contains `assert` when try to warning to an expression.

changelog: [`nonminimal_bool`] add check for condition expression
2024-01-27 17:44:24 +00:00
bors
18e1f25a9f Auto merge of #12206 - y21:issue12205, r=Alexendoo
[`never_loop`]: recognize desugared `try` blocks

Fixes #12205

The old code assumed that only blocks with an explicit label can be jumped to (using `break`). This is mostly correct except for `try` desugaring, where the `?` operator is rewritten to a `break` to that block, even without a label on the block. `Block::targeted_by_break` is a little more accurate than just checking if a block has a label in that regard, so we should just use that instead

changelog: [`never_loop`]: avoid linting when `?` is used inside of a try block
2024-01-27 17:27:38 +00:00
y21
ff5afac616 [never_loop]: recognize ? desugaring in try blocks 2024-01-27 17:07:10 +01:00
bors
85e08cd3b9 Auto merge of #12169 - GuillaumeGomez:unnecessary_result_map_or_else, r=llogiq
Add new `unnecessary_result_map_or_else` lint

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

r? `@llogiq`

changelog: Add new `unnecessary_result_map_or_else` lint
2024-01-27 12:42:18 +00:00
bors
79f10cf364 Auto merge of #12122 - andrewbanchich:tostring-impl, r=llogiq
add to_string_trait_impl lint

closes #12076

changelog: [`to_string_trait_impl`]: add lint for direct `ToString` implementations
2024-01-27 12:31:18 +00:00
bors
855aa08de5 Auto merge of #12178 - mdm:modulo-arithmetic-comparison-to-zero, r=llogiq
Don't warn about modulo arithmetic when comparing to zero

closes #12006

By default, don't warn about modulo arithmetic when comparing to zero. This behavior is configurable via `clippy.toml`.

See discussion [on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/.E2.9C.94.20Is.20issue.20.2312006.20worth.20implementing.3F)

changelog: [`modulo_arithmetic`]: By default don't lint when comparing the result of a modulo operation to zero.
2024-01-27 12:22:48 +00:00
bors
8905f78832 Auto merge of #12082 - PartiallyTyped:1553, r=dswij
Fixed FP in `redundant_closure_call` when closures are passed to macros

There are cases where the closure call is needed in some macros, this in particular occurs when the closure has parameters. To handle this case, we allow the lint when there are no parameters in the closure, or the closure is outside a macro invocation.

fixes: #11274 #1553
changelog: FP: [`redundant_closure_call`] when closures with parameters are passed in macros.
2024-01-27 09:26:35 +00:00
Andrew Banchich
6d76d14565 add to_string_trait_impl lint 2024-01-26 19:28:54 -05:00
Quinn Sinclair
f58950de86 correct lint case 2024-01-26 23:48:47 +01:00
Ralf Jung
1d94cc3895 remove illegal_floating_point_literal_pattern lint 2024-01-26 17:25:02 +01:00
Matthias Krüger
57f63a3a85 Rollup merge of #120345 - flip1995:clippy-subtree-update, r=Manishearth
Clippy subtree update

r? `@Manishearth`

Closes https://github.com/rust-lang/rust-clippy/issues/12148
2024-01-26 14:43:32 +01:00
bors
8de9d8ce99 Auto merge of #12160 - GuillaumeGomez:incompatible-msrv, r=blyxyas
Warn if an item coming from more recent version than MSRV is used

Part of https://github.com/rust-lang/rust-clippy/issues/6324.

~~Currently, the lint is not working for the simple reason that the `stable` attribute is not kept in dependencies. I'll send a PR to rustc to see if they'd be okay with keeping it.~~

EDIT: There was actually a `lookup_stability` function providing this information, so all good now!

cc `@epage`

changelog: create new [`incompatible_msrv`] lint
2024-01-26 13:15:29 +00:00
Guillaume Gomez
14e15206ed Warn if an item coming from more recent version than MSRV is used 2024-01-26 14:13:02 +01:00
bors
a65fe787d6 Auto merge of #116167 - RalfJung:structural-eq, r=lcnr
remove StructuralEq trait

The documentation given for the trait is outdated: *all* function pointers implement `PartialEq` and `Eq` these days. So the `StructuralEq` trait doesn't really seem to have any reason to exist any more.

One side-effect of this PR is that we allow matching on some consts that do not implement `Eq`. However, we already allowed matching on floats and consts containing floats, so this is not new, it is just allowed in more cases now. IMO it makes no sense at all to allow float matching but also sometimes require an `Eq` instance. If we want to require `Eq` we should adjust https://github.com/rust-lang/rust/pull/115893 to check for `Eq`, and rule out float matching for good.

Fixes https://github.com/rust-lang/rust/issues/115881
2024-01-26 00:17:00 +00:00
y21
fd3e966bdd avoid linting on #[track_caller] functions in redundant_closure 2024-01-26 00:37:56 +01:00
y21
87a6300b22 add a test for rust-lang/rust-clippy#12181 2024-01-25 19:43:47 +01:00
y21
42d13f8eb0 [unconditional_recursion]: compare by types instead of DefIds 2024-01-25 19:43:47 +01:00
Philipp Krones
798865c593 Merge commit '66c29b973b3b10278bd39f4e26b08522a379c2c9' into clippy-subtree-update 2024-01-25 19:17:36 +01:00
Philipp Krones
1534e08250
Merge remote-tracking branch 'upstream/master' into rustup 2024-01-25 18:39:39 +01:00
Marc Dominik Migge
e456c28e11 Don't warn about modulo arithmetic when comparing to zero
Add lint configuration for `modulo_arithmetic`

Collect meta-data
2024-01-25 12:42:53 +01:00
y21
4780637cbc
suggest similar config option if one is found 2024-01-25 00:11:43 +01:00
bors
76a75bf145 Auto merge of #12179 - y21:issue12176, r=dswij
[`multiple_crate_versions`]: add a configuration option for allowed duplicate crates

Closes #12176

changelog: [`multiple_crate_versions`]: add a configuration option for allowed duplicate crates
2024-01-24 07:00:34 +00:00
Ralf Jung
99d8d33419 remove StructuralEq trait 2024-01-24 07:56:23 +01:00
Oli Scherer
0b6cf3b78c We don't look into static items anymore during const prop 2024-01-23 16:34:43 +00:00
Guillaume Gomez
32bbeba16b Add ui test for unnecessary_result_map_or_else 2024-01-23 16:12:56 +01:00
Nicholas Nethercote
6b359b7e1b Rename TyCtxt::struct_span_lint_hir as TyCtxt::node_span_lint. 2024-01-23 08:09:01 +11:00
Nicholas Nethercote
cf355c6e9d Rename LintContext::struct_span_lint as LintContext::span_lint. 2024-01-23 07:59:45 +11:00
bors
0b6e7e2acf Auto merge of #12183 - y21:issue12182, r=dswij
respect `#[allow]` attributes in `single_call_fn` lint

Fixes #12182

If we delay linting to `check_crate_post`, we need to use `span_lint_hir_and_then`, since otherwise it would only respect those lint level attributes at the crate root.
<sub>... maybe we can have an internal lint for this somehow?</sub>

changelog: respect `#[allow]` attributes in `single_call_fn` lint
2024-01-22 18:36:35 +00:00
bors
a8017ae131 Auto merge of #12153 - GuillaumeGomez:non-exhaustive, r=llogiq
Don't emit `derive_partial_eq_without_eq` lint if the type has the `non_exhaustive` attribute

Part of https://github.com/rust-lang/rust-clippy/issues/9063.

If a type has a field/variant with the `#[non_exhaustive]` attribute or the type itself has it, then do no emit the `derive_partial_eq_without_eq` lint.

changelog: Don't emit `derive_partial_eq_without_eq` lint if the type has the `non_exhaustive` attribute
2024-01-22 18:20:12 +00:00
Matthias Krüger
a417366d58 Rollup merge of #119710 - Nilstrieb:let-_-=-oops, r=TaKO8Ki
Improve `let_underscore_lock`

- lint if the lock was in a nested pattern
- lint if the lock is inside a `Result<Lock, _>`

addresses https://github.com/rust-lang/rust/pull/119704#discussion_r1444044745
2024-01-22 07:56:41 +01:00
y21
ad4d90b4a9 respect #[allow] attribute in single_call_fn lint 2024-01-21 15:16:29 +01:00
bors
99423e8b30 Auto merge of #12170 - GuillaumeGomez:improve-suggestions-wording, r=llogiq
Improve wording for suggestion messages

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

r? `@llogiq`

changelog: Improve wording for suggestion messages
2024-01-21 06:08:41 +00:00
y21
95a084f2eb [multiple_crate_versions]: add a configuration option for allowed duplicate dependencies 2024-01-21 03:23:41 +01:00
bors
64d08a8b1d Auto merge of #12005 - PartiallyTyped:11713, r=blyxyas
`unused_io_amount` captures `Ok(_)`s

Partial rewrite of `unused_io_amount` to lint over `Ok(_)` and `Ok(..)`.

Moved the check to `check_block` to simplify context checking for expressions and allow us to check only some expressions.

For match (expr, arms) we emit a lint for io ops used on `expr` when an arm is `Ok(_)|Ok(..)`. Also considers the cases when there are guards in the arms and `if let Ok(_) = ...` cases.

For `Ok(_)` and `Ok(..)` it emits a note indicating where the value is ignored.

changelog: False Negatives [`unused_io_amount`]: Extended `unused_io_amount` to catch `Ok(_)`s in `If let` and match exprs.

Closes #11713

r? `@giraffate`
2024-01-21 02:12:57 +00:00
Quinn Sinclair
f73879e096 unused_io_amount captures Ok(_)s
Partial rewrite of `unused_io_account` to lint over Ok(_).

Moved the check to `check_block` to simplify context checking for
expressions and allow us to check only some expressions.

For match (expr, arms) we emit a lint for io ops used on `expr` when an
arm is `Ok(_)`. Also considers the cases when there are guards in the
arms. It also captures `if let Ok(_) = ...` cases.

For `Ok(_)` it emits a note indicating where the value is ignored.

changelog: False Negatives [`unused_io_amount`]: Extended
`unused_io_amount` to catch `Ok(_)`s in `If let` and match exprs.
2024-01-21 02:49:27 +01:00
bors
73868563ed Auto merge of #12172 - samueltardieu:issue-12166, r=Alexendoo
no_effect_underscore_binding: _ prefixed variables can be used

Prefixing a variable with a `_` does not mean that it will not be used. If such a variable is used later, do not warn about the fact that its initialization does not have a side effect as this is fine.

changelog: [`no_effect_underscore_binding`]: warn only if variable is unused

Fix #12166
2024-01-21 00:01:21 +00:00
bors
fe3e6827c3 Auto merge of #12144 - blyxyas:10283-postfix, r=llogiq
Add . to end of lint lists in configuration + Fix typo in pub_underscore_fields_behavior

Fixes https://github.com/rust-lang/rust-clippy/pull/10283#issuecomment-1890600381

In the "/// Lint: " list on each configuration option, you have to end with a dot. If the lint list doesn't have a dot, the configuration won't have documentation.

This PR adds those missing dots in some of the configuration, thus also adding their documentation.

changelog: Fix bug where a lot of config documentation wasn't showing.
changelog: Fix typo in `pub_underscore_fields_behavior` (`PublicallyExported` -> `PubliclyExported`)
2024-01-20 22:58:23 +00:00
Guillaume Gomez
38d9585978 Update ui tests 2024-01-20 16:47:08 +01:00
Samuel Tardieu
6267b6ca09 no_effect_underscore_binding: _ prefixed variables can be used
Prefixing a variable with a `_` does not mean that it will not be used.
If such a variable is used later, do not warn about the fact that its
initialization does not have a side effect as this is fine.
2024-01-19 23:25:36 +01:00
bors
989ce17b55 Auto merge of #12125 - cocodery:issue12045, r=xFrednet
Fix error warning span for issue12045

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

In issue#12045, unexpected warning span occurs on attribute `#[derive(typed_builder::TypedBuilder)]`, actually the warning should underline `_lifetime`.

In the source code we can find that the original intend is to warning on `ident.span`, but in this case, `stmt.span` is unequal with `ident.span`. So, fix the nit here is fine.

Besides, `ident.span` have an accurate range than `stmt.span`.

changelog: [`no_effect_underscore_binding`]: correct warning span
2024-01-19 13:54:06 +00:00
Samuel Tardieu
c6079a6880 blocks_in_conditions: do not warn if condition comes from macro 2024-01-19 01:06:08 +01:00
bors
4b3a9c09f3 Auto merge of #12167 - J-ZhengLi:issue12133, r=Alexendoo
fix FP on [`semicolon_if_nothing_returned`]

fixes: #12123

---

changelog: fix FP on [`semicolon_if_nothing_returned`] which suggesting adding semicolon after attr macro
2024-01-18 19:38:09 +00:00
y21
efd8dafa2f [default_numeric_fallback]: improve const context detection 2024-01-18 17:45:50 +01:00
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
bb2d497364 Auto merge of #12146 - kristof-mattei:multiple-crate-versions-with-dashes, r=Manishearth
Fix [`multiple_crate_versions`] to correctly normalize package names to avoid missing the local one

Fixes #12145

changelog: [`multiple_crate_versions`]: correctly normalize package name
2024-01-17 23:00:36 +00:00
bors
2067fe482c Auto merge of #12155 - GuillaumeGomez:fix-9961, r=blyxyas
Correctly handle type relative in trait_duplication_in_bounds lint

Fixes #9961.

The generic bounds were not correctly checked and left out `QPath::TypeRelative`, making different bounds look the same and generating invalid errors (and fix).

r? `@blyxyas`

changelog: [`trait_duplication_in_bounds`]: Correctly handle type relative.
2024-01-17 15:44:16 +00:00
bors
e27ebf28e7 Auto merge of #11766 - dswij:issue-9274, r=blyxyas
`read_zero_byte_vec` refactor for better heuristics

Fixes #9274

Previously, the implementation of `read_zero_byte_vec` only checks for the next statement after the vec init. This fails when there is a block with statements that are expanded and walked by the old visitor.

This PR refactors so that:

1. It checks if there is a `resize`	on the vec
2. It works on blocks properly

e.g. This should properly lint now:

```
    let mut v = Vec::new();
    {
        f.read(&mut v)?;
        //~^ ERROR: reading zero byte data to `Vec`
    }
```

changelog: [`read_zero_byte_vec`] Refactored for better heuristics
2024-01-17 15:14:11 +00:00
bors
5f3a06023a Auto merge of #11608 - atwam:suspicious-open-options, r=y21
Add suspicious_open_options lint.

changelog: [`suspicious_open_options`]: Checks for the suspicious use of std::fs::OpenOptions::create() without an explicit OpenOptions::truncate().

create() alone will either create a new file or open an existing file. If the file already exists, it will be overwritten when written to, but the file will not be truncated by default. If less data is written to the file than it already contains, the remainder of the file will remain unchanged, and the end of the file will contain old data.

In most cases, one should either use `create_new` to ensure the file is created from scratch, or ensure `truncate` is called so that the truncation behaviour is explicit. `truncate(true)` will ensure the file is entirely overwritten with new data, whereas `truncate(false)` will explicitely keep the default behavior.

```rust
use std::fs::OpenOptions;

OpenOptions::new().create(true).truncate(true);
```

- [x] Followed [lint naming conventions][lint_naming]
- [x] Added passing UI tests (including committed `.stderr` file)
- [x] `cargo test` passes locally
- [x] Executed `cargo dev update_lints`
- [x] Added lint documentation
- [x] Run `cargo dev fmt`
2024-01-16 21:33:04 +00:00
Michael Goulet
f7376a0f8c Deal with additional wrapping of async closure body in clippy 2024-01-16 17:12:10 +00:00
Guillaume Gomez
7217c22f69 Update trait_duplication_in_bounds.rs ui test to add regression for ##9961 2024-01-16 12:13:27 +01: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
136a582349 Add non_exhaustive checks in derive_partial_eq_without_eq.rs ui test 2024-01-15 23:29:06 +01:00
y21
f09cd88199
fix false positive in suspicious_open_options, make paths work 2024-01-15 17:15:09 +00:00
atwam
515fe65ba8
Fix conflicts
- New ineffective_open_options had to be fixed.
- Now not raising an issue on missing `truncate` when `append(true)`
  makes the intent clear.
- Try implementing more advanced tests for non-chained operations. Fail
2024-01-15 17:15:09 +00:00
atwam
84588a8815
Add suggestion/fix to suspicious_open_options
Also rebase and fix conflicts
2024-01-15 17:15:09 +00:00
atwam
2ec8729962
PR Fixes 2024-01-15 17:15:08 +00:00
atwam
6fb471d646
More helpful text, small style changes. 2024-01-15 17:15:08 +00:00
atwam
6c201db005
Add suspicious_open_options lint.
Checks for the suspicious use of OpenOptions::create()
without an explicit OpenOptions::truncate().

create() alone will either create a new file or open an
existing file. If the file already exists, it will be
overwritten when written to, but the file will not be
truncated by default. If less data is written to the file
than it already contains, the remainder of the file will
remain unchanged, and the end of the file will contain old
data.
In most cases, one should either use `create_new` to ensure
the file is created from scratch, or ensure `truncate` is
called so that the truncation behaviour is explicit.
`truncate(true)` will ensure the file is entirely overwritten
with new data, whereas `truncate(false)` will explicitely
keep the default behavior.

```rust
use std::fs::OpenOptions;

OpenOptions::new().create(true).truncate(true);
```
2024-01-15 17:15:08 +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
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
Kristof Mattei
d975e267b9
fix: add fix for bug, fix test name 2024-01-13 17:44:27 -07:00
Kristof Mattei
5769c21f23
chore: negative test for multiple crate versions not working when name contains dashes 2024-01-13 17:27:43 -07:00
blyxyas
44f5d969d5
Change PublicallyExported -> PubliclyExported 2024-01-14 01:14:05 +01:00
y21
be5707ce1b lint on .map(|&x| x.clone()) 2024-01-13 17:46:46 +01:00
Quinn Sinclair
e0228eeb94 Fixes FP in redundant_closure_call when closures are passed to macros
There are cases where the closure call is needed in some macros, this in
particular occurs when the closure has parameters. To handle this case,
we allow the lint when there are no parameters in the closure, or the
closure is outside a macro invocation.

fixes: #11274, #1553
changelog: FP: [`redundant_closure_call`] when closures with parameters
are passed in macros.
2024-01-13 17:45:30 +01:00
Samuel Tardieu
e025356969 from_over_into: suggest a correct conversion to () 2024-01-13 13:19:55 +01:00
Nilstrieb
3b7ba1d10a Improve let_underscore_lock
- lint if the lock was in a nested pattern
- lint if the lock is inside a `Result<Lock, _>`
2024-01-12 23:18:58 +01:00
Guillaume Gomez
37947ffc40 Update ui tests 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
e9f87132a1 Rollup merge of #119819 - chenyukang:yukang-fix-118183-lint, r=davidtwco
Check rust lints when an unknown lint is detected

Fixes #118183
2024-01-12 15:16:56 +01:00
y21
153b83f61b [useless_asref]: check that the clone receiver is the local 2024-01-12 13:39:42 +01:00
yukang
1485e5c4da check rust lints when an unknown lint is detected 2024-01-12 18:50:36 +08:00