Commit graph

9747 commits

Author SHA1 Message Date
cerdelen
aa2f48b09d Change Test for Issue 14422 (Cognitive Complexity lowered through multiple returns) to test it does'nt regress to false negative 2025-04-13 15:35:18 +02:00
Jason Newcomb
d19c651c62
Remove some clippy::all uses from UI tests (#14600)
It's either unneeded (`warn`/`deny`) or can be replaced by individual
lints (`allow`). Also removes some redundant `allow`s covered by the
default `-Aunused` that I saw along the way

changelog:  none
2025-04-12 22:23:04 +00:00
Timo
b157411dba
Consecutive returns dont decrease cognitive Complexity level anymore (#14460)
changelog: [`cognitive_complexity`]: Consecutive return calls decreased
complexity level of the function by 1.

fixes rust-lang/rust-clippy#14422
2025-04-12 16:53:50 +00:00
Timo
8dfcaa0590
Do not propose to auto-derive Clone in presence of unsafe fields (#14559)
`unsafe_fields` is an incomplete feature; comments have been put near
`#![expect(incomplete_features)]` to ensure that we revisit the
situation when the feature becomes complete.

changelog: [`expl_impl_clone_on_copy`]: do not lint in the presence of
`unsafe` fields

Fixes #14558
2025-04-12 16:50:12 +00:00
Timo
3dd1a9b56e
dogfood: run with -D clippy::dbg_macro (#14579)
This prevents forgotten `dbg!()` calls from entering Clippy codebase by
mistake.

Suggested by @y21 when one of my PR forgot to remove one `dbg!()` call.

changelog: none
2025-04-12 14:41:40 +00:00
Alex Macleod
4b140cb48f Remove some clippy::all uses from UI tests 2025-04-12 13:40:49 +00:00
Samuel Tardieu
ec105bab2f
fix: redundant_clone FP in overlapping lifetime (#14237)
fixes #13900

changelog: [`redundant_clone`]: fix FP in overlapping lifetime
2025-04-11 15:47:20 +00:00
yanglsh
07d8a9d331 fix: redundant_clone FP in overlapping lifetime 2025-04-11 23:42:26 +08:00
Alex Macleod
ac4c69f423
implicit_return: better handling of asynchronous code (#14446)
Blocks created by desugaring will not contain an explicit `return`. Do
not suggest to add it when the user has no control over the desugared
code.

Also, ensure that in a `xxx.await` expression, the suggested `return` is
emitted before the whole expression, not before the `await` keyword.

Fix #14411

changelog: [`implicit_return`]: fix proposed `return` position in the
presence of asynchronous code
2025-04-11 13:39:03 +00:00
Samuel Tardieu
c67df0530a
arbitrary_source_item_ordering should ignore test modules (#14585)
Close rust-lang/rust-clippy#14570

The test is provided
[here](https://github.com/rust-lang/rust-clippy/blob/master/tests/ui-toml/arbitrary_source_item_ordering/ordering_good_var_1.rs#L171)
but it's passed without `//@compile-flags: --test`

changelog: [`arbitrary_source_item_ordering`]: should ignore test
modules
2025-04-11 08:48:20 +00:00
Alexey Semenyuk
e1bd4e4b6c arbitrary_source_item_ordering should ignore test modules 2025-04-11 13:42:21 +05:00
cerdelen
c7fbcf4c33 Test for Multiple return statements doesnt decrease cognitive complexity 2025-04-11 09:30:28 +02:00
León Orell Valerian Liehr
15fd2ab73e
Fix a help message of empty_line_after_doc_comments for cases where the following item is nameless 2025-04-10 18:24:45 +02:00
Samuel Tardieu
529bb5f253
Correctly handle bracketed type in default_constructed_unit_struct (#14367)
There were two bugs here. Let's assume `T` is a singleton type
implementing `Default` and that `f()` takes a `T`:

- `f(<T>::default())` cannot be replaced by `f(<T)` as it was (incorrect
spans – this is tricky because the type relative path uses a base span
covering only `T`, not `<T>`) (third commit)
- The argument of `f(<_>::default())` is inferred correctly, but cannot
be replaced by `<_>` or `_`, as this cannot be used to infer an instance
of a singleton type (first commit).

The second commit offers better error messages by pointing at the whole
expression.

Fix #12654

changelog: [`default_constructed_unit_struct`]: do not suggest incorrect
fix when using a type surrounded by brackets
2025-04-10 05:51:39 +00:00
Samuel Tardieu
0aa0d074cd Remove brackets around type name when it is no longer a prefix
When `<T>::default()` is replaced by `T` when `T` is a singleton,
the brackets around the type name can be removed.
2025-04-10 07:46:45 +02:00
Samuel Tardieu
85bf0b2f78 dogfood: run with -D clippy::dbg_macro
This prevents `dbg!()` calls from entering Clippy codebase by mistake.
2025-04-10 07:38:16 +02:00
Manish Goregaokar
630ac0ca72
Accept self.cmp(other).into() as canonical PartialOrd impl (#14573)
`non_canonical_partial_ord_impl` will now recognize two forms of
canonical implementations: `Some(self.cmp(other))` and
`self.cmp(other).into()`.

changelog: [`non_canonical_partial_ord_impl`]: recognize
`self.cmp(other).into()` as a canonical implementation of
`PartialOrd::partial_cmp()`.

Fixes rust-lang/rust-clippy#13640
2025-04-09 15:23:17 +00:00
Alex Macleod
1cfc95c573
fix: map_entry: don't emit lint before checks have been performed (#14568)
Fixes rust-lang/rust-clippy#14449, introduced in #14314

changelog: [`map_entry`]: fix a false positive where the lint would
trigger without any insert calls present
2025-04-09 12:14:18 +00:00
Samuel Tardieu
e463309f4a
add manual_abs_diff lint (#14482)
changelog: [`manual_abs_diff`]: Initial implementation

Hey, first time writing a new lint for clippy, hope I got it right. I
think it's pretty self-explanatory!
Added a few `fixme` test cases, where the lint can be improved to catch
more (probably rare) patterns, but opening a PR with this initial
implementation to make sure I'm on the right track, and that this lint
is acceptable at all.

😁
2025-04-09 10:29:48 +00:00
Samuel Tardieu
0fe33171e4 Accept self.cmp(other).into() as canonical PartialOrd impl
`non_canonical_partial_ord_impl` will now recognize two forms of
canonical implementations: `Some(self.cmp(other))` and
`self.cmp(other).into()`.
2025-04-09 10:47:41 +02:00
Maja Kądziołka
189b0761c8
fix: map_entry: don't emit lint before checks have been performed
Fixes #14449, introduced in #14314
2025-04-09 04:36:14 +02:00
Samuel Tardieu
1a1ad5e54f
fix: iter_cloned_collect FP with custom From/IntoIterator impl (#14473)
Closes #9119

changelog: [`iter_cloned_collect`]: fix FP with custom
`From`/`IntoIterator` impl
2025-04-08 13:46:46 +00:00
Alex Macleod
634c1c885f
Ensure that peeling does not recurse into macros (#14527)
We do not want to remove casts done inside macros. Also, when printing
the suggestion, take it from the same context as the origin expression
(the root context).

Problems found while working on #14526, but should be merged even if
#14526 is not.

changelog: none
2025-04-08 12:52:36 +00:00
yanglsh
ee36124011 fix: iter_cloned_collect FP with custom From/IntoIterator impl 2025-04-08 20:38:43 +08:00
Samuel Tardieu
cf9cffa114
Fixes for missing_asserts_for_indexing (#14108)
This PR fixes issues with the `missing_asserts_for_indexing` lint.
- false positive when the first index is the highest(or equal) value in
a list of indexes:
```rust
pub fn foo(slice: &[i32]) -> i32{
	slice[1] * slice[0]
}
```
- false negative when an assert statement if found after the indexing
operation.
```rust
pub fn bar(slice: &[i32]) -> i32 {
	let product = slice[0] * slice[1];
	assert!(slice.len() > 1);
	product
}
```

examples: https://godbolt.org/z/s7Y47vKdE

closes: #14079

changelog: [`missing_asserts_for_indexing`]: ignore asserts found after
indexing, and do not require asserts if the first index is highest.
2025-04-06 10:42:29 +00:00
Samuel Tardieu
315ea9590d Do not propose to auto-derive Clone in presence of unsafe fields
`unsafe_fields` is an incomplete feature; comments have been put near
`#![expect(incomplete_features)]` to ensure that we revisit the
situation when the feature becomes complete.
2025-04-06 10:21:40 +02:00
Philipp Krones
ab7e525929
Merge remote-tracking branch 'upstream/master' into rustup 2025-04-03 21:31:02 +02:00
Guillaume Gomez
893a6a381e Update to new rinja version (askama) 2025-04-03 15:48:20 +02:00
Samuel Tardieu
db4bd96575 Ensure that peeling does not recurse into macros
We do not want to remove casts done inside macros. Also, when printing
the suggestion, take it from the same context as the origin expression
(the root context).
2025-04-03 01:38:53 +02:00
Yotam Ofek
52a3082056 add manual_abs_diff lint 2025-04-02 19:40:14 +00:00
Samuel Moelius
dc7d9ec35c Validate paths in disallowed_* configurations 2025-04-01 14:53:48 -04:00
Alejandra González
e429bdebbd
Manually fulfill lint expectations for all unsafe blocks with metavars (#14501)
Fixes #14488

Context: the `macro_metavars_in_unsafe` lint looks for unsafe blocks
with a macro span that then contain expressions with a root context span
(which means that it is a macro with an unsafe block expanding a
metavariable inside). In order to avoid emitting a warning for every
single macro invocation, it will deduplicate the unsafe blocks by the
span in the macro.

This leads to the linked issue where because of the deduplicating and
removing unsafe blocks that all belong to the same unsafe block in the
macro, only one of the unsafe blocks will actually have its lint
expectation fulfilled. This PR fixes that by manually fulfilling all of
the unsafe blocks from all expansions before deduplicating them.

changelog: [`macro_metavars_in_unsafe`]: fix unfulfilled `#[expect]` if
macro is invoked multiple times
2025-04-01 18:05:23 +00:00
León Orell Valerian Liehr
54994b2d4b
Fix the primary span of redundant_pub_crate when flagging nameless items 2025-04-01 18:20:41 +02:00
Philipp Krones
9e6c7af4ba
Suggest ./x test src/tools/clippy --bless when in rust-lang/rust (#14507)
changelog: none
2025-03-31 17:30:19 +00:00
Manish Goregaokar
7d3d824d64
Properly handle expansion in single_match (#14495)
Having a macro call as the scrutinee is supported. However, the proposed
suggestion must use the macro call itself, not its expansion.

When the scrutinee is a macro call, do not complain about an irrefutable
match, as the user may not be aware of the result of the macro. A
comparaison will be suggested instead, as if we couldn't see the outcome
of the macro.

Similarly, do not accept macro calls as arm patterns.

changelog: [`single_match`]: proper suggestions in presence of macros

Fixes #14493
2025-03-31 16:42:36 +00:00
Manish Goregaokar
1e78abca67
expand obfuscated_if_else to support {then(), then_some()}.unwrap_or_default() (#14431)
These method chains can be expressed concisely with `if` / `else`.

changelog: [`obfuscated_if_else`]: support `then().unwrap_or_default()`
and `then_some().unwrap_or_default()`
2025-03-31 16:40:32 +00:00
Alex Macleod
f894a81654 Fulfill expectations after first missing-panics-doc 2025-03-31 12:52:06 +00:00
Alex Macleod
6ee4f34741 Abide by allow/expect in bodies for missing_panics_doc 2025-03-31 12:52:06 +00:00
Alex Macleod
c89368537c Fix partially const bodies not linting missing_panics_doc 2025-03-31 12:52:06 +00:00
Alex Macleod
9172556de8 Suggest ./x test src/tools/clippy --bless when in rust-lang/rust 2025-03-31 12:39:41 +00:00
Jason Newcomb
b46b311ee7
add manual_dangling_ptr lint (#14107)
close #2177

changelog: [`manual_dangling_ptr`]: new lint
2025-03-31 10:14:46 +00:00
Urgau
5f26d0e970 Drop clippy::invalid_null_ptr_usage 2025-03-30 19:33:15 +02:00
y21
c7390279ca add comment and .clone() test case 2025-03-30 14:04:56 +02:00
y21
d5d2189c71 rename lint to char_indices_as_byte_indices 2025-03-30 13:40:03 +02:00
y21
fb32aaf9ac new lint: chars_enumerate_for_byte_indices 2025-03-30 13:39:01 +02:00
y21
ffaecd008d manually fulfill lint expectations for all unsafe blocks with metavars 2025-03-29 17:55:30 +01:00
Timo
4c610e32ad
fix: unnested_or_patterns suggests wrongly in let (#14401)
Closes #9952

changelog: [`unnested_or_patterns`] fix wrong suggestion in `let`
2025-03-29 13:04:15 +00:00
yanglsh
2df6bba5b0 fix: unnested_or_patterns suggests wrongly in let 2025-03-29 20:52:59 +08:00
Samuel Tardieu
432a8a7a7c Properly handle expansion in single_match
Having a macro call as the scrutinee is supported. However, the proposed
suggestion must use the macro call itself, not its expansion.

When the scrutinee is a macro call, do not complain about an irrefutable
match, as the user may not be aware of the result of the macro. A
comparaison will be suggested instead, as if we couldn't see the outcome
of the macro.

Similarly, do not accept macro calls as arm patterns.
2025-03-28 22:30:09 +01:00
Samuel Tardieu
4ac3611225 implicit_return: do not suggest adding return into desugared code
Blocks created by desugaring will not contain an explicit `return`. Do not
suggest to add it when the user has no control over the desugared code.

Also, in the case of an implicit return on a `.await` expression, ensure
that the suggested `return` is emitted at the right place instead of
before the `await` keyword.
2025-03-28 12:14:43 +01:00