Commit Graph

11085 Commits

Author SHA1 Message Date
Jeremy S
2d499d8f4a
Fix typo in exhaustive_items.rs 2024-03-22 22:19:31 +00:00
bors
c7bb200054 Auto merge of #12532 - samueltardieu:issue-12531, r=llogiq
Add necessary parentheses to `manual_unwrap_or_default` lint output

Fix #12531

----

changelog: [`manual_unwrap_or_default`]: add parentheses to suggestion when appropriate
2024-03-22 19:53:26 +00:00
bors
44a5edaaab Auto merge of #12507 - Alexendoo:unused-qualifications, r=dswij
Enable unused_qualifications lint

Fixes a common nit

changelog: none
2024-03-22 16:15:06 +00:00
Alex Macleod
a24d12b7aa Enable unused_qualifications lint 2024-03-22 15:58:29 +00:00
bors
52b2a5e50d Auto merge of #12529 - samueltardieu:issue-12528, r=y21
Do not warn on .map(_::clone) for Arc, Rc, and their weak variants

Those constructions are idiomatic, and using `Arc::clone(x)` and `Rc::clone(x)` is often the recommended way of cloning a `Arc` or a `Rc`.

Fix #12528

changelog: [`map_clone`]: do not warn on `.map(_::clone)` for `Arc`, `Rc`, and their `Weak` variants
2024-03-22 15:11:52 +00:00
Samuel Tardieu
2ffd1336c7 Add necessary parentheses to manual_unwrap_or_default lint output 2024-03-22 15:42:55 +01:00
bors
f2020c884f Auto merge of #12508 - y21:issue12506, r=llogiq
Fix infinite loop in `cast_sign_loss` when peeling unwrap method calls

Fixes #12506

The lint wants to peel method calls but didn't actually reassign the expression, leading to an infinite loop.

----

changelog: Fix infinite loop in [`cast_sign_loss`] when having two chained `.unwrap()` calls
2024-03-22 13:19:09 +00:00
bors
403433f2f7 Auto merge of #12526 - kpreid:patch-2, r=blyxyas
Mention `size_hint()` effect in `flat_map_option` lint documentation.

The previous documentation for `flat_map_option` mentioned only readability benefits, but there is also at least one performance benefit: the `size_hint()` upper bound is preserved, whereas `flat_map().size_hint()` is always `(0, None)`.

Program demonstrating this difference:

```rust
fn main() {
    let evens = |i| if i % 2 == 0 { Some(i) } else { None };

    dbg!(
        [1, 2, 3].iter().flat_map(evens).size_hint(),
        [1, 2, 3].iter().filter_map(evens).size_hint(),
    );
}
```

changelog: [`flat_map_option`]: Mention the benefit to `size_hint()`.
2024-03-22 13:09:28 +00:00
bors
fc053c3296 Auto merge of #12522 - rust-lang:Manishearth-patch-1, r=xFrednet
Correct version for incompatible_msrv

Unsure what happened here

Probably what caused https://github.com/rust-lang/blog.rust-lang.org/issues/1277

changelog: none
2024-03-22 10:12:29 +00:00
Samuel Tardieu
7c9fe30ce4 Do not warn on .map(_::clone) for Arc, Rc, and their weak variants
Those constructions are idiomatic, and using `Arc::clone(x)` and
`Rc::clone(x)` is often the recommended way of cloning a `Arc` or a
`Rc`.
2024-03-22 10:02:09 +01:00
Kevin Reid
15da6e735a
Mention size_hint() effect in flat_map_option lint documentation. 2024-03-21 14:06:45 -07:00
Philipp Krones
e1d15b5b87
Bump Clippy version -> 0.1.79 2024-03-21 22:06:41 +01:00
Philipp Krones
7d42d736c5
Merge remote-tracking branch 'upstream/master' into rustup 2024-03-21 22:05:29 +01:00
Rua
238cd36671 Fix documentation typo "appects" > "affects" 2024-03-21 18:22:23 +01:00
Manish Goregaokar
87b93520a8
Correct version for incompatible_msrv
Unsure what happened here

