Commit Graph

2387 Commits

Author SHA1 Message Date
Philipp Krones de365c057e Merge remote-tracking branch 'upstream/master' into rustup 2025-12-11 18:48:00 +01:00
Scott McMurray 9495686c40 Update clippy for the ast TryBlock change 2025-12-09 20:18:43 -08: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 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
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 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
Philipp Krones f64e401f74 Merge remote-tracking branch 'upstream/master' into rustup 2025-10-31 18:58:07 +01:00
Matthias Krüger 33232af2e4 Rollup merge of #144291 - oli-obk:const_trait_alias, r=fee1-dead
Constify trait aliases

Allow `const trait Foo = Bar + [const] Baz;` trait alias declarations. Their rules are the same as with super traits of const traits. So `[const] Baz` or `const Baz` is only required for `[const] Foo` or `const Foo` bounds respectively.

tracking issue rust-lang/rust#41517 (part of the general trait alias feature gate, but I can split it out into a separate const trait alias feature gate. I just assumed that const traits would stabilize before trait aliases, and we'd want to stabilize trait aliases together with const trait aliases at the same time)

r? ``@compiler-errors`` ``@fee1-dead``
2025-10-31 02:39:14 +01:00
Oli Scherer 3f5ea6beb4 Constify trait aliases 2025-10-30 08:05:37 +00:00
Frank King 42f074df62 Implement pattern matching for &pin mut|const T 2025-10-30 07:56:16 +08:00
Oli Scherer 07b6b325e2 Trait aliases are rare large ast nodes, box them 2025-10-28 11:11:56 +00:00
Cameron Steffen a2d89559f7 Remove QPath::LangItem 2025-10-27 21:19:38 -05:00
Cameron Steffen ae9d202f8c Remove QPath::LangItem from ranges 2025-10-27 21:19:38 -05:00
Ada Alakbarova 605cc879bc introduce as_some_expr, is_none_expr 2025-10-27 16:54:48 +01:00
Ada Alakbarova 59890a9736 introduce as_some_pattern 2025-10-27 16:54:47 +01:00
bors 05aaed9523 Auto merge of #146069 - camsteffen:range-desugar-span, r=SparrowLii
Mark desugared range expression spans with DesugaringKind::RangeExpr

This is a prerequisite to removing `QPath::LangItem` (rust-lang/rust#115178) because otherwise there would be no way to detect a range expression in the HIR.

There are some non-obvious Clippy changes so a Clippy team review would be good.
2025-10-27 02:50:35 +00:00
Peter Jaszkowiak ff9a1757f1 refactor ub_checks and contract_checks to share logic 2025-10-25 14:30:04 -06:00
ceptontech 622a77d288 feat(search_is_some): Fix when the closure spans multiple lines
Previously the program only fixed the code when the closure supplied to
the method contained only 1 line.  This patch removes the restriction.

The code already works.  This patch only removes the extra check that
causes the restriction.  The test cases that can now be fixed are moved
into the files containing tests cases that can be fixed.

The unnecessary check has survived in the code this way.

- In Dec 2015, patch a6bd2d0622, pull request 524.  The lint was first
  added.  The program did not support fixing code automatically yet.  So
  the suggested fix was printed as a part of the diagnostic message.
  When the original code contained multiple lines, the suggested fix was
  omitted in order to keep the diagnostic message concise.

- In May 2019, patch bd0b75f6c3, pull request 4049.  Logic was added
  to strip the reference in the closure when the suggested replacement
  method required it.  Because the fix was still only printed when the
  code contained a single line, the new transformation was only done
  when the code contained a single line.

- In Aug 2019, patch 945d4cf69f, pull request 4454.  The lint was
  updated to fix code automatically.  Because the fixed code had only
  been printed in the diagnostic message for a single line, the fix was
  only added for a single line.

- In Nov 2021, patch 092fe209a6, pull request 7463.  The logic for
  transforming the closure was moved into another file.  A comment was
  added saying that it was only good for a single line because it had
  only been used for a single line.

changelog: [`search_is_some`] now fixes code spanning multiple lines
2025-10-24 14:33:47 -07:00
bors 8d15b5f6a9 Auto merge of #148014 - jhpratt:rollup-aglren3, r=jhpratt
Rollup of 3 pull requests

Successful merges:

 - rust-lang/rust#134316 (Add `String::replace_first` and `String::replace_last`)
 - rust-lang/rust#147713 (Retire ast::TyAliasWhereClauses.)
 - rust-lang/rust#148011 (Revert constification of `AsRef for Cow` due to inference failure )

r? `@ghost`
`@rustbot` modify labels: rollup
2025-10-23 08:17:05 +00:00
Camille Gillot 26b12a9756 Retire ast::TyAliasWhereClauses. 2025-10-23 00:40:01 +00:00
Camille Gillot 6026cc9d11 Replace NullOp::SizeOf and NullOp::AlignOf by lang items. 2025-10-23 00:38:28 +00:00