Commit Graph

2414 Commits

Author SHA1 Message Date
Jason Newcomb 7d41f1d7a4 Fix implicit_saturating_sub suggests wrongly on untyped int literal (#16309)
Closes rust-lang/rust-clippy#16307

changelog: [`implicit_saturating_sub`] fix wrong suggestions on untyped
int literal
2026-01-01 05:25:50 +00:00
Jason Newcomb 5a97a1733d manual_div_ceil: Added check for variant x.next_multiple_of(y) / y (#16221)
Suggest using `x.div_ceil(y)` instead of `x.next_multiple_of(y) / y`.

fixes rust-lang/rust-clippy#16219

changelog: [`manual_div_ceil`]: Added check for variant
`x.next_multiple_of(y) / y`
2026-01-01 05:10:49 +00:00
mnemonikr c2f97d194f Added check for next_multiple_of in manual_div_ceil 2025-12-31 13:54:48 -08:00
Linshu Yang 67a76f9fb5 fix: implicit_saturating_sub suggests wrongly on untyped int literal 2025-12-29 18:43:57 +00:00
Philipp Krones 7f4b539293 Merge remote-tracking branch 'upstream/master' into rustup 2025-12-25 20:50:32 +01:00
Boxy Uwu 7a3097f18d Fix tools 2025-12-23 13:55:00 +00:00
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
Camille Gillot f57b09d0f2 Introduce Operand::RuntimeChecks. 2025-12-14 17:25:53 +00:00
Camille Gillot 8e967a5a7b Replace Rvalue::NullaryOp by a variant in mir::ConstValue. 2025-12-14 17:25:51 +00:00
bors 6a98e2c68b Auto merge of #146348 - jdonszelmann:eiiv3, r=lcnr,oli-obk
Externally implementable items

Supersedes https://github.com/rust-lang/rust/pull/140010
Tracking issue: https://github.com/rust-lang/rust/issues/125418

Getting started:

```rust
#![feature(eii)]

#[eii(eii1)]
pub fn decl1(x: u64)
// body optional (it's the default)
{
    println!("default {x}");
}

// in another crate, maybe
#[eii1]
pub fn decl2(x: u64) {
    println!("explicit {x}");
}

fn main() {
    decl1(4);
}
```

- tiny perf regression, underlying issue makes multiple things in the compiler slow, not just EII, planning to solve those separately.
- No codegen_gcc support, they don't have bindings for weak symbols yet but could
- No windows support yet for weak definitions

This PR merges the implementation of EII for just llvm + not windows, doesn't yet contain like a new panic handler implementation or alloc handler. With this implementation, it would support implementing the panic handler in terms of EII already since it requires no default implementation so no weak symbols

The PR has been open in various forms for about a year now, but I feel that having some implementation merged to build upon
2025-12-14 04:20:26 +00:00
bors a0d1a66828 Auto merge of #149709 - Urgau:overhaul-filenames, r=davidtwco
Overhaul filename handling for cross-compiler consistency

This PR overhauls the way we handle filenames in the compiler and `rmeta` in order to achieve achieve cross-compiler consistency (ie. having the same path no matter if the filename was created in the current compiler session or is coming from `rmeta`).

This is required as some parts of the compiler rely on consistent paths for the soundness of generated code (see rust-lang/rust#148328).

In order to achieved consistency multiple steps are being taken by this PR:
 - by making `RealFileName` immutable
 - by only having `SourceMap::to_real_filename` create `RealFileName`
   - currently `RealFileName` can be created from any `Path` and are remapped afterwards, which creates consistency issue
 - by also making `RealFileName` holds it's working directory, embeddable name and the remapped scopes
   - this removes the need for a `Session`, to know the current(!) scopes and cwd, which is invalid as they may not be equal to the scopes used when creating the filename

In order for `SourceMap::to_real_filename` to know which scopes to apply `FilePathMapping` now takes the current remapping scopes to apply, which makes `FileNameDisplayPreference` and company useless and are removed.

This PR is split-up in multiple commits (unfortunately not atomic), but should help review the changes.

Unblocks https://github.com/rust-lang/rust/pull/147611
Fixes https://github.com/rust-lang/rust/issues/148328
2025-12-13 14:32:09 +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
Matthias Krüger 0f0b2a7bff Rollup merge of #149884 - flip1995:clippy-subtree-update, r=matthiaskrgr
Clippy subtree update

r? ``````@Manishearth``````

Cargo.lock update due to Clippy version bump.
2025-12-12 12:19:11 +01:00
Jana Dönszelmann 8b69673c41 EII ast changes 2025-12-12 11:17:33 +01:00
Urgau b30c7c2554 Adapt Clippy to the overhaul filename handling 2025-12-12 07:34:51 +01: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
bors ce3c1773bd Auto merge of #149645 - GuillaumeGomez:doc-attr-based, r=jdonszelmann,jonathanbrouwer
Port `doc` attributes to new attribute API

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

This PR ports the `doc` attributes to the new attribute API. However, there are things that will need to be fixed in a follow-up:

* Some part of `cfg_old.rs` are likely unused now, so they should be removed.
* Not all error/lints are emitted at the same time anymore, making them kinda less useful considering that you need to run and fix rustc/rustdoc multiple times to get through all of them.
* For coherency with the other attribute errors, I didn't modify the default output too much, meaning that we have some new messages now. I'll likely come back to that to check if the previous ones were better in a case-by-case approach.
* `doc(test(attr(...)))` is handled in a horrifying manner currently. Until we can handle it correctly with the `Attribute` system, it'll remain that thing we're all very ashamed of. 😈
* A type in rustdoc got its size increased, I'll check the impact on performance. But in any case, I plan to improve it in a follow-up so should be "ok".
* Because of error reporting, some fields of `Doc` are suboptimal, like `inline` which instead of being an `Option` is a `ThinVec` because we report the error later on. Part of the things I'm not super happy about but can be postponed to future me.
* In `src/librustdoc/clean/cfg.rs`, the `pub(crate) fn parse(cfg: &MetaItemInner) -> Result<Cfg, InvalidCfgError> {` function should be removed once `cfg_trace` has been ported to new `cfg` API.
* Size of type `DocFragment` went from 32 to 48. Would be nice to get it back to 32.
* ``malformed `doc` attribute input`` wasn't meant for so many candidates, should be improved.
* See how many of the checks in `check_attr` we can move to attribute parsing
* Port target checking to be in the attribute parser completely
* Fix target checking for `doc(alias)` on fields & patterns

And finally, once this PR is merged, I plan to finally stabilize `doc_cfg` feature. :)

cc `@jdonszelmann`
r? `@JonathanBrouwer`
2025-12-11 21:08:19 +00:00
Philipp Krones 19f0c81b3f Merge commit '9e3e9649cbae7ed33ba62ca436f43081eaaedeb5' into clippy-subtree-update 2025-12-11 19:13:34 +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
Guillaume Gomez 503b34ab0d Update clippy code 2025-12-10 12:28:08 +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 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 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