Probably what caused https://github.com/rust-lang/blog.rust-lang.org/issues/1277
2024-03-21 15:41:12 +00:00
bors
a16a9ed4c6 Auto merge of #12509 - xFrednet:changelog-1-77, r=dswij
Changelog for Clippy 1.77 🏫

Roses are violets,
Red is blue,
Let's create a world,
Perfect for me and you

---

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

<img width=500 src="https://github.com/rust-lang/rust-clippy/assets/17087237/ea13d05c-e5ba-4189-9e16-49bf1b43c468" alt="The cats of this Clippy release" />

The cat for the next release can be voted on: [here](https://forms.gle/57gbrNvXtCUmrHYh6)

The cat for the next next release can be nominated in the comments and will be voted in the next changelog PR (Submission deadline is 2024-03-30 23:59CET)

---

changelog: none
2024-03-20 23:43:14 +00:00
bors
34766a6792 Auto merge of #12496 - Jacherr:issue-12492, r=blyxyas
Disable `cast_lossless` when casting to u128 from any (u)int type

Fixes https://github.com/rust-lang/rust-clippy/issues/12492

Disables `cast_lossless` when casting to u128 from any int or uint type. The lint states that when casting to any int type, there can potentially be lossy behaviour if the source type ever exceeds the size of the destination type in the future, which is impossible with a destination of u128.

It's possible this is a bit of a niche edge case which is better addressed by just disabling the lint in code, but I personally couldn't think of any good reason to still lint in this specific case - maybe except if the source is a bool, for readability reasons :).

changelog: FP: `cast_lossless`: disable lint when casting to u128 from any (u)int type
2024-03-20 23:08:45 +00:00
bors
5b7efe827f Auto merge of #12516 - humannum14916:assigning_clones_msrv, r=Alexendoo
Make `assigning_clones` MSRV check more precise

Continuation of #12511

`clone_into` is the only suggestion subject to the 1.63 MSRV requirement, and the lint should still emit other suggestions regardless of the MSRV.

changelog: [assigning_clones]: only apply MSRV check to `clone_into` suggestions.
2024-03-20 20:41:41 +00:00
humannum14916
5f7b3c5eea Only enforce MSRV check on .clone_into() suggestions 2024-03-20 14:04:12 -04:00
Jacherr
477108d382 FP: cast_lossless: disable lint when casting to (u)128 from any (u)int type 2024-03-20 13:20:51 +00:00
bors
89aba8d45d Auto merge of #12511 - humannum14916:assigning_clones_msrv, r=Alexendoo
`assigning_clones` should respect MSRV

Fixes: #12502

This PR fixes the `assigning_clones` lint suggesting to use `clone_from` or `clone_into` on incompatible MSRVs.

`assigning_clones` will suggest using either `clone_from` or `clone_into`, both of which were stabilized in 1.63. If the current MSRV is below 1.63, the lint should not trigger.

changelog: [`assigning_clones`]: don't lint when the MSRV is below 1.63.
2024-03-19 23:46:51 +00:00
humannum14916
21a97f0192 Specify an MSRV of 1.63.0 for assigning_clones 2024-03-19 17:05:32 -04:00
goodmost
e7c3e049f8 chore: fix typo
Signed-off-by: goodmost <zhaohaiyang@outlook.com>
2024-03-19 22:09:05 +08:00
bors
56288a72be Auto merge of #122021 - oli-obk:delangitemification, r=compiler-errors
Use hir::Node helper methods instead of repeating the same impl multiple times

I wanted to do something entirely different and stumbled upon a bunch of cleanups
2024-03-19 11:05:45 +00:00
y21
3930f8b45d fix infinite loop when peeling unwrap method calls 2024-03-19 00:13:18 +01:00
xFrednet
83af0e5928
Update version attribute for 1.77 lints 2024-03-18 22:59:52 +01:00
Oli Scherer
0dc876991c Deduplicate associated_body and body_id
They match on almost the same patterns, which is fishy.

Also turn `associated_body` into a method and do some cleanups nearby the call sites
2024-03-18 18:12:32 +00:00
Oli Scherer
003c4bc7bf Avoid various uses of Option<Span> in favor of using DUMMY_SP in the few cases that used None 2024-03-18 09:34:08 +00:00
bors
b5dcaae844 Auto merge of #12498 - y21:issue12489, r=blyxyas
[`map_entry`]: call the visitor on the local's `else` block

