Commit graph

24309 commits

Author SHA1 Message Date
Ada Alakbarova
2193494b6c
clean-up 2025-11-17 17:45:28 +01:00
dswij
abc17b3707
fix(equatable_if_let): don't suggest = in const context (#16092)
Supersedes https://github.com/rust-lang/rust-clippy/pull/15482

I wasn't able to get `is_const_method` to work, so for now we just don't
suggest `=` in const context.

changelog: [`equatable_if_let`]: don't suggest `=` in const context
2025-11-17 15:53:08 +00:00
Jason Newcomb
63c7197be0
refactor(time_subtraction): give the same message for Instant - Duration and Duration - Duration (#16097)
Supersedes https://github.com/rust-lang/rust-clippy/pull/16057

changelog: [`time_subtraction`]: give the same message for `Instant -
Duration` and `Duration - Duration`
2025-11-16 23:16:20 +00:00
Alex Macleod
03ab7b832a
chore(useless_vec): clean-up (#15952)
changelog: none
2025-11-15 15:33:52 +00:00
Alex Macleod
86e036af36
Add a doc_paragraphs_missing_punctuation lint (#15758)
This introduces a new lint that aims to check for missing terminal
punctuation in doc comments.

## Lint scope and motivation

It partially addresses
https://github.com/rust-lang/rust-clippy/issues/8371 by currently
focusing on the case that is both the easiest to look for without
advanced NLP capacities and still very useful: missing punctuation at
the end of the last sentence of doc comments. This is particularly
useful when working in a team to enforce a style guide and make sure all
doc comments end with some kind of punctuation, which is often forgotten
in the case of short, single-sentence doc comments. The lint is biased
towards avoiding false positives so it can be easily adopted without
requiring an excessive number of `#[expect]` attributes.

It is currently only concerned with Latin languages, but adding support
for `。` for instance should be very easy.

Even if consistently ending doc comments (even very short ones) with
punctuation is somewhat of an opinion, it seems sufficiently
well-established, [at least in the
`std`](https://github.com/rust-lang/rust/pull/91886), to warrant its own
lint, even if of course it would be allow-by-default.

## Lint category and possible evolution

Because it is unclear how useful and more complex it would be to also
look for missing punctuation at the end of *each* Markdown paragraphs, I
opted for the `nursery` category for now. My understanding of [the
stability
guarantees](https://github.com/rust-lang/rfcs/blob/master/text/2476-clippy-uno.md#stability-guarantees)
is that would it not be acceptable to add such capability later if it
was part of `pedantic` or `restriction` categories right away. I tried
to make sure the lint name allows this kind of iterative evolution.

## Testing

I ran the lint against the `core` library which led me to introduce a
few special cases (which seem common enough) to avoid false positives:
e.g., the last sentence being in parentheses. After excluding specific
modules which should likely be excluded (e.g., `core_arch`,
`intrinsincs`), it currently finds a bit more than 200 errors in the
`core` library.

This lint also helped find issues with a few doc comments, which [are
now fixed](https://github.com/rust-lang/rust/pull/146136).

## How to review this PR

I suppose it is easier to have a look at the UI tests first before
checking the implementation.

---

*Please write a short comment explaining your change (or "none" for
internal only changes)*

changelog: add new lint [`doc_paragraphs_missing_punctuation`]
2025-11-15 14:56:50 +00:00
llogiq
c8e5fff413
feat({unnecessary,panicking}_unwrap): lint field accesses (#15949)
Resolves https://github.com/rust-lang/rust-clippy/issues/15321

Unresolved questions:
- [ ] I did implement support for nested field accesses, but I'm not
sure if that's desired
    - It brings some additional complexity, though not too much
- It might be surprising for the user to get a lint on a direct field
access, but not a nested one
    - It's unclear how often such nested case comes up

changelog: [`unnecessary_unwrap`]: lint field accesses
changelog: [`panicking_unwrap`]: lint field accesses
2025-11-15 11:38:45 +00:00
Ada Alakbarova
215cfedf9a
add tests for partial moves 2025-11-15 11:22:41 +01:00
Ada Alakbarova
0384c20e1a
lint nested field accesses as well 2025-11-15 11:00:05 +01:00
Ada Alakbarova
f13d246318
feat({unnecessary,panicking}_unwrap): lint field accesses 2025-11-15 11:00:05 +01:00
Ada Alakbarova
aa4869f27a
clean-up 2025-11-15 11:00:05 +01:00
llogiq
cd61be7c56
Fix sliced_string_as_bytes FP with a RangeFull (#15873)
changelog: [`sliced_string_as_bytes`]: don't fire on
`str[..].as_bytes()`

So I ran into this in some codebase I was working on,
where the lint fired on this line:
```rust
let string: &str;
string[..].as_bytes()
```
So I was trying to understand the rationale behind this lint, and it
says:
> It involves doing an unnecessary UTF-8 alignment check which is less
efficient, and can cause a panic.

This is obviously not true in the case where a `RangeFull` slice is
being taken, since there is no UTF-8 boundary check, and no panic can be
caused. So I created an exemption for `RangeFull`s.

Two other notes:
1. I'm not sure the word "alignment" in the lint's description (quoted
above) is really correct, should probably say "char boundary" instead?
2. I might be missing something, but isn't there a lint for doing
superfluous slice indexing, and then calling a slice method? e.g.
`str[..].len()` or `slice[..].len()`, where `str` and `slice` are `&str`
and `&[T]`, respectively. If we had one, I would expect *it* to fire for
the example code I quoted above.
2025-11-15 08:53:12 +00:00
Ada Alakbarova
32f5ae101d
Give the same message for Instant - Duration and Duration - Duration
Diff best seen with whitespace ignored
2025-11-15 08:29:45 +01:00
Ada Alakbarova
e1344da2fe
Handle the suggestion-less case inside print_unchecked_duration_subtration_sugg
This doesn't change any functionality, but will make it easier to switch
to a uniform message in the next commit. Also a nice simplification imo
2025-11-15 08:28:11 +01:00
Ada Alakbarova
bbb251a25f
clean-up
- move `is_allowed_vec_method` (a stripped-down version of it, anyway,
  as the function doesn't make sense as is out of context) to utils, as
  it's shared between `useless_vec` and `ptr_arg`
- add another test for non-standard macro brace case
- rm unneeded `allow`s
- rm duplicated tests
- add comments to some tests
2025-11-15 08:04:36 +01:00
Ada Alakbarova
91779ae78f
rename lint files to match lint name 2025-11-15 08:04:36 +01:00
Ada Alakbarova
f279a0bef7
rename tests/ui/useless_vec{,_unfixable}.rs
will improve the diff for the next commit
2025-11-15 08:03:42 +01:00
Philipp Krones
62589a21d3
Rustup (#16094)
r? @ghost

changelog: none
2025-11-15 00:05:34 +00:00
Philipp Krones
72fc40c3d0 Fix fn_to_numeric_cast 32 bit stderr 2025-11-15 00:58:12 +01:00
Philipp Krones
ca4557c692 Bump nightly version -> 2025-11-15 2025-11-15 00:37:56 +01:00
Philipp Krones
03cd6b6dd8 Merge remote-tracking branch 'upstream/master' into rustup 2025-11-15 00:37:39 +01:00
Yotam Ofek
386451c16a Fix sliced_string_as_bytes FP with a RangeFull 2025-11-15 00:11:25 +02:00
Ada Alakbarova
757bad7206
fix equatable_if_let: FP in const context 2025-11-14 22:33:23 +01:00
Alejandra González
c48592eb49
Use extend when creating the lint pass constructors (#15994)
Alternative to part of rust-lang/rust-clippy#14509.

changelog: none
2025-11-14 14:18:36 +00:00
llogiq
f1c74612e0
refactor(rc_buffer): remove RcKind (#16089)
not really necessary

Follow-up to https://github.com/rust-lang/rust-clippy/pull/15803

changelog: none

r? @llogiq
2025-11-14 14:12:37 +00:00
Jason Newcomb
2027c0e02b Update dev new_lint to add passes to each array. 2025-11-14 07:50:55 -05:00
Jason Newcomb
cd41914e31 Register late passes with extend instead of register_late_pass. 2025-11-14 07:50:21 -05:00
Jason Newcomb
bffde26197 Register early passes with extend instead of register_early_pass. 2025-11-14 07:49:03 -05:00
llogiq
540e2f4a2a
feat(ok_expect): add autofix (#15867)
changelog: [`ok_expect`]: add autofix
2025-11-14 12:12:31 +00:00
Ada Alakbarova
3bef3ff3d4
refactor(rc_buffer): remove RcKind
not really necessary
2025-11-14 12:03:05 +01:00
llogiq
663ef9b31b
fix(rc_buffer): don't touch the path to Rc/Arc in the suggestion (#15803)
Fixes https://github.com/rust-lang/rust-clippy/issues/15802

changelog: [`rc_buffer`]: don't touch the path to `Rc`/`Arc` in the
suggestion
2025-11-14 09:52:59 +00:00
Samuel Tardieu
4016c0fdb8
Add documentation for clippy_utils::numeric_literal (#16078)
For rust-lang/rust-clippy#15569

changelog: none
2025-11-13 22:48:54 +00:00
Fernando Valentim Torres
44700b962e add documentation comments for clippy_utils::numeric_literal 2025-11-13 15:57:58 -03:00
Samuel Tardieu
801e5b3cc0
Fix website history interactions (#16060)
cc @GuillaumeGomez

- Searching/filtering no longer creates a new history entry per
keystroke/change
- Loading a URL with a specified search query now works. The search is
now stored as `?search=foo` instead of `#/foo`, not a breaking change
since this didn't work before
- The browser back/forward actions now update the filters/search and
displayed lints

The bulk of the changes are to support that last one, previously the
filter state was stored both in the DOM and as JS objects. The DOM is
now the single source of truth

changelog: none
2025-11-13 08:56:08 +00:00
Timo
0ac66461bb
refactor(needless_arbitrary_self_type): give suggestions with finer diffs (#16005)
changelog: [`needless_arbitrary_self_type`]: give suggestions with finer
diffs
2025-11-12 20:49:39 +00:00
Philipp Krones
da2a220a2e
incompatible_msrv: Don't check the contents of any std macro. (#16083)
cc rust-lang/rust#148190 @flip1995 @RalfJung

This is a bit of a hack in that it hardcodes the list of crates with
stability attributes. This shouldn't be a big deal since that isn't a
set that changes very frequently and an internal lint could detect when
that happens.

The `fixme`s added aren't new issues and shouldn't get in the way of
unblocking the upstream issue.

changelog: none
2025-11-12 17:22:17 +00:00
Jason Newcomb
a537e86e7f incompatible_msrv: Don't check the contents of any std macro. 2025-11-12 12:01:16 -05:00
Mara Bos
3352bea655 Bless clippy tests. 2025-11-12 14:43:05 +01:00
Mara Bos
7ae882efd0 Bless clippy tests. 2025-11-12 12:48:39 +01:00
Mara Bos
18de21629a Make clippy happy. 2025-11-12 12:48:36 +01:00
Mads Marquart
70cfebbddc Fix building rustdoc and clippy with jemalloc feature 2025-11-11 20:16:16 +01:00
Mads Marquart
a72893f708 Simplify jemalloc setup
Using the new `override_allocator_on_supported_platforms` feature in
`tikv-jemalloc-sys v0.6.1` we can avoid the manual statics.
2025-11-11 20:16:15 +01:00
Samuel Tardieu
d599529223
Fix single_range_in_vec_init FP for explicit Range (#16043)
Closes rust-lang/rust-clippy#16042
Closes rust-lang/rust-clippy#16044

changelog: [`single_range_in_vec_init`] fix FP for explicit `Range`
2025-11-11 10:28:46 +00:00
Stuart Cook
39107ffff6 Rollup merge of #141470 - GuillaumeGomez:function_casts_as_integer, r=urgau
Add new `function_casts_as_integer` lint

The `function_casts_as_integer` lint detects cases where users cast a function pointer into an integer.

*warn-by-default*

### Example

```rust
fn foo() {}
let x = foo as usize;
```

```
warning: casting a function into an integer implicitly
  --> $DIR/function_casts_as_integer.rs:9:17
   |
LL |     let x = foo as usize;
   |                 ^^^^^^^^
   |
help: add `fn() as usize`
   |
LL |     let x = foo as fn() as usize;
   |                 +++++++
```

### Explanation

You should never cast a function directly into an integer but go through a cast as `fn` first to make it obvious what's going on. It also allows to prevent confusion with (associated) constants.

Related to https://github.com/rust-lang/rust/issues/81686 and https://stackoverflow.com/questions/68701177/whats-the-meaning-of-casting-a-rust-enum-variant-to-a-numeric-data-type

r? ````@urgau````
2025-11-11 21:09:32 +11:00
llogiq
0b30af05dc
Fix useless_let_if_seq FN when if is in the last expr of block (#16063)
Closes rust-lang/rust-clippy#16062
Closes rust-lang/rust-clippy#16064

changelog: [`useless_let_if_seq`] fix FN when `if` is in the last expr
of block
2025-11-10 23:54:24 +00:00
Linshu Yang
e1ac7da6a1 fix: useless_let_if_seq wrongly unmangled macros 2025-11-10 20:01:15 +00:00
Linshu Yang
8a1dde1449 fix: useless_let_if_seq FN when if is in the last expr of block 2025-11-10 19:30:50 +00:00
Linshu Yang
6834ab61b1 fix: single_range_in_vec_init wrongly unmangles macros 2025-11-10 17:25:01 +00:00
Linshu Yang
c8885d5313 fix: single_range_in_vec_init FP for explicit Range 2025-11-10 17:25:01 +00:00
Alex Macleod
4e35148a50 Fix website history interactions 2025-11-10 16:29:45 +00:00
dswij
3c3452a3b1
Fix mod_module_files false positive for tests in workspaces (#16048)
Workspaces don't have their integration tests in tests/ at the root, so
this check missed them.

This fixes rust-lang/rust-clippy#11775 for workspaces.

changelog: [`mod_module_files`]: Fix false positive for integration
tests in workspace crates.
2025-11-10 16:27:47 +00:00