Commit Graph

2491 Commits

Author SHA1 Message Date
llogiq 741b684c90 New lint - same_length_and_capacity (#15656)
Fixes rust-lang/rust-clippy#5955

I understand that there's a feature freeze right now. I had started
working on this before I was aware of the feature freeze. I don't mind
waiting as long as I need to for feedback.

changelog: [`same_length_and_capacity`]: adds a new lint that checks for
usages of `from_raw_parts` where the same expression is passed for the
length and the capacity

<!-- TRIAGEBOT_START -->

<!-- TRIAGEBOT_SUMMARY_START -->

### Summary Notes

-
[Feature-freeze](https://github.com/rust-lang/rust-clippy/pull/15656#issuecomment-3276620004)
by [github-actions[bot]](https://github.com/github-actions[bot])

*Managed by `@rustbot`—see
[help](https://forge.rust-lang.org/triagebot/note.html) for details*

<!-- TRIAGEBOT_SUMMARY_END -->
<!-- TRIAGEBOT_END -->
2025-12-18 13:55:44 +00:00
Ada Alakbarova 3e55ab1adf dogfood the lint
This commit is put before the one that actually introduces the lint,
since, were they put in the opposite order, the first commit wouldn't
pass dogfood
2025-12-17 12:20:51 +01:00
Alejandra González d93e1eb294 Fix branches-sharing-code suggests wrongly on const and static (#15522)
Closes rust-lang/rust-clippy#15347

changelog: [`branches-sharing-code`] fix wrong suggestions on `const`
and `static`
2025-12-15 17:26:29 +00:00
Jason Newcomb d36794f5ec Add iterator reduction coverage to never_loop (#16222)
Fixes rust-lang/rust-clippy#16061.

Extend `never_loop` to also lint iterator reduction methods (e.g.
`for_each`, `try_for_each`, `fold`, `try_fold`, `reduce`, `all`, `any`)
when the closure’s body diverges (return type `!`). Add a UI test
`never_loop_iterator_reduction` to cover these cases.

Testing:
- TESTNAME=never_loop_iterator_reduction cargo uitest

changelog: [`never_loop`]: lint diverging iterator reduction closures
like `for_each` and `fold`
2025-12-15 12:00:31 +00:00
Jason Newcomb d06ae84771 feat(unnecessary_fold): lint on folds with Add::add/Mul::mul (#16124)
Resurrects https://github.com/rust-lang/rust-clippy/pull/13475

changelog: [`unnecessary_fold`]: lint on `fold`s with
`Add::add`/`Mul::mul`
2025-12-12 18:39:22 +00:00
Cuong Le fefd58b32b Clean up unused try_reduce entry in sym 2025-12-12 10:37:34 +07:00
Cuong Le 89a848c439 Fix fmt and dogfood lints for never_loop iterator reduction 2025-12-12 10:24:49 +07:00
Cuong Le 36201bdf3e Add iterator reduction coverage to never_loop 2025-12-12 10:01:58 +07:00
Philipp Krones 1ff4682590 Bump Clippy version -> 0.1.94 2025-12-11 18:48:15 +01:00
Philipp Krones 42c8b68ee9 Bump nightly version -> 2025-12-11 2025-12-11 18:48:10 +01:00
Philipp Krones de365c057e Merge remote-tracking branch 'upstream/master' into rustup 2025-12-11 18:48:00 +01:00
Ada Alakbarova 4ce7628869 clean-up 2025-12-10 19:38:09 +01:00
Scott McMurray 9495686c40 Update clippy for the ast TryBlock change 2025-12-09 20:18:43 -08:00
km247 b1993dce20 Implement lint to check for usages of from_raw_parts where the same expression is used for the length and the capacity 2025-12-08 09:02:18 -06:00
Matthias Krüger f81cf11958 Rollup merge of #148814 - bend-n:stabilize_array_windows, r=scottmcm
stabilize `array_windows`

Tracking issue: rust-lang/rust#75027
Closes: rust-lang/rust#75027
FCP completed: https://github.com/rust-lang/rust/issues/75027#issuecomment-3477510526
2025-12-06 09:57:59 +01:00
Boxy Uwu 7f61da9c69 account for safe target features in fndef<->closure and fndef<->fndef coerce-lubs 2025-12-03 14:55:41 +00:00
Alex Macleod a10cafebcd feat(manual_ilog2): new lint (#15865)
Revival of https://github.com/rust-lang/rust-clippy/pull/13331

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

changelog: [`manual_ilog2`]: new lint
2025-12-02 19:08:25 +00:00
bendn 3e88c6a639 stabilize [T]::array_windows 2025-12-02 00:37:17 +07:00
Philipp Krones 099308af90 Merge commit '92b4b68683249c781c3acad742fc6e57c4140ad9' into clippy-subtree-update 2025-11-28 20:25:22 +01:00
Philipp Krones aa988c8e14 Bump nightly version -> 2025-11-28 2025-11-28 20:09:58 +01:00
Philipp Krones 181601c342 Merge remote-tracking branch 'upstream/master' into rustup 2025-11-28 20:09:43 +01:00
Ada Alakbarova e6ad406d48 feat(manual_ilog2): new lint 2025-11-28 10:34:37 +01:00
Alex Macleod a6dfbb3524 Stop inserting redundant parenthesis around desugared match expressions (#16102)
Currently the `sugg` utility treats all `ExprKind::Match` expressions as
potentially needing brackets, and therefore many lints will add
parenthesis around them. However this includes desugared match
expressions like the `?` and `.await` operators.

In this PR I have updated the utility to only treat match expressions
which include a code block as needing parenthesis, as the other types
have similar precedence rules and expectations to things like member
access and I think can be treated like as such.

While this change is small on paper it touches a large amount of code
due to changing a cross cutting concern, I am happy to add additional
tests if we think it is needed, but I wanted to get a feel for if this
is even a sensible change to be doing and what the expectations were
around the level of testing needed before investing more time into it.

Regarding not putting a specific lint in the changelog, determining all
the lints this could possibly effect would be possible but take some
time, and I wonder if it would be a bit too noisy in the changelog. Open
to suggestions about how best to address that.

fixes rust-lang/rust-clippy#16045

changelog: stop inserting unnecessary brackets around `x?` and `x.await`
expressions in suggestions
2025-11-27 18:49:07 +00:00
yanglsh f83c72f00c fix: branches-sharing-code suggests wrongly on const and static 2025-11-27 01:31:12 +00:00
lcnr 640c39ce13 fix tooling 2025-11-26 11:09:03 +01:00
bors 04d65f9fd9 Auto merge of #148434 - oli-obk:inherent-const-impl, r=fee1-dead
Inherent const impl

Some constifications are annoying because we need to repeat `T: Trait` bounds from an impl block on the individual constified `const fn`s as `T: [const] Trait`. We've brainstormed solutions before, and one would be to have separate `const impl` blocks or sth. However the final syntax will look, I decided to just impl this syntax and either have sth nice on nightly to work with or at least move the discussion along.

Also interacts with the discussion around `impl const Trait for Type` vs `const impl Trait for Type`, as we may want to use the latter to keep inherent and trait impls in sync (unless we come up with even another scheme).

* [ ] rustdoc + tests
* [ ] macro stability /regression tests

r? `@fee1-dead`

cc `@traviscross` `@rust-lang/project-const-traits`
2025-11-19 02:23:56 +00:00
Oli Scherer f893111123 Give all impls a constness 2025-11-18 09:20:21 +00:00
Camille Gillot 9e0f3ec368 Replace OffsetOf by an actual sum. 2025-11-18 00:10:03 +00:00
robert-mccausland 2d4c45ff62 feat: change desuragered match suggestions to NonParen 2025-11-17 19:50:35 +00:00
Jason Newcomb 60050e56fd Merge and extend tests for missing_docs_in_private_items 2025-11-16 18:30:24 -05:00
Philipp Krones 44731205b8 Merge commit '62589a21d351f63d77dcd173c31107e9f1d06328' into clippy-subtree-update 2025-11-16 15:19:59 +01:00
Alex Macleod 03ab7b832a chore(useless_vec): clean-up (#15952)
changelog: none
2025-11-15 15:33:52 +00: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
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
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
Jason Newcomb a537e86e7f incompatible_msrv: Don't check the contents of any std macro. 2025-11-12 12:01:16 -05:00
Mara Bos 18de21629a Make clippy happy. 2025-11-12 12:48:36 +01:00
Frank King 276053175d Implement &pin patterns and ref pin bindings 2025-11-10 09:57:08 +08:00
Stuart Cook f5ccdae676 Rollup merge of #128666 - pitaj:intrinsic-overflow_checks, r=BoxyUwU
Add `overflow_checks` intrinsic

This adds an intrinsic which allows code in a pre-built library to inherit the overflow checks option from a crate depending on it. This enables code in the standard library to explicitly change behavior based on whether `overflow_checks` are enabled, regardless of the setting used when standard library was compiled.

This is very similar to the `ub_checks` intrinsic, and refactors the two to use a common mechanism.

The primary use case for this is to allow the new `RangeFrom` iterator to yield the maximum element before overflowing, as requested [here](https://github.com/rust-lang/rust/issues/125687#issuecomment-2151118208). This PR includes a working `IterRangeFrom` implementation based on this new intrinsic that exhibits the desired behavior.

[Prior discussion on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Ability.20to.20select.20code.20based.20on.20.60overflow_checks.60.3F)
2025-11-09 13:22:23 +11:00
bors 5b5709b248 Auto merge of #139558 - camelid:mgca-const-items, r=oli-obk,BoxyUwU
mgca: Add ConstArg representation for const items

tracking issue: rust-lang/rust#132980
fixes rust-lang/rust#131046
fixes rust-lang/rust#134641

As part of implementing `min_generic_const_args`, we need to distinguish const items that can be used in the type system, such as in associated const equality projections, from const items containing arbitrary const code, which must be kept out of the type system. Specifically, all "type consts" must be either concrete (no generics) or generic with a trivial expression like `N` or a path to another type const item.

To syntactically distinguish these cases, we require, for now at least, that users annotate all type consts with the `#[type_const]` attribute. Then, we validate that the const's right-hand side is indeed eligible to be a type const and represent it differently in the HIR.

We accomplish this representation using a new `ConstItemRhs` enum in the HIR, and a similar but simpler enum in the AST. When `#[type_const]` is **not** applied to a const (e.g. on stable), we represent const item right-hand sides (rhs's) as HIR bodies, like before. However, when the attribute is applied, we instead lower to a `hir::ConstArg`. This syntactically distinguishes between trivial const args (paths) and arbitrary expressions, which are represented using `AnonConst`s. Then in `generics_of`, we can take advantage of the existing machinery to bar the `AnonConst` rhs's from using parent generics.
2025-11-08 22:31:33 +00:00
Noah Lev 7a745ff987 Use "rhs" terminology instead of "body" 2025-11-08 13:50:48 -05:00
Noah Lev 8cb6e1bfcf Fix clippy
When mgca is enabled, const rhs's that are paths may have false
negatives with the lints in non_copy_const.rs. But these should probably
be using the trait solver anyway, and it only happens under mgca.
2025-11-08 13:50:48 -05:00
llogiq 8e8fe61198 Introduce helper functions for Some(x)/None patterns and expressions (#15930)
Reduces boilerplate a bit

changelog: none
2025-11-01 22:10:25 +00:00
Noah Lev eefeff552e mgca: Add ConstArg representation for const items 2025-11-01 14:59:10 -04:00
Jason Newcomb 7562179364 Overhaul and document clippy_utils::attrs (#15763)
For https://github.com/rust-lang/rust-clippy/issues/15569

changelog: none
2025-11-01 10:50:07 +00:00
Matthias Krüger 7ec6593bfd Rollup merge of #148340 - flip1995:clippy-subtree-update, r=Manishearth
Clippy subtree update

r? ``@Manishearth``

Cargo.lock update due to Clippy version bump
2025-11-01 08:25:48 +01:00
Matthias Krüger 78adb20385 Rollup merge of #139751 - frank-king:feature/pin-project, r=Nadrieril,traviscross
Implement pin-project in pattern matching for `&pin mut|const T`

This PR implements part of rust-lang/rust#130494. It supports pin-project in pattern matching for `&pin mut|const T`.

~Pin-projection by field access (i.e. `&pin mut|const place.field`) is not fully supported yet since pinned-borrow is not ready (rust-lang/rust#135731).~

CC ``````@traviscross``````
2025-11-01 08:25:44 +01:00
Philipp Krones c71f7b63f8 Merge commit 'c936595d17413c1f08e162e117e504fb4ed126e4' into clippy-subtree-update 2025-10-31 19:15:42 +01:00