Commit graph

12144 commits

Author SHA1 Message Date
bors
73bad368f2 Auto merge of #13548 - wowinter13:unnecessary_filter_map_filter_map_some, r=llogiq
fix: remove unnecessary filter_map usages

fixes https://github.com/rust-lang/rust-clippy/issues/12556

(Fixed version of https://github.com/rust-lang/rust-clippy/pull/12766)

changelog: [unnecessary_filter_map]: filter map improvements
2024-10-27 22:27:49 +00:00
bors
c02f3a2822 Auto merge of #13600 - samueltardieu:push-tzuvnutssmrs, r=xFrednet
borrow_deref_ref: do not trigger on `&raw` references

changelog: [`borrow_deref_ref`]: do not trigger on `&raw` references

Fix #13584
2024-10-27 12:37:40 +00:00
J-ZhengLi
c4815aeef1 [infinite_loops]: fix suggestion error on async functions/closures 2024-10-26 17:18:02 +00:00
bors
9e36f89701 Auto merge of #125116 - blyxyas:ignore-allowed-lints-final, r=cjgillot
(Big performance change) Do not run lints that cannot emit

Before this change, adding a lint was a difficult matter because it always had some overhead involved. This was because all lints would run, no matter their default level, or if the user had `#![allow]`ed them. This PR changes that. This change would improve both the Rust lint infrastructure and Clippy, but Clippy will see the most benefit, as it has about 900 registered lints (and growing!)

So yeah, with this little patch we filter all lints pre-linting, and remove any lint that is either:
- Manually `#![allow]`ed in the whole crate,
- Allowed in the command line, or
- Not manually enabled with `#[warn]` or similar, and its default level is `Allow`

As some lints **need** to run, this PR also adds **loadbearing lints**. On a lint declaration, you can use the ``@eval_always` = true` marker to label it as loadbearing. A loadbearing lint will never be filtered (it will always run)

Fixes #106983
2024-10-26 16:37:43 +00:00
Deadbeef
350d1c4aee Effects cleanup
- removed extra bits from predicates queries that are no longer needed in the new system
- removed the need for `non_erasable_generics` to take in tcx and DefId, removed unused arguments in callers
2024-10-26 10:19:07 +08:00
GnomedDev
560353c90a
Stop linting unused_io_amount in io traits 2024-10-26 00:39:18 +01:00
bors
9cf416dc6e Auto merge of #13586 - evanj:evan.jones/long-paragraph-edit, r=xFrednet
docs: Fix too_long_first_doc_paragraph: line -> paragraph

The documentation for too_long_first_doc_paragraph incorrectly says "line" where it should say "paragraph".

Fix a minor typo: doscstring -> docstring.

Also do a few tiny edits to attempt to make the wording slightly shorter and clearer.

changelog: [`too_long_first_doc_paragraph`]: Edit documentation
2024-10-24 19:29:29 +00:00
bors
6bcd0b9b42 Auto merge of #13558 - alex-semenyuk:const_is_empty_fix, r=dswij
Don't trigger `const_is_empty` for inline const assertions

Close #13106

Considered case was described [here](https://github.com/rust-lang/rust-clippy/pull/13114#issuecomment-2266629991)

changelog: [`const_is_empty`]: skip const_is_empty for inline const assertions
2024-10-24 13:55:52 +00:00
Samuel Tardieu
b0412d0dd7 borrow_deref_ref: do not trigger on &raw references 2024-10-24 09:03:15 +02:00
Ralf Jung
54f9bc4884 nightly feature tracking: get rid of the per-feature bool fields 2024-10-23 09:14:41 +01:00
Evan Jones
0bcc6f8156
docs: Fix too_long_first_doc_paragraph: line -> paragraph
The documentation for too_long_first_doc_paragraph incorrectly says
"line" where it should say "paragraph".

Fix a minor typo: doscstring -> docstring.

Also do a few tiny edits to attempt to make the wording slightly
shorter and clearer.

changelog: Edit documentation for [`too_long_first_doc_paragraph`]
2024-10-22 16:04:30 -04:00
Michael Goulet
088f07a0a7 Represent TraitBoundModifiers as distinct parts in HIR 2024-10-22 19:48:44 +00:00
Ralf Jung
2fd8222bd4 terminology: #[feature] *enables* a feature (instead of "declaring" or "activating" it) 2024-10-22 07:37:54 +01:00
blyxyas
3773534f29 Move COGNITIVE_COMPLEXITY to use macro again 2024-10-21 19:27:34 +02:00
bors
8538562429 Auto merge of #13567 - y21:span_debug_assertions, r=flip1995
Add debug assertions for empty replacements and overlapping spans

rustc has debug assertions [^1] [^2] that check that a substitution doesn't have an empty suggestion string and an empty span at the same time, as well as that spans in multipart suggestions don't overlap.
However, since we link to the rustc-dev distributed compiler, these debug assertions are always disabled and so we never actually run them.

This leads to the problem that the debug ICE is not necessarily caught in the PR and only triggered in the rust repo sync, and in one of the last syncs this was a blocker and delayed the sync by several weeks because the fix was not obvious.

So this PR essentially copies the checks over and runs them in clippy debug builds as well, so that we can catch these errors in PRs directly.

-----
As for the second commit, this also *did* cause an ICE in a sync before and was fixed in the sync PR (see https://github.com/rust-lang/rust/pull/120345#issuecomment-1911005554), but it seems like that commit didn't make it back into the clippy repo (cc `@flip1995),` so the fixed code is in the rust repo but not in the clippy repo.

changelog: none

[^1]: https://doc.rust-lang.org/1.82.0/nightly-rustc/src/rustc_errors/diagnostic.rs.html#1019
[^2]: https://doc.rust-lang.org/1.82.0/nightly-rustc/src/rustc_errors/diagnostic.rs.html#932
2024-10-21 08:26:32 +00:00
bors
1d0dad5eb3 Auto merge of #131988 - matthiaskrgr:rollup-tx173wn, r=matthiaskrgr
Rollup of 4 pull requests

Successful merges:

 - #126588 (Added more scenarios where comma to be removed in the function arg)
 - #131728 (bootstrap: extract builder cargo to its own module)
 - #131968 (Rip out old effects var handling code from traits)
 - #131981 (Remove the `BoundConstness::NotConst` variant)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-10-21 06:13:34 +00:00
y21
b3bf128e54 don't lint nested items that don't have generated documentation in missing_docs_in_private_items 2024-10-20 23:42:28 +02:00
y21
2f71ce6651 don't lint unnamed constants in missing_docs_in_private_items 2024-10-20 22:14:02 +02:00
y21
65eb1ec0fb remove the semicolon for builtin macro call statements in statement_outside_block
The expansion of `asm!()` and `line!()` is not marked as from an expansion, in which case `SourceMap::stmt_span` returns the input span unchanged. So instead of using `stmt_span`, use `mac_call_stmt_semi_span` directly
2024-10-20 19:00:55 +02:00
Michael Goulet
d8b2f9364d Rip out old effects var handling code from traits 2024-10-20 13:40:22 +00:00
alexey semenyuk
64c4cf1cba
Fix version for ref_option 2024-10-20 14:43:32 +05:00
Michael Goulet
69b088626c Fix tests 2024-10-19 18:07:35 +00:00
y21
4de65a113f fix empty suggestion ICE in from_over_into 2024-10-19 19:24:09 +02:00
blyxyas
e518d66dc0 Apply review comments + use shallow_lint_levels_on 2024-10-19 16:20:52 +02:00
blyxyas
e427a4e694 Remove module passes filtering 2024-10-19 16:20:51 +02:00
blyxyas
8f8aa46a87 Follow review comments (optimize the filtering) 2024-10-19 16:20:33 +02:00
blyxyas
698363122e Do not run lints that cannot emit
Before this change, adding a lint was a difficult matter
because it always had some overhead involved. This was
because all lints would run, no matter their default level,
or if the user had #![allow]ed them. This PR changes that
2024-10-19 16:19:44 +02:00
bors
5678531c6d Auto merge of #13564 - GnomedDev:fix-manualbits-in-macro, r=blyxyas
Stop linting manual_bits in any macro invoke

Closes #13563.

changelog: [`manual_bits`] No longer lints in macro-generated code
2024-10-19 14:09:28 +00:00
bors
f2f0175eb2 Auto merge of #13543 - GnomedDev:symbol-comparisons, r=y21
Add internal lint to check for slow symbol comparisons

See the conversation on [Zulip](https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/Checking.20a.20Symbol.20is.20equal.20to.20a.20string.20literal).

changelog: none
2024-10-18 23:20:38 +00:00
GnomedDev
a739cc3abe
Stop linting manual_bits in any macro invoke 2024-10-18 21:41:05 +01:00
Philipp Krones
91a458f451 Hotfix TRAIT_METHODS static->const 2024-10-18 14:54:06 +02:00
Philipp Krones
fea5e77da1 Merge commit 'a109190d7060236e655fc75533373fa274ec5343' into clippy-subtree-update 2024-10-18 13:44:06 +02:00
Philipp Krones
4d5eaa0344
Bump Clippy version -> 0.1.84 2024-10-18 13:25:50 +02:00
Philipp Krones
224d1e323a
Merge remote-tracking branch 'upstream/master' into rustup 2024-10-18 13:25:37 +02:00
Alexey Semenyuk
8555922351 Don't trigger const_is_empty for inline const assertions 2024-10-17 22:36:26 +05:00
bors
dae1be90ee Auto merge of #13525 - xFrednet:changelog-1-82, r=dswij
Changelog for Clippy 1.82 ✈️

```
Roses are red,
Violets are blue,
EuroRust in Austria,
    RustConf in Canada.
```

---

### The cat of this release is *Racka*:

<img height=500 src="https://github.com/user-attachments/assets/e5e3cc95-6fc3-4214-aab0-4f26e0967ae5" alt="The cats of this Clippy release" />

Cats for the next release can be nominated in the comments :D

---

changelog: none
2024-10-17 11:13:09 +00:00
wowinter13
ad002ea99f fix: linter 2024-10-16 01:49:15 +02:00
wowinter13
40cb24f23c fix: simplify suggestion 2024-10-16 01:42:43 +02:00
Anastasis Georgoulas
48636259df Correct typo in lint description 2024-10-15 22:47:04 +01:00
Asuna
ac81f176a8 Change the category of manual_is_power_of_two to pedantic 2024-10-15 21:27:46 +02:00
GnomedDev
b62d2624ac
Use path_res instead of lowering hir::Ty to ty::Ty 2024-10-15 17:06:21 +01:00
GnomedDev
42511a3ffa
Add lint for unnecessary lifetime bounded &str return 2024-10-15 17:06:21 +01:00
xFrednet
fcf46466ce
Move too_long_first_doc_paragraph to nursery
See: https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/too_long_first_doc_paragraph.20to.20nursery.3F/near/476448239
2024-10-15 17:08:53 +02:00
wowinter13
11162d1b48 fix: remove unnecessary unfilter_map usages 2024-10-15 00:18:50 +02:00
Michael Goulet
360d86e9ec Move trait bound modifiers into hir::PolyTraitRef 2024-10-14 09:20:38 -04:00
bors
f444012c4c Auto merge of #13454 - samueltardieu:push-ymnkzlqloptz, r=xFrednet
Use correct std/core prefix in lint output

changelog: none

I was waiting for #13452 to be merged before sending this one. `std` is used instead of `core` when appropriate in messages.
2024-10-14 13:12:22 +00:00
bors
43e99e54fa Auto merge of #13541 - xFrednet:0-module-name-rep, r=blyxyas
Move `clippy::module_name_repetitions` to `restriction` (from `pedantic`)

Rational:
- Too pedantic IMO, I use `#[warn(pedantic)]` in my personal projects, but then always allow this lint. The fact that we had a few `#[expect(clippy::module_name_repetitions)]` also underlines this point IMO
- STD doesn't do this either. Examples:
  - std::vec::Vec
  - std::collections::vec_deque::VecDequeue
- #7666 commonly ignored

---

changelog: Move [`module_name_repetitions`] to `restriction` (from `pedantic`)
[#13541](https://github.com/rust-lang/rust-clippy/pull/13541)
2024-10-13 23:39:55 +00:00
GnomedDev
dedc380df9
Apply fixes from lint 2024-10-13 21:03:38 +01:00
bors
6a281e9a73 Auto merge of #13487 - Coekjan:fix-slice-size-calc-on-ref-ref, r=dswij
Fix lint `manual_slice_size_calculation` when a slice is ref more than once

When a slice is ref more than once, current suggestion given by `manual_slice_size_calculation` is wrong. For example:

```rs
let s: &[i32] = &[1, 2][..];
let ss: &&[i32] = &s;  // <-----

let _ = size_of::<i32>() * ss.len();
```

clippy now suggests:

```patch
- let _ = size_of::<i32>() * ss.len();
+ let _ = size_of_val(ss);
```

However, this can result in calculating the size of `&[i32]`, instead of `[i32]` (this wrong suggestion also leads to `size_of_ref` warning: https://rust-lang.github.io/rust-clippy/master/index.html#/size_of_ref )

Now I am sending this PR to fix this bug, so that clippy will suggest (some deref added):

```patch
- let _ = size_of::<i32>() * ss.len();
+ let _ = size_of_val(*ss);
```

As I am not familiar with current clippy code-base, please correct me if I am not doing well or I can do it better :)

changelog: [`manual_slice_size_calculation`]: fix a bug when a slice is ref more than once.
2024-10-13 15:49:30 +00:00
GnomedDev
6b1779b0ee
Add lint to check for slow symbol comparisons 2024-10-13 16:36:22 +01:00
bors
f883e28e3d Auto merge of #13542 - blyxyas:fix-implicit_saturating_sub, r=y21
[`implicit_saturating_sub`] Fix suggestion with a less volatile approach

Related to #13533, such and obvious mistake got pass my watch, quite embarassing :/

Revert #13533 and implement a more robust solution.

Revert "Fix span issue on `implicit_saturating_sub`
This reverts commit 140a1275f2.

changelog: [`lint_name`]: Fix suggestion for `if {} else if {} else {}` cases

r? `@y21`
2024-10-13 15:24:05 +00:00
bors
236751d093 Auto merge of #13540 - GnomedDev:create-dir-single-arg, r=y21
Check MethodCall/Call arg count earlier or at all

This gets rid of a bunch of possible panic spots, as well as bailing out earlier for optimisation reasons.

I started doing this because I saw that a significant amount of time was being spent in the `create_dir` restriction lint when running clippy with `perf`, but this also helps with robustness.

changelog: none
2024-10-13 13:34:48 +00:00
GnomedDev
ef1db3f502 Check MethodCall/Call arg count earlier or at all 2024-10-13 11:24:47 +01:00
bors
04849bd7d9 Auto merge of #13510 - alex-semenyuk:cleanup_const_float_classify, r=llogiq
Cleanup `const_float_classify`

As mentioned at #13508 `const_float_classify` has been stabilized recently in https://github.com/rust-lang/rust/pull/130157 and can be cleanup

Close #13508

changelog: [none]
2024-10-13 09:17:14 +00:00
Samuel Tardieu
46a0770102 Use correct std/core prefix in lint output 2024-10-13 10:48:27 +02:00
bors
c71f0bebd2 Auto merge of #13334 - nyurik:ascii-str-eq, r=xFrednet
Add manual_ignore_cast_cmp lint

```rust
// bad
fn compare(a: &str, b: &str) -> bool {
    a.to_ascii_lowercase() == b.to_ascii_lowercase()
    || a.to_ascii_lowercase() == "abc"
}

// good
fn compare(a: &str, b: &str) -> bool {
   a.eq_ignore_ascii_case(b)
   || a.eq_ignore_ascii_case("abc")
}
```

- [x] Followed [lint naming conventions][lint_naming]
- [x] Added passing UI tests (including committed `.stderr` file)
- [x] `cargo test` passes locally
- [x] Executed `cargo dev update_lints`
- [x] Added lint documentation
- [x] Run `cargo dev fmt`

changelog: New lint: [`manual_ignore_case_cmp`] `perf`
[#13334](https://github.com/rust-lang/rust-clippy/pull/13334)

Closes #13204
2024-10-13 07:34:38 +00:00
Matthias Krüger
b1c468422a Rollup merge of #131277 - ismailarilik:handle-potential-query-instability-lint-for-clippy, r=xFrednet
Handle `clippy` cases of `rustc::potential_query_instability` lint

This PR removes `#![allow(rustc::potential_query_instability)]` line from [`src/tools/clippy/clippy_lints/src/lib.rs`](https://github.com/rust-lang/rust/blob/master/src/tools/clippy/clippy_lints/src/lib.rs#L30) and converts `FxHash{Map,Set}` types into `FxIndex{Map,Set}` to suppress lint errors.

A somewhat tracking issue: https://github.com/rust-lang/rust/issues/84447
2024-10-12 23:00:57 +02:00
bors
55f6029baa Auto merge of #13444 - kpreid:fix-8524-private-rep, r=blyxyas
`module_name_repetitions`: don't warn if the item is in a private module.

Fixes <https://github.com/rust-lang/rust-clippy/issues/8524>.

There is still a warning (as there should be) if the item is reexported by name, but not by glob; that would require further work to examine the names in the glob, and I haven't looked into that.

Credit to `@Centri3` for suggesting approximately this simple fix in <https://github.com/rust-lang/rust-clippy/issues/8524#issuecomment-1729036149>. However, per later comment <https://github.com/rust-lang/rust-clippy/issues/8524#issuecomment-2035836495>, I am not making it configuration-dependent, but *always* checking public items in public modules only.

changelog: [`module_name_repetitions`]: don't warn if the item is in a private module.
2024-10-12 16:46:31 +00:00
blyxyas
2b562dece6 Fix suggestion with a less volatile approach
Revert "Fix span issue on `implicit_saturating_sub`"
This reverts commit 140a1275f2.
2024-10-12 17:43:06 +02:00
xFrednet
8b075fc634
Move clippy::module_name_repetitions to restriction (from pedantic)
Rational:
- Too pedantic IMO, it's often better to have fine grained modules and
  then rexport stuff instead of one gigantic file
- STD doesn't do this either. Examples:
  - std::vec::Vec
  - std::collections::vec_deque::VecDequeue
- rust-clippy#7666 commonly ignored
2024-10-12 12:03:24 +02:00
Manish Goregaokar
42723dc9df Mark unnecessary_first_then_check and byte_char_slices as Applicable 2024-10-11 12:20:07 -07:00
bors
b85f632607 Auto merge of #13528 - zvavybir:master, r=Alexendoo
Improved wording of or_fun_call lint

The current wording (e.g. ``use of `ok_or` followed by a function call``) is potentially confusing (at least it confused me) by suggesting that the function that follows the (in this case) `ok_or` is the problem and not the function that is an argument to it.

The code in my program that triggered the confusing message is the following:
```rust
let file_id = buf
    .lines()
    .next()
    .ok_or((
        InternalError::ProblemReadingFromInbox,
        anyhow!("No first line in inbox response ({file:?}): {buf:?}"),
    ))
    .html_context(stream, lang)?;
```
I thought that `html_context` was the problem and that I should do something along the following lines:
```rust
let file_id = buf
    .lines()
    .next()
    .ok_or_else(
        (
            InternalError::ProblemReadingFromInbox,
            anyhow!("No first line in inbox response ({file:?}): {buf:?}"),
        ),
        html_context(stream, lang),
    )?
```
This is of course wrong.  My confusion was only cleared up through the help message indicating what I should try instead.

If someone has a better idea of a replacement wording (currently e.g. ``` function call inside of `ok_or` ```), I'm all ears.

changelog: none
2024-10-11 15:01:07 +00:00
bors
8125cd5c2a Auto merge of #13359 - blyxyas:declare_clippy_macro, r=Alexendoo
Turn declare_clippy_lint into a declarative macro

Ease of development, and hopefully compile times (the dependencies are still there because of ui-test). The procedural macro was doing just some very basic processing (like assigning a lint level to each category), so it didn't have a reason to stay IMO

changelog: None
2024-10-11 14:10:01 +00:00
bors
47903dbf97 Auto merge of #13532 - y21:issue13531, r=Alexendoo
Only emit `manual_c_str_literals` in >= Edition 2021

Fixes #13531

changelog: none
2024-10-11 12:47:38 +00:00
bors
05f3793392 Auto merge of #13534 - GnomedDev:fix-large-stack-arrays-nested-item, r=flip1995
Fix large_stack_arrays triggering when nesting const items

Fixes #13529.

r? `@flip1995`

changelog: [`large_stack_arrays`]: No longer triggers in static/const context when using nested items
2024-10-11 09:04:46 +00:00
bors
14c05c974c Auto merge of #13533 - blyxyas:fix-implicit_saturating_sub, r=dswij
Fix span issue on `implicit_saturating_sub`

Fixes #13524

changelog: [`implicit_saturating_sub`]: Fix span issue on else blocks
2024-10-11 06:25:08 +00:00
GnomedDev
87b4c1ffb7
Fix large_stack_arrays triggering when nesting const items 2024-10-10 22:01:46 +01:00
blyxyas
140a1275f2 Fix span issue on implicit_saturating_sub
Fixes #13524
2024-10-10 19:10:04 +02:00
Alexey Semenyuk
cb19f23c79 Clean up const_float_classify leftovers 2024-10-10 22:08:45 +05:00
y21
2b86ffc57e only emit manual_c_str_literals in >= edition2021 2024-10-10 18:08:40 +02:00
bors
806a9dfddd Auto merge of #13464 - y21:issue13458, r=flip1995
Don't warn on proc macro generated code in `needless_return`

Fixes #13458
Fixes #13457
Fixes #13467
Fixes #13479
Fixes #13481
Fixes #13526
Fixes #13486

The fix is unfortunately a little more convoluted than just simply adding a `is_from_proc_macro`. That check *does*  fix the issue, however it also introduces a bunch of false negatives in the tests, specifically when the returned expression is in a different syntax context, e.g. `return format!(..)`.

The proc macro check builds up a start and end pattern based on the HIR nodes and compares it to a snippet of the span, however that would currently fail for `return format!(..)` because we would have the patterns `("return", <something inside of the format macro>)`, which doesn't compare equal. So we now return an empty string pattern for when it's in a different syntax context.

"Hide whitespace" helps a bit for reviewing the proc macro detection change

changelog: none
2024-10-10 11:34:13 +02:00
bors
8e60f143d8 Auto merge of #13464 - y21:issue13458, r=flip1995
Don't warn on proc macro generated code in `needless_return`

Fixes #13458
Fixes #13457
Fixes #13467
Fixes #13479
Fixes #13481
Fixes #13526
Fixes #13486

The fix is unfortunately a little more convoluted than just simply adding a `is_from_proc_macro`. That check *does*  fix the issue, however it also introduces a bunch of false negatives in the tests, specifically when the returned expression is in a different syntax context, e.g. `return format!(..)`.

The proc macro check builds up a start and end pattern based on the HIR nodes and compares it to a snippet of the span, however that would currently fail for `return format!(..)` because we would have the patterns `("return", <something inside of the format macro>)`, which doesn't compare equal. So we now return an empty string pattern for when it's in a different syntax context.

"Hide whitespace" helps a bit for reviewing the proc macro detection change

changelog: none
2024-10-10 09:17:20 +00:00
Matthias Kaak
8c46c498d9 Improved wording of or_fun_call lint
Signed-off-by: Matthias Kaak <zvavybir@zvavybir.eu>
2024-10-10 08:05:41 +00:00
xFrednet
33018b46f4
Update version attribute for 1.81 lints 2024-10-09 19:04:20 +02:00
bors
1f8f982f22 Auto merge of #13504 - samueltardieu:needless-raw-strings, r=Alexendoo
Check for needless raw strings in `format_args!()` template as well

changelog: [`needless_raw_strings`, `needless_raw_string_hashes`]: check `format_args!()` template as well

Fix #13503
2024-10-09 01:35:08 +00:00
bors
d9c8d976cb Auto merge of #13512 - samueltardieu:issue-13511, r=xFrednet
`infinite_loop`: continuing an outer loop leaves the inner loop

changelog: [`infinite_loop`]: detect a `continue` targeting an outer loop

Fix #13511
2024-10-08 08:49:07 +00:00
Samuel Tardieu
36c31db705 Apply updated needless_raw_strings to Clippy sources 2024-10-07 18:29:25 +02:00
Samuel Tardieu
5e78c15caa raw_strings: handle format template as well 2024-10-07 18:29:24 +02:00
bors
b013e69692 Auto merge of #13496 - y21:issue10619, r=Alexendoo
Show interior mutability chain in `mutable_key_type`

Fixes #10619

Just ran into this myself and I definitely agree it's not very nice to have to manually go through all the types involved to figure out why this happens and to evaluate if this is really a problem (knowing if the field of a struct is something that a hash impl relies on), so this changes the lint to emit notes for each step involved.

changelog: none
2024-10-07 15:32:34 +00:00
Samuel Tardieu
99ce411ed6 infinite_loop: continuing an outer loop leaves the inner loop 2024-10-06 19:19:27 +02:00
bors
1c9e5d0e5c Auto merge of #13513 - samueltardieu:push-zvvzytrovulq, r=y21
Style: do not defensively use `saturating_sub()`

Using `saturating_sub()` here in code which cannot fail brings a false sense of security. If for any reason a logic error was introduced and caused `self.loop_depth` to reach 0 before being decremented, using `saturating_sub(1)` would silently mask the programming error instead of panicking loudly as it should (at least in dev profile).

changelog: none
2024-10-06 17:15:53 +00:00
Samuel Tardieu
af6816c5b6 infinite_loop: do not defensively use saturating_sub()
Using `saturating_sub()` here in code which cannot fail brings a false
sense of security. If for any reason a logic error was introduced and
caused `self.loop_depth` to reach 0 before being decremented, using
`saturating_sub(1)` would silently mask the programming error instead of
panicking loudly as it should (at least in dev profile).
2024-10-06 18:52:24 +02:00
codemountains
2226f16945 Rename NestedMetaItem to MetaItemInner 2024-10-06 23:28:30 +09:00
bors
f7aaecf3f5 Auto merge of #13506 - samueltardieu:push-zyqvkwlswvkk, r=xFrednet
unused_result_ok: added in Clippy 1.82.0, not 1.70.0

changelog: none

Fix #13497
2024-10-06 11:33:31 +00:00
bors
2d2e8cc21f Auto merge of #13485 - GnomedDev:reduce-large-threshold, r=xFrednet
Reduce default 'large array' threshold

As-is this threshold is `512kb`, but as #9449 points out this is way too high for most people to consider sensible (why would you want to copy `256kb` of data around on the stack or duplicate it via `const`) and didn't get any discussion when originally added. This PR reduces it the threshold to `1kb`, which is higher than the issue says ("a few cpu words") but helps out for actual codebases.

While reducing this, I found that `large_stack_arrays` was triggering for statically promoted arrays in constants/statics, so I also fixed that up as seen in the difference to [array_size_threshold.stderr](https://github.com/rust-lang/rust-clippy/compare/master...GnomedDev:rust-clippy:reduce-large-threshold?expand=1#diff-4c2a2a855d9ff7777f1d385be0c1bede2a3fc8aaab94837cde27a35235233fc7).

Closes #9449.

changelog: [`large_stack_arrays`]: No longer triggers in `static`/`const` context
changelog: [`large_const_arrays`]: Changed the default of [`array-size-threshold`] from `512kb` to `16kb`
2024-10-06 11:24:28 +00:00
Samuel Tardieu
0596a04bf4 unused_result_ok: added in Clippy 1.82.0, not 1.70.0 2024-10-05 23:50:14 +02:00
Samuel Tardieu
846bd30cfe raw_strings: separate raw string detection from lint logic 2024-10-05 23:17:29 +02:00
bors
753629bb33 Auto merge of #13412 - GnomedDev:regex-comp-in-loop, r=y21
Implement lint for regex::Regex compilation inside a loop

Closes #598.

Seems like a pretty simple one, I'm not sure if I sorted out all the lint plumbing correctly because I was adding it to the existing regex pass, but seems to work. The name is a bit jank and I'm super open to suggestions for changing it.

changelog: [`regex_creation_in_loops`]: Added lint for Regex compilation inside loops.
2024-10-05 18:41:45 +00:00
GnomedDev
196dbcf6d5
Avoid linting for Regexes compiled in items defined in loops 2024-10-05 17:10:21 +01:00
bors
a1beaa1992 Auto merge of #129244 - cjgillot:opaque-hir, r=compiler-errors
Make opaque types regular HIR nodes

Having opaque types as HIR owner introduces all sorts of complications. This PR proposes to make them regular HIR nodes instead.

I haven't gone through all the test changes yet, so there may be a few surprises.

Many thanks to `@camelid` for the first draft.
Fixes https://github.com/rust-lang/rust/issues/129023

Fixes #129099
Fixes #125843
Fixes #119716
Fixes #121422
2024-10-05 06:19:35 +00:00
ismailarilik
0b632ec812 Handle clippy cases of rustc::potential_query_instability lint 2024-10-05 07:34:14 +03:00
Camille GILLOT
8ad3e13765 Adapt clippy. 2024-10-04 23:50:02 +00:00
Jubilee
47b681d276 Rollup merge of #130518 - scottmcm:stabilize-controlflow-extra, r=dtolnay
Stabilize the `map`/`value` methods on `ControlFlow`

And fix the stability attribute on the `pub use` in `core::ops`.

libs-api in https://github.com/rust-lang/rust/issues/75744#issuecomment-2231214910 seemed reasonably happy with naming for these, so let's try for an FCP.

Summary:
```rust
impl<B, C> ControlFlow<B, C> {
    pub fn break_value(self) -> Option<B>;
    pub fn map_break<T>(self, f: impl FnOnce(B) -> T) -> ControlFlow<T, C>;
    pub fn continue_value(self) -> Option<C>;
    pub fn map_continue<T>(self, f: impl FnOnce(C) -> T) -> ControlFlow<B, T>;
}
```

Resolves #75744

``@rustbot`` label +needs-fcp +t-libs-api -t-libs

---

Aside, in case it keeps someone else from going down the same dead end: I looked at the `{break,continue}_value` methods and tried to make them `const` as part of this, but that's disallowed because of not having `const Drop`, so put it back to not even unstably-const.
2024-10-04 14:11:34 -07:00
GnomedDev
995eb95000
Fix TRAIT_METHODS being large const array 2024-10-04 19:07:40 +01:00
GnomedDev
4b7c19018d
Fix large_stack_arrays triggering for static/constants 2024-10-04 19:06:39 +01:00
y21
19d1358b31 print cause chain in mutable_key_type 2024-10-03 21:27:05 +00:00
bors
a01975b152 Auto merge of #13493 - y21:trait_duplication_in_bounds_fix, r=Manishearth
Compare trait references in `trait_duplication_in_bounds` correctly

Fixes #13476
Fixes #11067
Fixes #9915
Fixes #9626

Currently, the `trait_duplication_in_bounds` lints has a helper type for a trait reference that can be used for comparison and hashing, represented as `{trait: Res, generic_args: Vec<Res>}`. However, there are a lot of issues with this. For one, a `Res` can't represent e.g. references, slices, or lots of other types, as well as const generics and associated type equality. In those cases, the lint simply ignores them and has no way of checking if they're actually the same.

So, instead of using `Res` for this, use `SpanlessEq` and `SpanlessHash` for comparisons with the trait path for checking if there are duplicates.

However, using `SpanlessEq` as is alone lead to a false negative in the test. `std::clone::Clone` + `foo::Clone` wasn't recognized as a duplicate, because it has different segments. So this also adds a new "mode" to SpanlessEq which compares by final resolution. (I've been wondering if this can't just be the default but it's quite a large scale change as it affects a lot of lints and I haven't yet looked at all uses of it to see if there are lints that really do care about having exactly the same path segments).

Maybe an alternative would be to turn the hir types/consts into middle types/consts and compare them instead but I'm not sure there's really a good way to do that

changelog: none
2024-10-03 21:16:22 +00:00
Matthias Krüger
743623d4f7 Rollup merge of #131183 - compiler-errors:opaque-ty-origin, r=estebank
Refactoring to `OpaqueTyOrigin`

Pulled out of a larger PR that uses these changes to do cross-crate encoding of opaque origin, so we can use them for edition 2024 migrations. These changes should be self-explanatory on their own, tho 😄
2024-10-03 21:52:46 +02:00
y21
d6be597fbc Use SpanlessEq for in trait_bounds lints 2024-10-03 15:49:37 +00:00
Philipp Krones
277c4e4baf Merge commit 'aa0d551351a9c15d8a95fdb3e2946b505893dda8' into clippy-subtree-update 2024-10-03 16:32:51 +02:00