Fixes #12489

The lint already has all the logic it needs for figuring out if it can or can't suggest a closure if it sees control flow expressions like `break` or `continue`, but it was ignoring the local's else block, which meant that it didn't see the `return None;` in a `let..else`.

changelog: [`map_entry`]: suggest `if let` instead of a closure when `return` expressions exist in the else block of a `let..else`
2024-03-18 06:28:47 +00:00
bors
e9a50f2859 Auto merge of #12451 - Jacherr:issue-12391, r=llogiq
new restriction lint: `integer_division_remainder_used`

Fixes https://github.com/rust-lang/rust-clippy/issues/12391

Introduces a restriction lint which disallows the use of `/` and `%` operators on any `Int` or `Uint` types (i.e., any that use the default `Div` or `Rem` trait implementations). Custom implementations of these traits are ignored.

----

changelog: Add new restriction lint [`integer_division_remainder_used`]
2024-03-17 08:10:32 +00:00
bors
d202eb653b Auto merge of #12450 - cookie-s:fix-optopt-duplicate-diags, r=llogiq
[`option_option`]: Fix duplicate diagnostics

Relates to #12379

This `option_option` lint change skips checks against `ty`s inside `field_def`s defined by external macro to prevent duplicate diagnostics to the same span `ty` by multiple `Struct` definitions.

---

changelog: [`option_option`]: Fix duplicate diagnostics
2024-03-17 07:51:49 +00:00
bors
67fa36a9f2 Auto merge of #12479 - y21:readonly_write_lock_perf, r=Jarcho
move `readonly_write_lock` to perf

