Commit graph

21743 commits

Author SHA1 Message Date
Samuel Tardieu
5d2fe079ab let_and_return: lint more cases in edition ≥ 2024 2025-02-09 19:03:45 +01:00
Samuel Tardieu
657dda7b50 let_and_return: look for non-static references in expansion as well
One cannot avoid descending into expansion results when looking for
non-static references, or there is a risk of false negative which would
then trigger the `let_and_return` lint.
2025-02-09 18:18:02 +01:00
Alex Macleod
d7fd1c8e3c
make [manual_map] ignore types that contain dyn (#12712)
fixes: #12659

[`manual_map`] and [`manual_filter`] shares the same check logic, but
this issue doesn't seems like it could affect `manual_filter` (?)

---

changelog: make [`manual_map`] ignore types that contain `dyn`
2025-02-09 15:51:03 +00:00
Alejandra González
8c01600e23
Fix obfuscated_if_else suggestion on left side of a binary expr (#14124)
An `if … { … } else { … }` used as the left operand of a binary
expression requires parentheses to be parsed as an expression.

Fix #11141

changelog: [`obfuscated_if_else`]: fix bug in suggestion by issuing
required parentheses around the left side of a binary expression
2025-02-09 01:22:58 +00:00
Samuel Tardieu
ac0a11a8bc Fix obfuscated_if_else suggestion on left side of a binary expr
An `if … { … } else { … }` used as the left operand of a binary
expression requires parentheses to be parsed as an expression.
2025-02-09 02:11:37 +01:00
Alejandra González
77344b8c58
remove "Known problems" section for branches_sharing_code (#14176)
This is outdated.

changelog: none
2025-02-09 01:01:56 +00:00
Samuel Tardieu
aad3686823 Add error markers for obfuscated_if_else lint 2025-02-09 02:00:04 +01:00
lapla-cogito
5e3b968da0
remove "Known problems" section for branches_sharing_code 2025-02-09 06:49:38 +09:00
Catherine Flores
6cdb7f68c3
allow assign_op_pattern in the test of string_add (#14143)
Since `assign_op_pattern` is a style lint, not explicitly allowing it
can lead to undesirable output in other lint checks.

changelog: none
2025-02-08 12:34:52 +00:00
Catherine Flores
0ff95402c7
Two improvements to disallowed_* (#13669)
The improvements are as follows:
- Remove an [unnecessary `compile-flags`
directive](f712eb5cdc/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs (L1))
in `tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs`
- Support replacements as suggested by @mitsuhiko in
https://github.com/rust-lang/rust-clippy/issues/7609#issuecomment-908632622

---

changelog: support replacements in `disallowed_methods`
2025-02-08 11:32:11 +00:00
dswij
8cc596cf95
autofix for range_zip_with_len (#14136)
changelog: [`range_zip_with_len`]: add autofix
2025-02-08 05:20:10 +00:00
dswij
5211148dbd
add MSRV check for manual_flatten (#14086)
`manual_flatten` should respect MSRV.

changelog: [`manual_flatten`]: add MSRV check
2025-02-08 04:17:43 +00:00
dswij
a25e1526e4
Remove Known problems section invalid_upcast_comparisons (#14133)
Remove `Known problems` section `invalid_upcast_comparisons` since issue
was fixed #886

changelog: none
2025-02-07 17:34:49 +00:00
dswij
4e5d00a0a7
Deprecate redundant lint option_map_or_err_ok and take manual_ok_or out of pedantic (#14027)
While extending the `option_map_or_err_ok` lint (warn by default,
"style") to recognize η-expanded forms of `Ok`, as in

```rust
    // Should suggest `opt.ok_or("foobar")`
   let _ = opt.map_or(Err("foobar"), |x| Ok(x));
```

I discovered that the `manual_ok_or` lint (allow by default, "pedantic")
already covered exactly the cases handled by `option_map_or_err_ok`,
including the one I was adding. Apparently, `option_map_or_err_ok` was
added without realizing that the lint already existed under the
`manual_ok_or` name. As a matter of fact, artifacts of this second lint
were even present in the first lint `stderr` file and went unnoticed for
more than a year.

This PR:
- deprecates `option_map_or_err_ok` with a message saying to use
`manual_ok_or`
- moves `manual_ok_or` from "pedantic" to "style" (the category in which
`option_map_or_err_ok` was)

In addition, I think that this lint, which is short, machine applicable,
and leads to shorter and clearer code with less arguments (`Ok`
disappears) and the removal of one level of call (`Err(x)` is replaced
by `x`), is a reason by itself to be in "style".

changelog: [`option_map_or_err_ok` and `manual_ok_or`]: move
`manual_ok_or` from "pedantic" to "style", and deprecate the redundant
style lint `option_map_or_err_ok`.
2025-02-07 17:34:21 +00:00
Samuel Moelius
7c94744afb Address additional review comments 2025-02-07 09:13:59 -05:00
Catherine Flores
0d3bf65bd4
useless_asref: no lint if in a closure to change the ref depth (#14090)
Removing the `.as_ref()` or `.as_mut()` as the top-level expression in a
closure may change the type of the result. In this case, it may be
better not to lint rather than proposing a fix that would not work.

changelog: [`useless_asref`]: do not remove the `.as_ref()` or
`.as_mut()` call if this would change the type of the enclosing closure

Fix #14088
2025-02-07 13:33:18 +00:00
llogiq
f6d23c8d59
Handle more cases in is_normalizable (#13833)
By assuming that a recursive type is normalizable within the deeper
calls to `is_normalizable_helper()`, more cases can be handled by this
function.

In order to fix stack overflows, a recursion limit has also been added
for recursive generic type instantiations.

Fix #9798
Fix #10508
Fix #11915

changelog: [`large_enum_variant`]: more precise detection of variants
with large size differences
2025-02-07 13:20:11 +00:00
Catherine Flores
c6a861615e
add manual_option_as_slice MSRV to the lint documentation (#14171)
`manual_option_as_slice` takes MSRV into account, but this is not
mentioned in the lint documentation.

changelog: none
2025-02-07 12:28:06 +00:00
Catherine Flores
b5ea2491b3
[path_buf_push_overwrite]: mark suggestion as MaybeIncorrect (#14010)
Proposing to replace

```rust
let mut x = PathBuf::from("/foo");
x.push("/bar");
```

by

```rust
let mut x = PathBuf::from("/foo");
x.push("bar");
```

changes the content of `x` (`/bar` ⇒ `/foo/bar`). This is not equivalent
and should not be `MachineApplicable`, even if the original code is
suspicious.

changelog: none
2025-02-07 12:27:35 +00:00
Catherine Flores
9289cca712
remove an outdated line in transmute/mod.rs (#14159)
The `useless_transmute` already belongs to the complexity lint.

changelog: none
2025-02-07 12:25:26 +00:00
Catherine Flores
b0ad06daa8
add MSRV check for lines_filter_map_ok (#14130)
fixes #14127

changelog: [`lines_filter_map_ok`]: respect MSRV
2025-02-07 12:24:50 +00:00
Catherine Flores
c529b70e14
Fix ICE in unnecessary_mut_passed (#14065)
fix #12171

changelog: none
2025-02-07 12:17:54 +00:00
lapla-cogito
16781bf29d
add manual_option_as_slice to the lint documentation 2025-02-07 21:00:39 +09:00
llogiq
33394d28be
Correct version of doc_overindented_list_items (#14152)
Fix the version of `doc_overindented_list_items`. It actually will be in
1.86.0, not 1.80.0.
(https://github.com/rust-lang/rust/pull/136209 has a milestone of
1.86.0)

changelog: none
2025-02-07 10:07:50 +00:00
Timo
4a94ad6c52
Simplify reindent_multiline() signature (#14101)
- `reindent_multiline()` always returns the result of
`reindent_multiline_inner()` which returns a `String`. Make
`reindent_multiline()` return a `String` as well, instead of a
systematically owned `Cow<'_, str>`.
- There is no reason for `reindent_multiline()` to force a caller to
build a `Cow<'_, str>` instead of passing a `&str` directly, especially
considering that a `String` will always be returned.

Also, both the input parameter and return value (of type `Cow<'_, str>`)
shared the same (elided) lifetime for no reason: this worked only
because the result was always the `Cow::Owned` variant which is
compatible with any lifetime.

As a consequence, the signature changes from:

```rust
fn reindent_multiline(s: Cow<'_, str>, …) -> Cow<'_, str> { … }
```

to

```rust
fn reindent_multiline(s: &str, …) -> String { … }
```

changelog: none
2025-02-07 00:45:33 +00:00
Timo
dc330b89a8
Use edition 2024 when running cargo dev lint (#14166)
This part has been missed when switching Clippy to edition 2024 a while
back.

changelog: none
2025-02-07 00:31:01 +00:00
Samuel Tardieu
0e42ba908c Permit specifying a non-default edition when linting file
`cargo dev lint /tmp/file.rs -- --edition 2021` will select edition
2021.
2025-02-07 00:21:49 +01:00
Jason Newcomb
512b08f8b1
change the applicability of if_then_some_else_none to MachineApplicable (#14106)
`MachineApplicable` is appropriate for the applicability of this lint.

changelog: [`if_then_some_else_none`]: change the applicability to
`MachineApplicable`
2025-02-06 20:54:14 +00:00
Jason Newcomb
888365d7e5
Don't use labeled block as top-level blocks (#14102)
Labeled blocks cannot be used as-is in the "then" or "else" part of an
`if` expression. They must be enclosed in an anonymous block.

Fix #14099

changelog: [`match_bool`]: fix suggestion when the rewritten block has a
label
2025-02-06 20:51:41 +00:00
Jason Newcomb
7cda242e3c
don't emit suggestion inside macro in manual_async_fn (#14142)
fixes #12407

I think it is meaningful to emit a warning even if the span is in a
macro.

changelog: [`manual_async_fn`]: don't emit suggestion inside macro
2025-02-06 20:38:46 +00:00
Samuel Tardieu
8a9d55012d Use edition 2024 when running cargo dev lint 2025-02-06 18:59:33 +01:00
Alex Macleod
20b2461938
Skip use_self inside macro expansions of a impl Self block (#13128)
changelog: [`use_self`] Skip if inside macro expansions of a `impl Self`
block
Fixes #13092.
r? Alexendoo
2025-02-06 14:43:39 +00:00
Philipp Krones
3e3715c312
Rustup (#14163)
r? @ghost

changelog: none
2025-02-06 13:48:29 +00:00
Philipp Krones
9f31768adc
Bump nightly version -> 2025-02-06 2025-02-06 14:31:22 +01:00
Philipp Krones
f549562b81
Merge remote-tracking branch 'upstream/master' into rustup 2025-02-06 14:31:01 +01:00
Philipp Krones
660d861058
Fix docs for #[clippy::format_args] (#14161)
changelog: none
2025-02-06 09:23:50 +00:00
Philipp Krones
ee1c15eb56
Add Nursery and Deprecated groups section at Book (#13926)
[RFC](https://github.com/rust-lang/rfcs/blob/master/text/2476-clippy-uno.md#lint-audit-and-categories)
has more groups so add them

changelog: none
2025-02-06 09:23:22 +00:00
Yuri Astrakhan
694b245b20 Fix docs for #[clippy::format_args] 2025-02-06 03:21:49 -05:00
Lzu Tao
9ea2b6501e add test to check for popping wrong items
co-authored-by: Alex Macleod <alex@macleod.io>
2025-02-06 14:34:55 +07:00
Lzu Tao
bcfd0d1aba Skip use_self inside macro expansion of impl Self items 2025-02-06 14:34:55 +07:00
Lzu Tao
e3e6e6ea41 add bug 13092 2025-02-06 14:31:39 +07:00
Lzu Tao
925718d8eb Make the "expensive" comment belong to a branch 2025-02-06 14:31:39 +07:00
Lzu Tao
83b97ae713 Use clippy_utils::ty::ty_from_hir_ty to avoid ICE 2025-02-06 14:31:39 +07:00
Lzu Tao
daab21ef9d Pulicize clippy_utils::ty::ty_from_hir_ty
And use it in the next commit to avoid ICE.
2025-02-06 14:31:39 +07:00
lapla-cogito
5f6dd7a8eb
remove an outdated line 2025-02-06 12:47:47 +09:00
Alejandra González
f09701ab6a
Do not trigger [size_of_in_element_count] for u8 (#14011)
Counting in bytes for a pointer to `u8` is legitimate and must not
trigger the lint. Also, this prevents linting the
`{std,core}::ptr::write_bytes` as it manipulates bytes.

Fix #6590

changelog: [`size_of_in_element_count`]: do not lint if the pointee type
is `u8`
2025-02-05 22:17:10 +00:00
Alexey Semenyuk
c718ae8e2d Add Nursery and Deprecated lints section at Book 2025-02-05 23:09:08 +05:00
Alex Macleod
390286d664
Update version for unneeded_struct_pattern (#14031)
This lint was merged recently
https://github.com/rust-lang/rust-clippy/pull/13465 and should go with
the next version 1.86.0 https://github.com/rust-lang/rust-clippy/tags

changelog: none
2025-02-05 13:55:22 +00:00
Yutaro Ohno
44fda914d3 Correct version of doc_overindented_list_items 2025-02-05 19:16:50 +09:00
lapla-cogito
60f9445900
don't emit lint inside macro in manual_async_fn 2025-02-05 15:06:35 +09:00