Commit Graph

16048 Commits

Author SHA1 Message Date
Michael Goulet
73d293fb6d rename get_parent_node to parent_id 2023-01-04 00:43:13 +00:00
Andre Bogus
d3a50d2fda trim paths in box_default 2023-01-04 00:44:20 +01:00
bors
0bca8dd254 Auto merge of #10135 - ardislu:fix-typo, r=giraffate
Fix typo in installation instructions

changelog: none
<!-- changelog_checked -->
2023-01-03 14:17:55 +00:00
bors
8b1ac4539d Auto merge of #10141 - FoseFx:fosefx/9887, r=Jarcho
fix empty_structs_with_brackets suggestion errors

fixes #9887

I refer to [my comment](https://github.com/rust-lang/rust-clippy/issues/9887#issuecomment-1368495395) to explain this PR.

---

changelog: Sugg: [`empty_structs_with_brackets`]: The suggestion is no longer machine applicable, to avoid errors when accessing struct fields
[#10141](https://github.com/rust-lang/rust-clippy/pull/10141)
<!-- changelog_checked -->
2023-01-03 03:57:19 +00:00
bors
43349195f7 Auto merge of #10143 - EricWu2003:field_reassign_with_default-FP, r=Manishearth
don't lint field_reassign when field in closure

fixes #10136

This change makes the ContainsName struct visit all interior expressions, which means that ContainsName will return true even if `name` is used in a closure within `expr`.

---

changelog: FP: [`field_reassign_with_default`]: No longer lints cases, where values are initializes from closures capturing struct values
[#10143](https://github.com/rust-lang/rust-clippy/pull/10143)
<!-- changelog_checked -->
2023-01-03 03:16:18 +00:00
Tyler Weaver
0cee2c5095
Don't trigger lint if last method is to_lower/upper 2023-01-02 16:42:56 -07:00
Eric Wu
cf4e9813b0 use OnlyBodies instead of All
we only need to check closures, so
nestedfilter::All was overkill here.
2023-01-02 18:35:21 -05:00
Tyler Weaver
0aa7d73df3
Only remove method from end of recv, indent suggestion source
Signed-off-by: Tyler Weaver <maybe@tylerjw.dev>
2023-01-02 16:27:46 -07:00
Tyler Weaver
bd83650e91
Suggest using Path for comparing extensions
Signed-off-by: Tyler Weaver <maybe@tylerjw.dev>
2023-01-02 16:27:46 -07:00
bors
1a46dc0b9f Auto merge of #10138 - smoelius:unused_self-typo, r=xFrednet
Fix typo in `unused_self` diagnostic message

changelog: Msg: [`unused_self`]: The message now correctly uses *an*
[#10138](https://github.com/rust-lang/rust-clippy/pull/10138)
<!-- changelog_checked -->
2023-01-02 22:57:27 +00:00
bors
653f5d98d8 Auto merge of #10139 - chansuke:chore/fix-if_chain_ident, r=Jarcho
chore: fix identation of `if_chain` in `filter_map`

This is a really small fix.
If someone could take a look at it, I would appreciate it🙏

---

changelog: none
<!-- changelog_checked -->
2023-01-02 22:44:15 +00:00
bors
3006c7cd4f Auto merge of #10146 - Nilstrieb:💀, r=llogiq
Correct Gankra's name in the linkedlist lint

changelog: [`linkedlist`]: Update description
2023-01-02 20:14:21 +00:00
Nilstrieb
f53c6e2f15 Correct Gankra's name in the linkedlist lint 2023-01-02 19:58:00 +01:00
Andy Russell
9aef1a264a
reword dbg_macro labels 2023-01-02 12:09:26 -05:00
Max Baumann
7a1a9c8188
empty_structs_with_brackets: not MachineApplicable anymore 2023-01-02 14:58:10 +01:00
Eric Wu
01a2a9df43 [drop_ref]: don't lint idiomatic in match arm 2023-01-01 22:33:18 -05:00
Eric Wu
8de011fdf7 don't lint field_reassign when field in closure
This commit makes the ContainsName struct visit all interior
expressions, which means that ContainsName will return true
even if `name` is used in a closure within `expr`.
2023-01-01 21:41:46 -05:00
chansuke
6145194b68 chore: add simple comment for get_enclosing_block 2023-01-02 00:18:03 +09:00
chansuke
5b46f2db59 chore: fix identation of if_chain in filter_map 2023-01-02 00:17:52 +09:00
bors
a85e480dd1 Auto merge of #10110 - Niki4tap:needless_anyhow_return, r=Alexendoo
Fix FN in `needless_return`

Fixes #10051

changelog: Enhancement: [`needless_return`]: Now detects more cases for returns of owned values
[#10110](https://github.com/rust-lang/rust-clippy/pull/10110)
<!-- changelog_checked -->
2023-01-01 13:55:29 +00:00
Samuel Moelius
da7c99b81e Fix typo in unused_self diagnostic message 2023-01-01 06:21:28 -05:00
Ardis Lu
7a64a51818
Fix typo 2022-12-31 02:14:20 -08:00
bors
6ccd4ebd5b Auto merge of #10115 - rdrpenguin04:master, r=flip1995
Move `mutex_atomic` to `restriction`

By #4295, the general consensus seems to be that `mutex_atomic` is not a useful lint in most cases. If anything, it could be useful as a restriction on code that for whatever reason can't use atomics. Keeping it in `clippy::nursery` is harmful to people attempting to use clippy for soundness.

---

changelog: Moved [`mutex_atomic`] to `restriction`
[#10115](https://github.com/rust-lang/rust-clippy/pull/10115)
<!-- chnagelog_checked -->
2022-12-30 15:49:12 +00:00
Ray Redondo
0298095ac2 add comment about mutex_atomic issue to description 2022-12-29 14:48:36 -06:00
bors
cd579d69ec Auto merge of #106266 - matthiaskrgr:rollup-cxrdbzy, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #104531 (Provide a better error and a suggestion for `Fn` traits with lifetime params)
 - #105899 (`./x doc library --open` opens `std`)
 - #106190 (Account for multiple multiline spans with empty padding)
 - #106202 (Trim more paths in obligation types)
 - #106234 (rustdoc: simplify settings, help, and copy button CSS by not reusing)
 - #106236 (docs/test: add docs and a UI test for `E0514` and `E0519`)
 - #106259 (Update Clippy)
 - #106260 (Fix index out of bounds issues in rustdoc)
 - #106263 (Formatter should not try to format non-Rust files)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-12-29 19:40:06 +00:00
Matthias Krüger
d8365f9864 Rollup merge of #106259 - flip1995:clippyup, r=matthiaskrgr
Update Clippy

r? `@Manishearth`

I think this was the very first sync with no conflicts whatsoever. I love this time of the year :D
2022-12-29 18:24:32 +01:00
Esteban Küber
315bb10405 Account for multiple multiline spans with empty padding
Instead of

```
LL |    fn oom(
   |  __^
   | | _|
   | ||
LL | || ) {
   | ||_-
LL | |  }
   | |__^
```

emit

```
LL | // fn oom(
LL | || ) {
   | ||_-
LL | |  }
   | |__^
   ```
2022-12-29 09:13:40 -08:00
Philipp Krones
4ccafea92d Merge commit '4f3ab69ea0a0908260944443c739426cc384ae1a' into clippyup 2022-12-29 14:28:34 +01:00
bors
4f3ab69ea0 Auto merge of #10126 - flip1995:rustup, r=flip1995
Rustup

r? `@ghost`

Love this time of the year. No conflicts, because no one merges anything.

changelog: none
2022-12-29 13:26:43 +00:00
Philipp Krones
1f971866d1
Bump nightly version -> 2022-12-29 2022-12-29 14:24:44 +01:00
Philipp Krones
08535408e8
Merge remote-tracking branch 'upstream/master' into rustup 2022-12-29 14:24:30 +01:00
bors
22af8fe683 Auto merge of #10060 - alex-semenyuk:match_single_binding_fix, r=llogiq
Fix [match_single_binding] suggestion introduced an extra semicolon

Fix #9725

---

changelog: [`match_single_binding`]: suggestion no longer introduces unneeded semicolons
[#10060](https://github.com/rust-lang/rust-clippy/pull/10060)
<!-- changelog_checked -->
2022-12-29 09:23:03 +00:00
Nilstrieb
c617a8e01c Rename Rptr to Ref in AST and HIR
The name makes a lot more sense, and `ty::TyKind` calls it `Ref` already
as well.
2022-12-28 18:52:36 +01:00
bors
266eef7701 Auto merge of #10119 - koka831:doc/config-default-value, r=xFrednet
fix codeblocks in the document

While I've looked into https://github.com/rust-lang/rust-clippy/issues/9990, I found broken code blocks in the document.

This patch not only improves visibility, but also fixes a potential bug. When a lint description ends with code block, the string will have three backquotes at the end.
Since the current implementation prints the default value immediately after that, the markdown renderer is unable to properly close the code block.

e.g. `arithmetic_side_effects`, we can see code block is not rendered properly, and (I think) it's bit hard to understand what ``"defaults to `[]`"`` is meant.

![2022-12-26_01-51](https://user-images.githubusercontent.com/14945055/209476342-4d0b2e18-44b6-4c74-8c3c-4f4f0904e8ca.png)

In this PR, it will be rendered as:

![image](https://user-images.githubusercontent.com/14945055/209476353-07587b86-1100-445f-946d-41f62f741e51.png)

changelog: none

r? `@xFrednet`
2022-12-28 13:53:34 +00:00
bors
d98e714988 Auto merge of #10113 - EricWu2003:suboptimal_flops_incorrect_suggestion, r=Jarcho
fix incorrect suggestion in `suboptimal_flops`

fixes #10003

There was an error when trying to negate an expression like `x - 1.0`. We used to format it as `-x - 1.0` whereas a proper negation would be `-(x - 1.0)`.

Therefore, we add parentheses around the expression when it is `ExprKind::Binary`.

We also add parentheses around multiply and divide expressions, even though this is not strictly necessary.

changelog: [`suboptimal_flops`]: fix incorrect suggestion caused by an incorrect negation of floating point expressions.
2022-12-26 02:00:26 +00:00
Eric Wu
6bb6dd64d4 fix incorrect suggestion in suboptimal_flops
There was an error when trying to negate an expression
like `x - 1.0`. We used to format it as `-x - 1.0` whereas
a proper negation would be `-(x - 1.0)`.

Therefore, we add parentheses around the expression when it is a
Binary ExprKind.

We also add parentheses around multiply and divide expressions,
even though this is not strictly necessary.
2022-12-25 16:56:46 -05:00
koka
fae19a9a79
Place default values near its definitions
This patch not only improves visibility, but also fixes a potential bug.
When a lint description ends with code block, the string will have three
backquotes at the end.
Since the current implementation prints the default value immediately
after that, the markdown renderer is unable to properly close the code
block.
2022-12-26 01:51:46 +09:00
bors
4f1bae0c96 Auto merge of #10116 - tgross35:patch-1, r=llogiq
`not_unsafe_ptr_arg_deref` update documentation

changelog: [`not_unsafe_ptr_arg_deref`]: strengthened documentation wording, fixes #7714
2022-12-25 14:19:10 +00:00
Trevor Gross
12f2dea229 not_unsafe_ptr_arg_deref update documentation 2022-12-25 07:30:21 -05:00
Ray Redondo
0e5fcb7b7f move mutex_atomic to clippy::restriction 2022-12-24 23:47:14 -06:00
bors
e8703a0ce2 Auto merge of #10098 - lukaslueg:size_of_ref, r=Jarcho
Add size_of_ref lint

This addresses #9995, which is likely raising a valid point about `std::mem::size_of_val()`: It's [very easy to use double-references as the argument](https://github.com/apache/arrow-datafusion/pull/4371#discussion_r1032385224), which the function will happily accept and give back the size of _the reference_, not the size of the value _behind_ the reference. In the worst case, if the value matches the programmer's expectation, this seems to work, while in fact, everything will go horribly wrong e.g. on a different platform.

The size of a `&T` is independent of what `T` is, and people might want to use `std::mem::size_of_val()` to actually get the size of _any_ reference (e.g. via `&&()`). I would rather suggest that this is always bad behavior, though ([instead](https://doc.rust-lang.org/reference/type-layout.html#pointers-and-references-layout), [and](https://doc.rust-lang.org/stable/std/primitive.usize.html#associatedconstant.BITS)). I, therefore, put this lint into `correctness`.

Since the problem is usually easily fixed by removing extra `&`, I went light on suggesting code.

---

changelog: New lint: [`size_of_ref`]
[#10098](https://github.com/rust-lang/rust-clippy/pull/10098)
<!-- changelog_checked -->
2022-12-24 23:33:13 +00:00
Lukas Lueg
d7b9e195c2 Add size_of_ref lint
Fixes #9995
2022-12-24 23:39:54 +01:00
bors
e2a687da72 Auto merge of #10111 - alex-semenyuk:changelog_fix, r=flip1995
Changelog fix

changelog: show link to  [`derive_partial_eq_without_eq`] at changelog file
2022-12-23 11:30:34 +00:00
alexey semenyuk
faebca37e9
Changelog fix 2022-12-23 14:24:23 +03:00
Niki4tap
9ff868c4ae test test test 2022-12-23 01:14:07 +03:00
Niki4tap
a935826071 Fix the actual bug 2022-12-23 00:57:28 +03:00
Niki4tap
0cd9b06125 Small code style adjustments 2022-12-23 00:56:50 +03:00
bors
4fe3727c39 Auto merge of #9701 - smoelius:improve-possible-borrower, r=Jarcho
Improve `possible_borrower`

This PR makes several improvements to `clippy_uitls::mir::possible_borrower`. These changes benefit both `needless_borrow` and `redundant clone`.

1. **Use the compiler's `MaybeStorageLive` analysis**

I could spot not functional differences between the one in the compiler and the one in Clippy's repository. So, I removed the latter in favor of the the former.

2. **Make `PossibleBorrower` a dataflow analysis instead of a visitor**

The main benefit of this change is that allows `possible_borrower` to take advantage of statements' relative locations, which is easier to do in an analysis than in a visitor.

This is easier to illustrate with an example, so consider this one:
```rust
    fn foo(cx: &LateContext<'_>, lint: &'static Lint) {
        cx.struct_span_lint(lint, rustc_span::Span::default(), "", |diag| diag.note(&String::new()));
        //                                                                          ^
    }
```
We would like to flag the `&` pointed to by the `^` for removal. `foo`'s MIR begins like this:
```rust
fn span_lint::foo::{closure#0}(_1: [closure@$DIR/needless_borrow.rs:396:68: 396:74], _2: &mut rustc_errors::diagnostic_builder::DiagnosticBuilder<'_, ()>) -> &mut rustc_errors::diagnostic_builder::DiagnosticBuilder<'_, ()> {
    debug diag => _2;                    // in scope 0 at $DIR/needless_borrow.rs:396:69: 396:73
    let mut _0: &mut rustc_errors::diagnostic_builder::DiagnosticBuilder<'_, ()>; // return place in scope 0 at $DIR/needless_borrow.rs:396:75: 396:75
    let mut _3: &mut rustc_errors::diagnostic_builder::DiagnosticBuilder<'_, ()>; // in scope 0 at $DIR/needless_borrow.rs:396:75: 396:100
    let mut _4: &mut rustc_errors::diagnostic_builder::DiagnosticBuilder<'_, ()>; // in scope 0 at $DIR/needless_borrow.rs:396:75: 396:100
    let mut _5: &std::string::String;    // in scope 0 at $DIR/needless_borrow.rs:396:85: 396:99
    let _6: std::string::String;         // in scope 0 at $DIR/needless_borrow.rs:396:86: 396:99

    bb0: {
        StorageLive(_3);                 // scope 0 at $DIR/needless_borrow.rs:396:75: 396:100
        StorageLive(_4);                 // scope 0 at $DIR/needless_borrow.rs:396:75: 396:100
        _4 = &mut (*_2);                 // scope 0 at $DIR/needless_borrow.rs:396:75: 396:100
        StorageLive(_5);                 // scope 0 at $DIR/needless_borrow.rs:396:85: 396:99
        StorageLive(_6);                 // scope 0 at $DIR/needless_borrow.rs:396:86: 396:99
        _6 = std::string::String::new() -> bb1; // scope 0 at $DIR/needless_borrow.rs:396:86: 396:99
                                         // mir::Constant
                                         // + span: $DIR/needless_borrow.rs:396:86: 396:97
                                         // + literal: Const { ty: fn() -> std::string::String {std::string::String::new}, val: Value(<ZST>) }
    }

    bb1: {
        _5 = &_6;                        // scope 0 at $DIR/needless_borrow.rs:396:85: 396:99
        _3 = rustc_errors::diagnostic_builder::DiagnosticBuilder::<'_, ()>::note::<&std::string::String>(move _4, move _5) -> [return: bb2, unwind: bb4]; // scope 0 at $DIR/needless_borrow.rs:396:75: 396:100
                                         // mir::Constant
                                         // + span: $DIR/needless_borrow.rs:396:80: 396:84
                                         // + literal: Const { ty: for<'a> fn(&'a mut rustc_errors::diagnostic_builder::DiagnosticBuilder<'_, ()>, &std::string::String) -> &'a mut rustc_errors::diagnostic_builder::DiagnosticBuilder<'_, ()> {rustc_errors::diagnostic_builder::DiagnosticBuilder::<'_, ()>::note::<&std::string::String>}, val: Value(<ZST>) }
    }
```
The call to `diag.note` appears in `bb1` on the line beginning with `_3 =`. The `String` is owned by `_6`. So, in the call to `diag.note`, we would like to know whether there are any references to `_6` besides `_5`.

The old, visitor approach did not consider the relative locations of statements. So all borrows were treated the same, *even if they occurred after the location of interest*.

For example, before the `_3 = ...` call, the possible borrowers of `_6` would be just `_5`. But after the call, the possible borrowers would include `_2`, `_3`, and `_4`.

So, in a sense, the call from which we are try to remove the needless borrow is trying to prevent us from removing the needless borrow(!).

With an analysis, things do not get so muddled. We can determine the set of possible borrowers at any specific location, e.g., using a `ResultsCursor`.

3. **Change `only_borrowers` to `at_most_borrowers`**

`possible_borrowers` exposed a function `only_borrowers` that determined whether the borrowers of some local were *exactly* some set `S`. But, from what I can tell, this was overkill. For the lints that currently use `possible_borrower` (`needless_borrow` and `redundant_clone`), all we really want to know is whether there are borrowers *other than* those in `S`. (Put another way, we only care about the subset relation in one direction.) The new function `at_most_borrowers` takes this more tailored approach.

4. **Compute relations "on the fly" rather than using `transitive_relation`**

The visitor would compute and store the transitive closure of the possible borrower relation for an entire MIR body.

But with an analysis, there is effectively a different possible borrower relation at each location in the body. Computing and storing a transitive closure at each location would not be practical.

So the new approach is to compute the transitive closure on the fly, as needed. But the new approach might actually be more efficient, as I now explain.

In all current uses of `at_most_borrowers` (previously `only_borrowers`), the size of the set of borrowers `S` is at most 2. So you need only check at most three borrowers to determine whether the subset relation holds. That is, once you have found a third borrower, you can stop, since you know the relation cannot hold.

Note that `transitive_relation` is still used by `clippy_uitls::mir::possible_origin` (a kind of "subroutine" of `possible_borrower`).

cc: `@Jarcho`

---

changelog: [`needless_borrow`], [`redundant_clone`]: Now track references better and detect more cases
[#9701](https://github.com/rust-lang/rust-clippy/pull/9701)
<!-- changelog_checked -->
2022-12-22 15:08:04 +00:00
bors
8a6e6fd623 Auto merge of #10056 - koka831:fix/9993, r=Jarcho
Avoid `match_wildcard_for_single_variants` on guarded wild matches

fix #9993

changelog: FP: [`match_wildcard_for_single_variants`]: No longer lints on wildcards with a guard
[#10056](https://github.com/rust-lang/rust-clippy/pull/10056)
<!-- changelog_checked -->

r? `@Jarcho`
2022-12-22 14:54:50 +00:00
bors
f0d331ab36 Auto merge of #10109 - Niki4tap:yeet_not_return, r=flip1995
Fix FP in needless_return when using yeet

Fixes #9947

changelog: Fix: [`needless_return`]: don't lint when using `do yeet`
#10109
2022-12-22 10:40:33 +00:00