[There haven't been any issues](https://github.com/rust-lang/rust-clippy/issues?q=is%3Aissue+readonly_write_lock) since its creation and it's a pretty useful lint I think, so I'd say it's worth giving it a try?

Did a lintcheck run on 300 crates with no results, but I guess `RwLock` is usually not something that's used much in libraries.

changelog: move [`readonly_write_lock`] to perf (now warn-by-default)
2024-03-17 03:35:17 +00:00
bors
12ecaa8367 Auto merge of #12482 - J-ZhengLi:issue12131, r=Jarcho
fix [`dbg_macro`] FN when dbg is inside some complex macros

fixes: #12131

It appears that [`root_macro_call_first_node`] only detects `println!` in the following example:
```rust
println!("{:?}", dbg!(s));
```
---

changelog: fix [`dbg_macro`] FN when `dbg` is inside some complex macros

(re-opening b'cuz bors doesn't like my previous one)
2024-03-17 03:22:20 +00:00
bors
59a5ad4840 Auto merge of #12441 - CBSpeir:dedup-else-if-without-else, r=dswij
[`else_if_without_else`]: Fix duplicate diagnostics

Relates to: #12379

changelog:  Fix duplicate lint diagnostic emission from [`else_if_without_else`]
2024-03-16 15:55:11 +00:00
y21
4e72ca31b5 [map_entry]: call the visitor on the local's else block 2024-03-16 14:15:45 +01:00
kcz
9408c5974e
[option_option]: Use span.from_expansion 2024-03-15 21:25:24 -04:00
bors
c9f24827b3 Auto merge of #12493 - y21:issue12491, r=Alexendoo
fix span calculation for non-ascii in `needless_return`

Fixes #12491

Probably fixes #12328 as well, but that one has no reproducer, so 🤷

The bug was that the lint used `rfind()` for finding the byte index of the start of the previous non-whitespace character:
```
// abc\n     return;
     ^
```
... then subtracting one to get the byte index of the actual whitespace (the `\n` here).
(Subtracting instead of adding because it treats this as the length from the `return` token to the `\n`)

That's correct for ascii, like here, and will get us to the `\n`, however for non ascii, the `c` could be multiple bytes wide, which would put us in the middle of a codepoint if we simply subtract 1 and is what caused the ICE.

There's probably a lot of ways we could fix this.
This PR changes it to iterate backwards using bytes instead of characters, so that when `rposition()` finally finds a non-whitespace byte, we *know* that we've skipped exactly 1 byte. This was *probably*(?) what the code was intending to do

changelog: Fix ICE in [`needless_return`] when previous line end in a non-ascii character
2024-03-15 17:30:23 +00:00
Guillaume Gomez
1e30c2915b Rollup merge of #122513 - petrochenkov:somehir4, r=fmease
hir: Remove `opt_local_def_id_to_hir_id` and `opt_hir_node_by_def_id`

Also replace a few `hir_node()` calls with `hir_node_by_def_id()`.

Follow up to https://github.com/rust-lang/rust/pull/120943.
2024-03-15 17:24:09 +01:00
y21
d3f8f3e9d7 fix span calculation for non-ascii in needless_return 2024-03-15 16:59:23 +01:00
bors
5a11fefc25 Auto merge of #12432 - Ethiraric:fix-12411, r=y21
[`unused_enumerate_index`]: trigger on method calls

The lint used to check for patterns looking like:
```rs
for (_, x) in some_iter.enumerate() {
    // Index is ignored
}
```

This commit further checks for chained method calls constructs where we
can detect that the index is unused. Currently, this checks only for the
following patterns:
```rs
some_iter.enumerate().map_function(|(_, x)| ..)
let x = some_iter.enumerate();
x.map_function(|(_, x)| ..)
```
where `map_function` is one of `all`, `any`, `filter_map`, `find_map`,
`flat_map`, `for_each` or `map`.

Fixes #12411.

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

changelog: [`unused_enumerate_index`]: add detection for method chains such as `iter.enumerate().map(|(_, x)| x)`
2024-03-14 22:26:06 +00:00
Ethiraric
dadcd94b2a [unused_enumerate_index]: Keep explicit element type
Prior to this change, it might be that the lint would remove an explicit
type that was necessary for the type system to keep track of types.

This should be the last change that prevented this lint to be machine
applicable.
2024-03-14 23:12:47 +01:00
bors
b667d02340 Auto merge of #12472 - GuillaumeGomez:fix-10262, r=blyxyas
Don't emit `doc_markdown` lint for missing backticks if it's inside a quote

Fixes #10262.

changelog: Don't emit `doc_markdown` lint for missing backticks if it's inside a quote
2024-03-14 21:39:25 +00:00
Vadim Petrochenkov
f55a04928f hir: Remove opt_local_def_id_to_hir_id and opt_hir_node_by_def_id
Also replace a few `hir_node()` calls with `hir_node_by_def_id()`
2024-03-14 22:34:24 +03:00
bors
8a78128e9d Auto merge of #12386 - Ethiraric:fix-12381, r=blyxyas
[`use_self`]: Make it aware of lifetimes

Have the lint trigger even if `Self` has generic lifetime parameters.

```rs
impl<'a> Foo<'a> {
    type Item = Foo<'a>; // Can be replaced with Self

    fn new() -> Self {
        Foo { // No lifetime, but they are inferred to be that of Self
              // Can be replaced as well
            ...
        }
    }

    // Don't replace `Foo<'b>`, the lifetime is different!
    fn eq<'b>(self, other: Foo<'b>) -> bool {
        ..
    }
```

Fixes #12381

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

changelog: [`use_self`]: Have the lint trigger even if `Self` has generic lifetime parameters
2024-03-14 16:28:57 +00:00
Guillaume Gomez
0e2897fd4f Rename hir::StmtKind::Local into hir::StmtKind::Let 2024-03-14 12:42:04 +01:00
maekawatoshiki
5f8d8f1656
Simplify logic 2024-03-14 12:48:34 +09:00
maekawatoshiki
560a5a8cd1 Fix logic 2024-03-14 12:36:55 +09:00
maekawatoshiki
20e4c74521 Handle false positive with map_clone 2024-03-14 12:36:54 +09:00
J-ZhengLi
fe4e0aca73 checks dbg inside other macros as well (but no ext macro);
some refractoring;
2024-03-14 09:32:05 +08:00
J-ZhengLi
0535f55831 lint nested dbg! macros, split tests 2024-03-14 09:29:29 +08:00