Commit graph

5480 commits

Author SHA1 Message Date
Albert Larsan
5f8686ec3b Change src/test to tests in source files, fix tidy and tests 2023-01-11 09:32:13 +00:00
bors
15226f91bb Auto merge of #10166 - sulami:master, r=giraffate
unused_self: Don't trigger if the method body contains todo!()

If the author is using todo!(), presumably they intend to use self at some point later, so we don't have a good basis to recommend factoring out to an associated function.

Fixes #10117.

---

changelog: Enhancement: [`unused_self`]: No longer lints, if the method body contains a `todo!()` call
[#10166](https://github.com/rust-lang/rust-clippy/pull/10166)
<!-- changelog_checked -->
2023-01-11 00:30:19 +00:00
dswij
96e306843e tests: add case for multiple semis 2023-01-11 07:09:57 +08:00
Robert Bastian
8ca900b01c rename 2023-01-10 11:12:54 +01:00
Robert Bastian
53c12e085a hash xor peq 2023-01-09 21:29:42 +01:00
bors
41b2a3d9fe Auto merge of #10170 - c410-f3r:arith, r=dswij
[arithmetic_side_effects] Add more tests related to custom types

Add tests to ensure that custom types are triggered with any type of arithmetic operation as well as combinations with or without references.

---

changelog: none
<!-- changelog_checked -->
2023-01-09 14:54:12 +00:00
koka
1a7ef02dcb
Fix fp in unnecessary_safety_comment 2023-01-09 18:49:46 +09:00
Andre Bogus
d23dce54ec add a test against #100898 2023-01-08 20:25:42 +01:00
bors
cf1d3d0370 Auto merge of #10162 - tamaroning:fix10018, r=xFrednet
Fix FP of single-element-loop

closes #10018

---

changelog: [`single_element_loop`]: No longer lints, if the loop contains a `break` or `continue`
[#10162](https://github.com/rust-lang/rust-clippy/pull/10162)
<!-- changelog_checked -->
2023-01-07 11:53:45 +00:00
Caio
fb34fbf7e0 [arithmetic_side_effects] Add more tests related to custom types 2023-01-06 14:50:25 -03:00
Caio
4262aebeaa [arithmetic-side-effects] Consider negative numbers and add more tests 2023-01-06 12:25:51 -03:00
bors
179a22f624 Auto merge of #10153 - llogiq:box-default-trim-paths, r=Jarcho
trim paths in `box_default`

This might help with #10089, though I have not tested that yet. In any event, it keeps the suggestion short and to the point.

---
changelog: Trim paths in [`box_default`] suggestion
2023-01-06 09:21:27 +00:00
bors
3f48ed523f Auto merge of #10160 - llogiq:default-trim-paths, r=dswij
trim paths in `default_trait_access`/`clone_on_copy` suggestions

This should help making the suggestions more palatable. Similar to #10153.

---

changelog: trim paths in [`default_trait_access`]/[`clone_on_copy`] suggestions
2023-01-06 09:07:58 +00:00
bors
3816f9a6f9 Auto merge of #10137 - euclio:dbg-macro, r=giraffate
reword dbg_macro labels

---

This change rewords the `dbg_macro` lint labels to be clearer.

changelog: none
<!-- changelog_checked -->
2023-01-06 05:25:34 +00:00
Robin Schroer
e443604a24
unused_self: Don't trigger if the method body contains todo!()
If the author is using todo!(), presumably they intend to use self at
some point later, so we don't have a good basis to recommend factoring
out to an associated function.

Fixes #10117.

changelog: Don't trigger [`unused_self`] if the method body contains a `todo!()` call
2023-01-06 12:58:51 +09:00
bors
4f4c96155a Auto merge of #10142 - EricWu2003:drop_ref-FP, r=llogiq
[`drop_ref`]: don't lint idiomatic in match arm

fixes #10122

As established in issue #9482, it is idiomatic to use a single `drop()` expression in a match arm to achieve a side-effect of a function while discarding its output. This should also apply to cases where the function returns a reference.

The change to the lint's code was less than 1 line, because all the heavy lifting was done in PR #9491.

---

changelog: FP: [`drop_ref`]: No longer lints idiomatic expression in `match` arms
[#10142](https://github.com/rust-lang/rust-clippy/pull/10142)
<!-- changelog_checked -->
2023-01-05 23:36:49 +00:00
Raiki Tamura
79ed23ff81 fix 2023-01-05 18:30:13 +09:00
Kyle Huey
1c42dbba60 Expand derivable-impls to cover enums with a default unit variant. 2023-01-04 19:08:37 -08:00
bors
d5d8ef13d7 Auto merge of #10159 - khuey:iter_kv_map_ref_mut, r=llogiq
Make the iter_kv_map lint handle ref/mut annotations.

For the degenerate (`map(|(k, _)| k)`/`map(|(_, v)| v)`) cases a mut annotation is superfluous and a ref annotation won't compile, so no additional handling is required. For cases where the `map` call must be preserved ref/mut annotations should also be presereved so that the map body continues to work as expected.

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

changelog: [`iter_kv_map`]: handle ref/mut annotations
2023-01-04 23:13:39 +00:00
Andre Bogus
05ba519a3a trim paths in default_trait_access/clone_on_copy suggestions 2023-01-04 23:39:46 +01:00
Kyle Huey
d0c1605d51 Make the iter_kv_map lint handle ref/mut annotations.
For the degenerate (`map(|(k, _)| k)`/`map(|(_, v)| v)`) cases a mut annotation is superfluous and a ref annotation won't compile, so no additional handling is required. For cases where the `map` call must be preserved ref/mut annotations should also be presereved so that the map body continues to work as expected.
2023-01-04 13:32:34 -08:00
bors
a385d34fc2 Auto merge of #10107 - tylerjw:suggest_path, r=Alexendoo
Suggest using Path for comparing extensions

fixes #10042

changelog: Sugg: [`case_sensitive_file_extension_comparisons`]: Now displays a suggestion with `Path`
[#10107](https://github.com/rust-lang/rust-clippy/pull/10107)
<!-- changelog_checked -->
2023-01-04 19:27:11 +00:00
Tyler Weaver
ea6ff7ed04
Apply changes suggested in review 2023-01-04 07:06:07 -07:00
Andre Bogus
d3a50d2fda trim paths in box_default 2023-01-04 00:44:20 +01: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
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
Andy Russell
9aef1a264a
reword dbg_macro labels 2023-01-02 12:09:26 -05: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
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
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
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
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
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
Niki4tap
9ff868c4ae test test test 2022-12-23 01:14:07 +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
Niki4tap
b6882f6107 Fix FP in needless_return when using yeet 2022-12-22 12:47:39 +03:00
bors
065c6f78e7 Auto merge of #10091 - EricWu2003:manual-filter-FP, r=llogiq
fix manual_filter false positive

fixes #10088
fixes #9766

changelog: FP: [`manual_filter`]: Now ignores if expressions where the else branch has side effects or doesn't return `None`
[#10091](https://github.com/rust-lang/rust-clippy/pull/10091)
<!-- changelog_checked -->
2022-12-21 19:39:32 +00:00
bors
4a09068f87 Auto merge of #10063 - chansuke:issue-9702, r=Alexendoo
add [`permissions_set_readonly_false`] #9702

Add slight modification on [this PR](https://github.com/rust-lang/rust-clippy/pull/9744).

---

changelog: New lint [`permissions_set_readonly_false`]
[#10063](https://github.com/rust-lang/rust-clippy/pull/10063)
<!-- changelog_checked -->
2022-12-20 16:03:11 +00:00
chansuke
b21cc36ee9 hotfix: add help dialog for PermissionExt 2022-12-20 23:43:34 +09:00
Samuel Moelius
26df55112f Fix adjacent code 2022-12-20 05:12:13 -05:00
Samuel Moelius
ed519ad746 Improve possible_borrower 2022-12-20 05:12:13 -05:00
Samuel Moelius
c6477eb711 Add tests 2022-12-20 05:12:13 -05:00
bors
1e68973582 Auto merge of #10067 - chansuke:issue-7943, r=giraffate
Add 2018/2021 edition tests for wildcard_imports

Fixes #7943

---

changelog: none
<!-- changelog_checked -->
2022-12-20 00:28:21 +00:00
Michael Goulet
24444945ec Make Clippy test no longer unsound 2022-12-19 18:16:22 +00:00
dboso
30e6e85508 add [permissions_set_readonly_false] #9702 2022-12-20 00:37:51 +09:00
Niki4tap
d0ac6ba0b1 Fix overflow ICE in large_stack/const_arrays 2022-12-19 18:27:42 +03:00
bors
b3145fea6a Auto merge of #10099 - Niki4tap:null_fn_lints, r=llogiq
Null fn lints

Adds lints to check for code, that assumes nullable `fn()`.

### Lint examples:

`transmute_null_to_fn`:
```rust
error: transmuting a known null pointer into a function pointer
  --> $DIR/transmute_null_to_fn.rs:9:23
   |
LL |         let _: fn() = std::mem::transmute(std::ptr::null::<()>());
   |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this transmute results in undefined behavior
   |
   = help: try wrapping your function pointer type in `Option<T>` instead, and using `None` as a null pointer value
```

`fn_null_check`:
```rust
error: function pointer assumed to be nullable, even though it isn't
  --> $DIR/fn_null_check.rs:13:8
   |
LL |     if (fn_ptr as *mut ()).is_null() {}
   |        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: try wrapping your function pointer type in `Option<T>` instead, and using `is_none` to check for null pointer value
```

Closes #1644

---

changelog: Improvement: [`transmuting_null`]: Now detects `const` pointers to all types
[#10099](https://github.com/rust-lang/rust-clippy/pull/10099)
changelog: New lint: [`transmute_null_to_fn`]
[#10099](https://github.com/rust-lang/rust-clippy/pull/10099)
changelog: New lint: [`fn_null_check`]
[#10099](https://github.com/rust-lang/rust-clippy/pull/10099)
<!-- changelog_checked (This is just a flag for me, please don't add it manually) -->
2022-12-19 12:44:23 +00:00
bors
910a97d7ce Auto merge of #10020 - samueltardieu:more-into-iter-removal, r=xFrednet
Identify more cases of useless `into_iter()` calls

changelog: Sugg: [`useless_conversion`]: Now suggests removing calls to `into_iter()` on an expression implementing `Iterator`
[#10020](https://github.com/rust-lang/rust-clippy/pull/10020)
<!-- changelog_checked -->
2022-12-18 16:01:29 +00:00
koka
ebb0759bb3
Add a test for regular wildcard
fix
2022-12-18 21:07:18 +09:00
Niki4tap
42106e0495 Add lint fn_null_check 2022-12-18 03:02:45 +03:00
Niki4tap
6afe5471cf Add lint transmute_null_to_fn 2022-12-18 03:02:37 +03:00
Samuel Tardieu
af39a8a4a8 Identify more cases of useless into_iter() calls
If the type of the result of a call to `IntoIterator::into_iter()`
and the type of the receiver are the same, then the receiver
implements `Iterator` and `into_iter()` is the identity function.

The call to `into_iter()` may be removed in all but two cases:

- If the receiver implements `Copy`, `into_iter()` will produce
  a copy of the receiver and cannot be removed. For example,
  `x.into_iter().next()` will not advance `x` while `x.next()` will.
- If the receiver is an immutable local variable and the call to
  `into_iter()` appears in a larger expression, removing the call to
  `into_iter()` might cause mutability issues. For example, if `x`
  is an immutable local variable, `x.into_iter().next()` will
  compile while `x.next()` will not as `next()` receives
  `&mut self`.
2022-12-17 16:20:43 +01:00
Philipp Krones
1c422524c7 Merge commit '4bdfb0741dbcecd5279a2635c3280726db0604b5' into clippyup 2022-12-17 14:12:54 +01:00
bors
4bdfb0741d Auto merge of #10097 - flip1995:rustup, r=flip1995
Rustup

r? `@ghost`

I'm on the train and my internet is too bad to download the necessary toolchain, so I have to use CI to find sync fallout.

changelog: none
<!-- changelog_checked -->
2022-12-17 13:08:47 +00:00
Philipp Krones
d6488ae144
Merge remote-tracking branch 'upstream/master' into rustup 2022-12-17 13:56:32 +01:00
bors
391b2a6fac Auto merge of #10096 - feniljain:fix-seek-rewind, r=xFrednet
fix: not suggest seek_to_start_instead_of_rewind when expr is used

changelog: [`seek_to_start_instead_of_rewind`]: No longer lints, if the return of `seek` is used.
[#10096](https://github.com/rust-lang/rust-clippy/pull/10096)
<!-- changelog_checked -->

Fixes #10065
2022-12-17 12:35:26 +00:00
feniljain
c39849a34d fix: not suggest seek_to_start_instead_of_rewind when expr is used 2022-12-17 17:31:34 +05:30
chansuke
033f1ec797 Add 2018/2021 edition tests for wildcard_imports 2022-12-17 20:26:41 +09:00
Eric Wu
97c12e0460 fix logic in IncrementVisitor
There used to be a logical bug where IncrementVisitor would
completely stop checking an expression/block after seeing a continue
statement. This led to issue #10058 where a variable incremented
(or otherwise modified) after any continue statement would still be
considered incremented only once.

The solution is to continue scanning the expression after seeing a
`continue` statement, but increment self.depth so that the Visitor
thinks that the rest of the loop is within a conditional.
2022-12-16 10:54:12 -05:00
Eric Wu
3c14075b46 manual_filter: add a related test
The related issue is #9766 where the `manual_filter`
lint would remove side effects
2022-12-16 09:29:32 -05:00
Eric Wu
5b3a6669f7 fix manual_filter false positive
do explicit checks for the other branch being None
2022-12-15 23:53:28 -05:00
Gary Guo
7574c98371 Fix new_return_no_self with recursive bounds 2022-12-15 18:56:13 +00:00
bors
be15e60d00 Auto merge of #10053 - naosense:fix_9933, r=xFrednet
improve `manual_is_ascii_check ` check

Sorry, not familiar the api, i can only check the method name of expression `<expr-1>.contains(<expr-2>)` after read clippy book and hints from #9933 . i dont know how to check
1.  if <expr-1> is a specific range
2. <expr-2> is a character

r? `@xFrednet` could you please provide some more hints? 😝️

---

changelog: Enhancement: [`manual_is_ascii_check`]: Now detects ranges with `.contains()` calls
[#10053](https://github.com/rust-lang/rust-clippy/pull/10053)
<!-- changelog_checked -->
2022-12-14 13:48:53 +00:00
naosense
1f862c2ad3 remove assert macro 2022-12-13 21:43:16 +08:00
naosense
55fdd1e78c replace reference with value 2022-12-13 16:52:55 +08:00
naosense
de92da2974 add more test, limits check 2022-12-13 16:52:55 +08:00
naosense
25c9718c04 check ranges with .contains calls 2022-12-13 16:52:55 +08:00
alex-semenyuk
3b6bbf7d16 Fix match_single_binding suggestion introduced an extra semicolon 2022-12-10 20:35:49 +03:00
koka
055f349670
Avoid match_wildcard_for_single_variants on guarded wild matches
fix #9993
changlog: [`match_wildcard_for_single_variants`] avoid suggestion on wildcard with guard
2022-12-10 21:05:08 +09:00
Taiki Endo
e5010c996e uninlined_format_args: Ignore assert! and debug_assert! before 2021 edition 2022-12-10 18:35:24 +09:00
Hannah Town
4c80f210c3 Add lint almost_complete_range
This replaces and expands `almost_complete_letter_range`.
2022-12-09 13:29:50 -05:00
bors
3492856c07 Auto merge of #10047 - Alexendoo:collapsible-str-replace-msrv, r=xFrednet
Add 1.58 MSRV for `collapsible_str_replace`

The `Pattern` impl for `[char; N]` was added in 1.58

changelog: Enhancement: [`collapsible_str_replace`]: Now takes MSRV into consideration. The minimal version is 1.58
[#10047](https://github.com/rust-lang/rust-clippy/pull/10047)
2022-12-09 12:05:20 +00:00
bors
5a3a722c05 Auto merge of #10004 - Jarcho:issue_9904, r=llogiq
Don't suggest keeping borrows in `identity_op`

fixes #9904
changelog: `identity_op`: Don't suggest keeping borrows
2022-12-09 11:53:14 +00:00
bors
d4cd91c288 Auto merge of #9826 - Veykril:semi-blocks, r=Alexendoo
Add semicolon-outside/inside-block lints

changelog: Add `semicolon_outside_block` and `semicolon_inside_block` lints

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

An earlier attempt at this can be found here https://github.com/rust-lang/rust-clippy/pull/7564. This PR still implements two separate lints but I am open to merging them into a single one that's configurable.
2022-12-09 11:41:24 +00:00
bors
39f0719a25 Auto merge of #9840 - c410-f3r:arith-2, r=Alexendoo
[`arithmetic-side-effects`]: Consider user-provided pairs

Depends on https://github.com/rust-lang/rust-clippy/pull/9592.

Because of https://github.com/rust-lang/rust-clippy/pull/9559#discussion_r985293523, r? `@Alexendoo`

```
changelog: [`arithmetic-side-effects`]: Consider user-provided pairs
```
2022-12-09 11:27:15 +00:00
Caio
1f92f97e5a [arithmetic-side-effects]: Consider user-provided pairs 2022-12-08 17:41:49 -03:00
Alex Macleod
591c18d2f0 Add 1.58 MSRV for collapsible_str_replace 2022-12-07 17:45:12 +00:00
bors
4129054120 Auto merge of #10023 - Jarcho:issue_10017, r=xFrednet
Fix `zero_ptr` suggestion for `no_std` crates

fixes #10017

---

changelog: Sugg: [`zero_ptr`]: Now suggests `core::` paths for `no_std` crates
[#10023](https://github.com/rust-lang/rust-clippy/pull/10023)
2022-12-06 18:57:05 +00:00
bors
5d70746251 Auto merge of #9920 - naosense:suppress_lint_in_const, r=xFrednet
add `suppress_restriction_lint_in_const` config

According to #9808 , add a new lint `suppress_lint_in_const` to report even in const context. BTW, i am not good at naming either, if anyone have a better idea, i am happy to change it.

This PR is still in progress, so i keep it draft.

- \[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: Enhancement: [`indexing_slicing`]: add new config `suppress-restriction-lint-in-const` to enable restriction lints, even if the suggestion might not be applicable

r? `@xFrendet`
2022-12-06 18:43:28 +00:00
Lukas Wirth
20ec2ceab8 Add test case for blocks with semicolon inside and outside a block 2022-12-05 11:02:10 +01:00
bors
cb8df45333 Auto merge of #10027 - smoelius:fix-10021, r=dswij
Fix 10021

This PR proposes a fix for #10021.

The problem is similar to the one that `@mikerite` described in #9505. The compiler is generating an empty substitution for a call, even though the type of `Self` seems to be needed for a predicate. In `@mikerite's` case, the call was to [`IntoFuture::into_future`](https://doc.rust-lang.org/std/future/trait.IntoFuture.html#tymethod.into_future). In this case, the call is to [`Try::branch`](https://doc.rust-lang.org/std/ops/trait.Try.html#tymethod.branch).

The proposed fix is to verify that the parameter whose type is changing has an index within the substitution. The strikes me as a reasonable approach, since if the check were to fail, the following code would be a no-op:

4c123a06ba/clippy_lints/src/methods/unnecessary_to_owned.rs (L420-L428)

Like `@mikerite's` original solution, this solution turns ICEs into false negatives.

changelog: fix `unnecessary_to_owned` false positive involving `Try::branch`
2022-12-04 01:58:43 +00:00
naosense
eec5039f09 fix test 2022-12-03 16:06:57 +08:00
Samuel Moelius
cb420080ac Add test for #10021 2022-12-02 20:48:18 -05:00
Jason Newcomb
6ba2cda79a Fix zero_ptr suggestion for no_std crates 2022-12-02 15:36:17 -05:00
bors
38fce1235a Auto merge of #10022 - Jarcho:issue_10019, r=giraffate
Don't lint `implicit_clone` when the type doesn't implement clone

fixes #10019
changelog: `implicit_clone`: Don't lint when the type doesn't implement clone
2022-12-02 07:17:13 +00:00
bors
56d5657880 Auto merge of #9962 - mdgaziur:master, r=dswij
Fix #9958

This PR fixes #9958. In order to fix the issue, the lint will now peel reference operators and enclose the expression with parentheses when necessary.

changelog: [`comparison_to_empty`]: Peel deref operators in suggestions when necessary
2022-12-02 05:49:26 +00:00
bors
b43c9f7638 Auto merge of #9982 - Jarcho:issue_9935, r=flip1995
Don't lint `from_over_into` for opaque types

fixes #9935

This is stalled until the next sync. The impl in question can't be written on the pinned nightly.

changelog: Don't lint `from_over_into` for opaque types
2022-12-02 04:31:55 +00:00
bors
a1d22808af Auto merge of #104963 - petrochenkov:noaddids2, r=cjgillot
rustc_ast_lowering: Stop lowering imports into multiple items

Lower them into a single item with multiple resolutions instead.
This also allows to remove additional `NodId`s and `DefId`s related to those additional items.
2022-12-02 04:24:57 +00:00
Jason Newcomb
ab8c6beb85 Don't lint implicit_clone when the type doesn't implement clone 2022-12-01 23:05:53 -05:00
bors
fec00573a5 Auto merge of #10013 - Jarcho:issue_9886, r=Manishearth
Don't lint `manual_assert` in `else if`

fixes #9886
changelog: `manual_assert`: Don't lint in `else if`
2022-12-01 22:49:40 +00:00
Jason Newcomb
47fb67fa08 Don't lint manual_assert in else if 2022-12-01 17:37:18 -05:00
bors
e16a8b93ba Auto merge of #10008 - Jarcho:issue_9882, r=Manishearth
Treat custom enum discriminant values as constants

fixes #9882
changelog: All lints: Don't lint in enum discriminant values when the suggestion won't work in a const context
2022-12-01 22:37:15 +00:00
bors
be0eb20fff Auto merge of #10006 - Jarcho:issue_9890, r=Manishearth
Don't suggest removing `mut` from references in `redundant_static_lifetimes`

fixes #9890
changelog: `redundant_static_lifetimes`: Don't suggest removing `mut` from references
2022-12-01 22:25:38 +00:00
bors
53e1b45137 Auto merge of #9966 - alex-semenyuk:manual_let_else_paren, r=xFrednet
Fix manual_let_else produces a wrong suggestion with or-patterns

Fix #9938
changelog: Sugg: [`manual_let_else`]: Suggestions for or-patterns now include required brackets.
[#9966](https://github.com/rust-lang/rust-clippy/pull/9966)
2022-12-01 22:11:01 +00:00
Jason Newcomb
a21b5b25f6 Don't lint string_lit_as_bytes in match scrutinees 2022-12-01 14:52:41 -05:00
alex-semenyuk
05477ff8df Fix manual_let_else produces a wrong suggestion with or-patterns 2022-12-01 22:05:06 +03:00
Philipp Krones
d05e2865a0 Merge commit 'd822110d3b5625b9dc80ccc442e06fc3cc851d76' into clippyup 2022-12-01 18:29:38 +01:00
Jason Newcomb
6ecdff07e5 Don't lint from_over_into for opaque types 2022-12-01 11:51:31 -05:00
Vadim Petrochenkov
b0d490e308 rustc_ast_lowering: Stop lowering imports into multiple items
Lower them into a single item with multiple resolutions instead.
This also allows to remove additional `NodId`s and `DefId`s related to those additional items.
2022-12-01 18:51:20 +03:00
Philipp Krones
11434f270f
Merge remote-tracking branch 'upstream/master' into rustup 2022-12-01 12:55:15 +01:00
bors
641ced4eb9 Auto merge of #10007 - Jarcho:issue_10005, r=giraffate
Fix ICE in `result_large_err` with uninhabited enums

fixes #10005
changelog: `result_large_err`: Fix ICE with uninhabited enums
2022-12-01 07:20:06 +00:00
Jason Newcomb
a1b15f13f7 Treat custom enum discriminant values as constants 2022-11-30 22:34:42 -05:00
Jason Newcomb
7ae5c81e9f Fix ICE in result large_err with uninhabited enums 2022-11-30 21:44:18 -05:00
Jason Newcomb
55096eab0f Don't suggest removing mut from references in redundant_static_lifetimes 2022-11-30 21:29:48 -05:00
Jason Newcomb
03ba0ea400 Don't suggest keeping borrows in identity_op 2022-11-30 16:25:57 -05:00
bors
ee12b12be5 Auto merge of #9943 - dswij:pr-9940, r=Jarcho
manual_let_else: keep macro call on suggestion blocks

Closes #9940

changelog: [`manual_let_else`]: Do not expand macro calls on suggestions
2022-11-30 21:23:10 +00:00
bors
1cdb06d406 Auto merge of #10001 - Jarcho:issue_9866, r=llogiq
Fix ICE in `unused_rounding`

fixes #9866
changelog: `unused_rounding`: Fix ICE when using the `_` separator
2022-11-30 19:54:25 +00:00
bors
846c9b8170 Auto merge of #9996 - Jarcho:issue_9906, r=Alexendoo
Fix `unnecessary_cast` suggestion when taking a reference

fixes #9906
changelog: `unnecessary_cast`: Fix suggestion when taking a reference
2022-11-30 19:40:22 +00:00
bors
d7d098a7e6 Auto merge of #9997 - Jarcho:issue_9901, r=llogiq
Don't lint `explicit_auto_deref` when the initial type is neither a reference, nor a receiver

fixes #9901
fixes #9777
changelog: `explicit_auto_deref`: Don't lint when the initial value is neither a reference, nor a receiver
2022-11-30 19:29:40 +00:00
Jason Newcomb
c1b8bc66e9 Fix ICE in unused_rounding 2022-11-30 12:46:06 -05:00
bors
87963f03ba Auto merge of #9987 - Jarcho:issue_9957, r=flip1995
Don't cross contexts while building the suggestion for `redundant_closure_call`

fixes #9957

changelog: `redundant_closure_call`: Don't cross macro contexts while building the suggestion
2022-11-30 16:31:56 +00:00
Jason Newcomb
2d32b40359 Don't lint explicit_auto_deref when the initial type is neither a reference, nor a receiver 2022-11-30 11:23:01 -05:00
Jason Newcomb
73f4546d24 Fix unnecessary_cast suggestion when taking a reference 2022-11-30 10:55:48 -05:00
Jason Newcomb
e0eba9cafc Don't cross contexts while building the suggestion for redundant_closure_call 2022-11-30 10:53:27 -05:00
mdgaziur
7a0f0c0e8b
Fix #9958 2022-11-30 19:42:50 +06:00
bors
78589ffad2 Auto merge of #9989 - xFrednet:9986-move-safety-thingy, r=flip1995
Move `unnecessary_unsafety_doc` to `pedantic`

This lint was added in #9822. I like the idea, but also agree with #9986 as well. I think it should at least not be warn-by-default. This is one of these cases, where I'd like a group between pedantic and restriction. But I believe that users using `#![warn(clippy::pedantic)]` will know how to enable the lint if they disagree with it.

---

Since the lint is new:

changelog: none

r? `@flip1995` since I'd suggest back porting this, the original PR was merged 16 days ago.

Closes: #9986 (While it doesn't address everything, I believe that this is the best compromise)
2022-11-30 12:44:45 +00:00
xFrednet
cc43c3d25d
Move unnecessary_unsafety_doc to pedantic 2022-11-30 12:59:50 +01:00
bors
4cda21dc42 Auto merge of #9981 - Jarcho:issue_9954, r=flip1995
Don't lint `unnecessary_operation` in mixed macro contexts

fixes #9954

changelog: `unnecessary_operation`: Don't lint in mixed macro contexts.
2022-11-29 09:49:46 +00:00
naosense
67a94135cb change note style 2022-11-29 15:00:51 +08:00
naosense
4528aec7e9 update config and suggest 2022-11-29 15:00:51 +08:00
Jason Newcomb
f44b7aa81e Don't lint unnecessary_cast in mixed macro context 2022-11-28 23:58:02 -05:00
Jason Newcomb
0893322e54 Don't lint unnecessary_operation in mixed macro contexts 2022-11-28 23:56:02 -05:00
bors
12074808c7 Auto merge of #9865 - nyurik:allow-mixed, r=xFrednet
Add allow-mixed-uninlined-format-args config

Implement `allow-mixed-uninlined-format-args` config param to change the behavior of the `uninlined_format_args` lint. Now it is a part of `style` per [Zulip chat](https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/.60uninlined_format_args.60.20category), and won't propose inlining in case of a mixed usage, e.g. `print!("{} {}", var, 1+2)`. If the user sets `allow-mixed-uninlined-format-args` config param to `false`, the lint would behave like it did before -- proposing to inline args even in the mixed case.

---

changelog: [`uninlined_format_args`]: Added a new config `allow-mixed-uninlined-format-args` to allow the lint, if only some arguments can be inlined
[#9865](https://github.com/rust-lang/rust-clippy/pull/9865)
changelog: Moved [`uninlined_format_args`] to `style` (Now warn-by-default)
[#9865](https://github.com/rust-lang/rust-clippy/pull/9865)
2022-11-28 17:22:36 +00:00
Esteban Küber
fc108d4b61 fix clippy tests 2022-11-28 00:41:31 -08:00
bors
c8eba8e4a1 Auto merge of #9967 - koka831:fix/9416, r=llogiq
Remove blank lines when needless_return returns no value

fix https://github.com/rust-lang/rust-clippy/issues/9416

changelog: [`needless_return`] improve result format

r? `@llogiq`
2022-11-27 19:03:06 +00:00
Yuri Astrakhan
ab576afc18 addressed review feedback 2022-11-27 10:34:13 -05:00
Yuri Astrakhan
7a2d92e1f2 Add allow-mixed-uninlined-format-args config
Implement `allow-mixed-uninlined-format-args` config param to change the behavior of the `uninlined_format_args` lint. Now it is a part of `style`, and won't propose inlining in case of a mixed usage, e.g. `print!("{} {}", var, 1+2)`. If the user sets allow-mixed-uninlined-format-args config param to `false`, then it would behave like before, proposing to inline args even in the mixed case.
2022-11-27 10:12:51 -05:00
koka
8c50dfb546
Remove blank lines when needless_return returns no value
fix https://github.com/rust-lang/rust-clippy/issues/9416
2022-11-27 22:01:21 +09:00
Alex Macleod
461e219d1d Allow using clippy::msrv as an outer attribute 2022-11-27 12:43:17 +00:00
Lukas Wirth
dd1163f461 Fix macro statement handling 2022-11-25 17:10:10 +01:00
Lukas Wirth
23744cd4ba Use multi-span suggestions 2022-11-25 17:10:10 +01:00
Lukas Wirth
93b5c893e6 Add semicolon-outside/inside-block lints 2022-11-25 17:10:10 +01:00
kraktus
5610d22c8d Re-enable uninlined_format_args on multiline format!
But do not display the code suggestion which can be sometimes completely broken (fortunately when applied it's valid)
2022-11-25 16:36:22 +01:00
dswij
a4b53c9c14 manual_let_else: Add test with expanded macros 2022-11-25 18:17:34 +08:00
Lukas Wirth
f96dd38318 Address reviews 2022-11-25 10:09:35 +01:00
Lukas Wirth
4fa5757530 Lint unnecessary safety comments on statements and block tail expressions 2022-11-25 10:09:34 +01:00
Lukas Wirth
b8c3f64cee Add some more test cases for undocumented_unsafe_blocks 2022-11-25 10:09:34 +01:00
Lukas Wirth
a116b9bdba Lint unnecessary safety comments on items 2022-11-25 10:09:34 +01:00
Arpad Borsos
1ebdcca8b9 Avoid GenFuture shim when compiling async constructs
Previously, async constructs would be lowered to "normal" generators,
with an additional `from_generator` / `GenFuture` shim in between to
convert from `Generator` to `Future`.

The compiler will now special-case these generators internally so that
async constructs will *directly* implement `Future` without the need
to go through the `from_generator` / `GenFuture` shim.

The primary motivation for this change was hiding this implementation
detail in stack traces and debuginfo, but it can in theory also help
the optimizer as there is less abstractions to see through.
2022-11-24 10:04:27 +01:00
bors
69c5128cda Auto merge of #9924 - Alexendoo:msrv-stack, r=Jarcho
Add `clippy_utils::msrv::Msrv` to keep track of the current MSRV

changelog: Fix the scoping of the `#![clippy::msrv]` attribute

Fixes #6920

r? `@Jarcho`
2022-11-22 20:09:58 +00:00
bors
5595d7f5d5 Auto merge of #9750 - kraktus:lazy_eval, r=xFrednet
Fix [`unnecessary_lazy_eval`] when type has significant drop

fix for https://github.com/rust-lang/rust-clippy/issues/9427#issuecomment-1295742590

However current implementation gives too many false positive, rending the lint almost useless.

I don't know what's the best way to check if a type has a "significant" drop (in the common meaning, not the internal rustc one, for example Option<(u8, u8)> should not be considered significant)

changelog: Fix [`unnecessary_lazy_eval`] when type has significant drop
2022-11-22 17:21:23 +00:00
bors
94ce4465e5 Auto merge of #9796 - smoelius:issue-9771, r=flip1995
Fix #9771 (`unnecessary_to_owned` false positive)

Fixes #9771

In that issue's example(s), the lint tried to add a `&` to a value, which implicitly changed the type of a field to a reference. The fix is to add the reference to `receiver_ty` (the type of the receiver of the `to_owned`-like method), before passing `receiver_ty` to `can_change_type`. `can_change_type` properly rejects the modified `receiver_ty`.

cc: `@mikerite` just because I think he was the author of `can_change_type`.

changelog: fix `unnecessary_to_owned` false positive which implicitly tried to change the type of a field to a reference
2022-11-22 12:50:08 +00:00
bors
f4083c5ae7 Auto merge of #9745 - matttpt:fix-redundant-closure-for-method-calls-suggestion, r=flip1995
Fix `redundant_closure_for_method_calls` suggestion

Fixes #7746. The issue turns out to be more general than raw pointers. The `redundant_closure_for_method_calls` lint produces incorrect suggestions when the method is associated with a type that must be enclosed in angle brackets or must be written with generic arguments substituted. For example:

```rust
fn main() {
    // Clippy's suggestion: [T; N]::as_slice
    // Correct suggestion:  <[u8; 3]>::as_slice
    let array_opt: Option<&[u8; 3]> = Some(&[4, 8, 7]);
    array_opt.map(|a| a.as_slice());

    // Clippy's suggestion: [T]::len
    // Correct suggestion:  <[u8]>::len
    let slice_opt: Option<&[u8]> = Some(b"slice");
    slice_opt.map(|s| s.len());

    // Clippy's suggestion: *const T::is_null
    // Correct suggestion:  <*const usize>::is_null
    let ptr_opt: Option<*const usize> = Some(&487);
    ptr_opt.map(|p| p.is_null());

    // Clippy's suggestion: dyn TestTrait::method_on_dyn
    // Correct suggestion:  <dyn TestTrait>::method_on_dyn
    let test_struct = TestStruct {};
    let dyn_opt: Option<&dyn TestTrait> = Some(&test_struct);
    dyn_opt.map(|d| d.method_on_dyn());
}

// For the trait object example:
trait TestTrait {}
struct TestStruct {}
impl TestTrait for TestStruct {}

impl dyn TestTrait + '_ {
    fn method_on_dyn(&self) -> bool {
        false
    }
}
```

The issue also affects references and tuples, though I had to patch the standard library with non-trait methods for those types to test that. Just in case, I also included handling for `!`, since it appeared to be possible to call methods on it with angle brackets. I just couldn't verify the resulting suggestion, since dead-code analysis eliminates the code first.

This is my first exposure to Rust compiler internals, so please let me know if I'm taking the wrong approach here!

changelog: [`redundant_closure_for_method_calls`]: add angle brackets and substitute generic arguments in suggestion when needed
2022-11-22 09:20:50 +00:00
Philipp Krones
46c5a5d234 Merge commit 'f4850f7292efa33759b4f7f9b7621268979e9914' into clippyup 2022-11-21 20:51:52 +01:00
bors
73efce9ee6 Auto merge of #9770 - sgued:missnamed-getters, r=llogiq
Add new lint  [`misnamed-getters`]

```
changelog: Add new lint  [`misnamed-getters`]
```

Closes #9769

The current lint matches all methods with a body of just one expression under the form `(&mut?)? <expr>.field` where field doesn't match the name of the method but there is a field of the same type in `<expr>` that matches the name. This allows matching nested structs, for example for newtype wrappers. This may cast the net a bit too wide and cause false positives. I'll run [clippy_lint_tester](https://github.com/mikerite/clippy_lint_tester) on the top crates to see how frequently false positives happen.

There also may be room for improvement by checking that the replacement field would work taking into account implementations of `Deref` and `DerefMut` even if the types don't exactly match but I don't know yet how this could be done.
2022-11-21 19:51:42 +00:00
Philipp Krones
fd5b85c957
Merge remote-tracking branch 'upstream/master' into rustup 2022-11-21 20:01:17 +01:00
Alex Macleod
637139d2ff Add clippy_utils::msrv::Msrv to keep track of the current MSRV 2022-11-21 18:16:40 +00:00
kraktus
ed183ee9ac Fix [unnecessary_lazy_eval] when type has significant drop 2022-11-21 12:45:35 +01:00
bors
e0c1959616 Auto merge of #9592 - c410-f3r:arith, r=Jarcho
[arithmetic-side-effects] Detect overflowing associated constants of integers

Triggers the negation of maximum unsigned integers using associated constants. Rustc already handles `-128i8` but doesn't handle `-i8::MAX`.

At the same time, allows stuff like `-1234`.

changelog: FP: [arithmetic-side-effects] Detect overflowing associated constants of integers
2022-11-20 22:51:25 +00:00
bors
a85c8f33ff Auto merge of #9870 - koka831:unformat-unused-rounding, r=Jarcho
Keep original literal notation in suggestion

While I did some investigation of https://github.com/rust-lang/rust-clippy/issues/9866 (I couldn't reproduce it though) I found that `unused_rounding` formats as follows:

```rust
3.0_f64.round() // => 3.0f64
```

This PR makes them preserve as the original notation.

```rust
3.0_f64.round() // => 3.0_f64
```

changelog: Suggestion Enhancement: [`unused_rounding`]: The suggestion now preserves the original float literal notation
2022-11-20 22:09:25 +00:00
Sosthène Guédon
1f2f50c34e Fix many false negatives caused by autoderef 2022-11-20 17:03:53 +01:00
Sosthène Guédon
0411edfbbd Improve diagnostic for cases where autoderef is used 2022-11-20 15:49:09 +01:00
Sosthène Guédon
77374a9527 Add failing test 2022-11-20 13:45:12 +01:00
Sosthène Guédon
3f1a186bd1 misnamed_getters: Trigger on unsafe with _unchecked 2022-11-20 13:45:12 +01:00
Sosthène Guédon
a867c17ab3 Improve code 2022-11-20 13:45:12 +01:00
Sosthène Guédon
3428da6e00 Fix typo missnamed -> misnamed 2022-11-20 13:45:12 +01:00
Sosthène Guédon
ddc49966dc Fix suggestion to point to the whole method 2022-11-20 13:45:12 +01:00
Sosthène Guédon
9891af348c missnamed_getters: Match owned methods 2022-11-20 13:45:12 +01:00
Sosthène Guédon
31b83d0895 Add missnamed_getters lint 2022-11-20 13:45:11 +01:00
Alex Macleod
4d8af99365 Fix #[allow] for module_name_repetitions & single_component_path_imports 2022-11-20 12:39:19 +00:00
Caio
98b343c5e6 [arithmetic-side-effects] Detect overflowing associated constants of integers 2022-11-19 08:22:27 -03:00
bors
e144c7d1ae Auto merge of #9871 - koka831:fix/9864, r=xFrednet
Allow manual swap in const fn

Fix https://github.com/rust-lang/rust-clippy/issues/9864

changelog: Fix [`manual_swap`]: No longer lints in constant code
2022-11-18 16:04:18 +00:00
bors
d019fd9780 Auto merge of #9855 - Alexendoo:needless-borrowed-ref-extra, r=xFrednet
Extend `needless_borrowed_reference` to structs and tuples, ignore _

changelog: [`needless_borrowed_reference`]: Lint struct and tuple patterns, and patterns containing `_`

Now lints patterns like

```rust
&(ref a, ref b)
&Tuple(ref a, ref b)
&Struct { ref a, ref b }

&(ref a, _)
```
2022-11-18 14:26:50 +00:00
koka
928a158716
Allow manual swap in const fn 2022-11-18 21:51:43 +09:00
koka
921f4d317e
Keep original literal notation in suggestion 2022-11-18 21:23:16 +09:00
bors
01f40ce3bc Auto merge of #9863 - smoelius:expect-unwrap-used-typo, r=flip1995
Fix typo in `expect_used` and `unwrap_used` warning messages

"\`an Option\`" -> "an \`Option\`" and "\`a Result\`" -> "a \`Result\`".

changelog: fix typo in `expect_used` and `unwrap_used` warning messages
2022-11-18 11:49:47 +00:00
bors
dfe37f13cf Auto merge of #9850 - pheki:fix-7499-missing-ref, r=dswij
Preserve `ref` on `infallible_destructuring_match` suggestion

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

changelog: [`infallible_destructuring_match`]: Preserve `ref` on suggestion
2022-11-18 09:43:51 +00:00
bors
1c9c34de17 Auto merge of #9858 - DesmondWillowbrook:never_loop, r=dswij
`never_loop`: don't emit AlwaysBreaks if it targets a block

ref: https://github.com/rust-lang/rust-clippy/pull/9837#issuecomment-1312788194

The previous fix (#9837) was too simple and ignored all break commands inside a labelled block, regardless of whether their destination was a labelled block or a loop. This fix tracks all the labelled blocks in scope to ensure that only breaks targeting loops are considered.

changelog: [`never_loop`]: prevent false negatives from `breaks` nested in labelled blocks
2022-11-18 09:31:20 +00:00
Samuel Moelius
00ae5e15a8 Fix typo in expect_used and unwrap_used warning messages 2022-11-17 15:02:48 +00:00
Ralf Jung
2bf87f3830 cleanup and dedupe CTFE and Miri error reporting 2022-11-16 10:13:29 +01:00
Kartavya Vashishtha
036a0108ac
update tests 2022-11-16 11:39:09 +05:30
Kartavya Vashishtha
9f3b6e9acd
don't emit AlwaysBreaks if it targets a block
Introduced an ignored_ids parameter.
Takes O(n^2) time in the worst case.

Can be changed to collect block ids in first phase,
and then filter with binary search in second.
2022-11-16 11:01:07 +05:30
Alex Macleod
f75fc85783 Extend needless_borrowed_reference to structs and tuples, ignore _ 2022-11-15 18:24:18 +00:00
bors
38e059028f Auto merge of #9849 - koka831:fix/9748, r=Manishearth
Allow return types for closures with lifetime binder

fix https://github.com/rust-lang/rust-clippy/issues/9748

changelog: Fix [`unused_unit`] Allow return types for closures with lifetime binder
2022-11-15 09:13:54 +00:00
bors
5b0d727bad Auto merge of #9570 - nfejzic:lint-unchecked-duration-subtraction, r=llogiq
feat: lint unchecked subtraction of a 'Duration' from an 'Instant'

Hello all, I tried to tackle the open issue #9371 and this is what I came up with.

I have a difficulty currently - some tests are failing:

```
failures:
    [ui] ui/manual_instant_elapsed.rs
```

The `manual_instant_elapsed` is failing because of `Instant::now() - duration` test, this now gets also picked by `unchecked_duration_subtraction` lint.
What is the correct way to proceed in this case? Simply update the `.stderr` file for `manual_instant_elapsed` lint?

changelog: [`unchecked_duration_subtraction`]: Add lint for unchecked subtraction of a `Duration` from an `Instant`.

fixes #9371
2022-11-15 06:09:10 +00:00
Aphek
93ac0f58bf Keep ref on infallible_destructuring_match suggestion 2022-11-15 01:57:56 -03:00
koka
7c4611c7e1
Allow return types for closures with lifetime binder 2022-11-15 12:58:17 +09:00
bors
a5995279fb Auto merge of #9837 - DesmondWillowbrook:never_loop, r=dswij
fix never_loop false positive

fixes #9831

changelog: [`never_loop`]: fixed false positive on unconditional break in internal labeled block
2022-11-13 15:44:14 +00:00
bors
493b78885a Auto merge of #9829 - hrxi:pr_or_fun_call, r=llogiq
Make it clear that `or_fun_call` can be a false-positive

Also move it to nursery so that the false-positives can be dealt with.

CC #8574

changelog: [`or_fun_call`]: Mention false-positives, move to nursery.
2022-11-13 14:29:42 +00:00
bors
6ba3a00b94 Auto merge of #9822 - Veykril:unnecessary-safety-doc, r=Jarcho
Add `unnecessary_safety_doc` lint

changelog: [`unnecessary_safety_doc`]: Add `unnecessary_safety_doc` lint

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

This lint does not trigger for private functions, just like `missing_safety_docs`. Reason for that was implementation simplicity and because I figured asking first would make more sense, so if it should trigger for private functions as well let me know and I'll fix that up as well.
2022-11-13 14:18:04 +00:00
bors
a8151409a0 Auto merge of #9698 - kraktus:xc_bool, r=xFrednet
[`fn_params_excessive_bools`] Make it possible to allow the lint at the method level

changelog: FP: [`fn_params_excessive_bools`]: `#[allow]` now works on methods

fix https://github.com/rust-lang/rust-clippy/issues/9687

Tested without committing but `#[allow]`ing now works. Also rewrote the lint to be a late lint while at it :)
r? `@xFrednet`
2022-11-13 09:57:36 +00:00
hrxi
243661b739 Make it clear that or_fun_call can be a false-positive
Also move it to nursery so that the false-positives can be dealt with.

CC #8574
2022-11-12 22:26:09 +01:00
bors
9f283c97e1 Auto merge of #9835 - koka831:fix/9035, r=Alexendoo
Avoid linting unsized mutable reference

fix https://github.com/rust-lang/rust-clippy/issues/9035

changelog: [`mut_mut`] avoid suggesting to reborrow unsized mutable reference
2022-11-12 21:07:18 +00:00
Kartavya Vashishtha
989986144c
fix never_loop false positive
on unconditional break to internal labeled block

ref #9831
2022-11-12 20:36:30 +05:30
koka
34c4520eae
Fix is_async_fn to check FnKind::Method 2022-11-12 22:36:20 +09:00
koka
93edc127a0
Avoid lint to unsized mutable reference 2022-11-12 20:31:25 +09:00
bors
cad0d3d6da Auto merge of #9662 - ebobrow:result-large-err, r=dswij
`result_large_err` show largest variants in err msg

fixes #9538

changelog: Sugg: [`result_large_err`]: Now show largest enum variants in error message
2022-11-11 06:58:59 +00:00
koka
2bc04bdac2
fix: cognitive_complexity for async fn 2022-11-11 00:14:18 +09:00
Nadir Fejzic
862ac29192 fix: remove (redundant) semicolon in lint suggestion 2022-11-10 15:47:12 +01:00
Nadir Fejzic
62ab4fb9c2 fix: add rust-fix annotation to unckd. duration subtr. lint test 2022-11-10 15:47:12 +01:00