Commit Graph

5963 Commits

Author SHA1 Message Date
y21
c9daec2585 [unnecessary_fold]: suggest turbofish if necessary 2023-06-12 03:20:55 +02:00
y21
7280ad9f7b [redundant_closure_call]: handle nested closures 2023-06-11 23:54:48 +02:00
Centri3
d989f432a4 Update needless_if.fixed 2023-06-11 07:12:46 -05:00
Centri3
3822441335 Update unnecessary_cast.stderr 2023-06-11 07:06:44 -05:00
Centri3
59bca098f9 don't lint on if let
don't lint on `if let`
2023-06-11 07:02:20 -05:00
Centri3
4c7bc1785d ignore more type aliases in unnecessary_cast
ignore more type aliases in unnecessary_cast
2023-06-11 06:59:01 -05:00
bors
f93df98b84 Auto merge of #10914 - y21:issue10912, r=giraffate
handle exponent without digits in `numeric_literal`

Fixes #10912

The numeric literal util module didn't check for exponents with no digits.
So:
384cf37612/clippy_utils/src/numeric_literal.rs (L163-L168)

`exponent` here would be the empty string, which passed the `!= "0"` check (when it shouldn't have, it should probably be treated as if the user wrote `E0`), then later fails when counting the digits and subtracting one (0 - 1 = overflow).

Also, interestingly I can't even write a test for this because exponents with no digits is some kind of error by itself and `cargo dev fmt` fails on it.

changelog: [`unreadable_literal`]: don't (debug) ICE on numeric literal with empty exponent
2023-06-11 02:43:45 +00:00
Centri3
7ba904245d make cargo test pass 2023-06-10 09:39:53 -05:00
bors
e986b6444e Auto merge of #10917 - Centri3:module_inception, r=xFrednet
allow disabling module inception on private modules

Fixes #10842

changelog: Enhancement [`module_inception`]: Added `allow-private-module-inception` configuration.
[#10917](https://github.com/rust-lang/rust-clippy/pull/10917)
<!-- changelog_checked -->
2023-06-10 13:21:48 +00:00
Centri3
b303e2053c allow disabling module inception on private modules
allow disabling module inception on private modules
2023-06-10 08:09:07 -05:00
Centri3
26f50395ba Add needless_if lint 2023-06-10 06:51:03 -05:00
Jason Newcomb
949712c90a Reborrow mutable references in explicit_iter_loop 2023-06-09 21:40:03 -04:00
Jason Newcomb
482baf2bcc Fix explicit_into_iter_loop with mutable references 2023-06-09 21:40:03 -04:00
Jason Newcomb
974900b50e Split for_loops tests 2023-06-09 21:39:58 -04:00
bors
d44ea7c5c5 Auto merge of #10785 - Centri3:diverting_sub_expression, r=Jarcho
Fix `diverging_sub_expression` not checking body of block

Fixes #10776

This also adds a warning to the test `ui/never_loop.rs`, not sure if this is correct or not.

changelog: [`diverging_sub_expression`]: Fix false negatives with body of block
2023-06-10 00:16:43 +00:00
y21
9d58a42623 [map_unwrap_or]: don't lint when referenced variable is moved 2023-06-10 01:38:04 +02:00
Jason Newcomb
b6fa4d43d3 Extend explicit_iter_loop to all types 2023-06-09 19:24:55 -04:00
bors
476efe92e7 Auto merge of #10672 - Centri3:excessive-width-lints, r=Alexendoo
Add `excessive_nesting` lint

changelog: new lint [`excessive_nesting`]
2023-06-09 20:47:06 +00:00
Centri3
35aff1ae86 refactor 2023-06-09 15:32:42 -05:00
Centri3
c1c134a288 ensure there are no stmts for expr check 2023-06-09 11:44:59 -05:00
Centri3
0c545c7bcc also lint single expression blocks
Update mixed_read_write_in_expression.rs

Update diverging_sub_expression.stderr
2023-06-09 11:44:59 -05:00
y21
bbb9204008 add test 2023-06-09 15:49:35 +02:00
bors
05de787089 Auto merge of #10913 - y21:issue10033, r=Manishearth,Centri3
[`unnecessary_to_owned`]: check that the adjusted type matches target

Fixes #10033.

Before this change, the lint would assume that removing the `.to_string()` in `f(&x.to_string())` would be ok if x is of some type that implements `Deref<Target = str>` and `f` takes a `&str`.
This turns out to not actually be ok if the `to_string` call is some method that exists on `x` directly, which happens if it implements `Display`/`ToString` itself.

changelog: [`unnecessary_to_owned`]: only lint if the adjusted receiver type actually matches
2023-06-09 08:52:44 +00:00
y21
dd084940de check that the adjusted receiver type matches target 2023-06-09 04:13:00 +02:00
bors
384cf37612 Auto merge of #10910 - Alexendoo:unnecessary-pointer-casts, r=llogiq
Ignore more pointer types in `unnecessary_cast`

Spotted this because

e2c655b4c0/tests/ui/suspicious_to_owned.rs (L9-L10)

currently fails on `aarch64-unknown-linux-gnu` as `c_char` is `u8` there

The current implementation checks for `as alias`, `as _`. This adds things like
- `as *const alias`
- `as *const cfg_dependant`
- `as *const _`

changelog: none
2023-06-08 19:38:12 +00:00
Alex Macleod
4346c992cb Ignore more pointer types in unnecessary_cast 2023-06-08 18:19:35 +00:00
Renato Lochetti
55c9100334
Don't ling as_conversions in proc macros 2023-06-08 19:04:35 +01:00
Alex Macleod
96697d2ee7 Fix useless_vec suggestion in for _ in vec![..] 2023-06-08 17:27:12 +00:00
bors
b7c330fc78 Auto merge of #10905 - y21:issue10684, r=Alexendoo
[`redundant_closure`]: special case inclusive ranges

Fixes #10684.

`x..=y` ranges need a bit of special handling in this lint because it desugars to a call to the lang item `RangeInclusiveNew`, where the callee span would be the same as the range expression itself, so the suggestion looked a bit weird. It now correctly suggests `RangeInclusive::new`.

changelog: [`redundant_closure`]: special case `RangeInclusive`
2023-06-08 12:15:35 +00:00
bors
60258b061d Auto merge of #10898 - avborhanian:master, r=Manishearth,Centri3
Adds new lint `arc_with_non_send_or_sync`

Fixes #653

Adds a new lint to check for uses of non-Send/Sync types within Arc.

```
changelog: [`arc_with_non_send_sync`]: Added a lint to detect uses of non-Send/Sync types within Arc.
```
2023-06-08 09:46:01 +00:00
Centri3
5692677b3b cleanup spaghetti code 2023-06-08 02:41:51 -05:00
avborhanian
2f5d1c748a Adding extra check to ignore generic args. 2023-06-08 00:22:04 -07:00
bors
177c6fea1f Auto merge of #10901 - y21:smarter-useless-vec, r=Manishearth,Centri3
[`useless_vec`]: lint `vec!` invocations when a slice or an array would do

First off, sorry for that large diff in tests. *A lot* of tests seem to trigger the lint with this new change, so I decided to `#![allow()]` the lint in the affected tests to make reviewing this easier, and also split the commits up so that the first commit is the actual logic of the lint and the second commit contains all the test changes. The stuff that changed in the tests is mostly just line numbers now. So, as large as the diff looks, it's not actually that bad. 😅
I manually went through all of these to find out about edge cases and decided to put them in `tests/ui/vec.rs`.

For more context, I wrote about the idea of this PR here: https://github.com/rust-lang/rust-clippy/issues/2262#issuecomment-1579155257 (that explains the logic)

Basically, it now also considers the case where a `Vec` is put in a local variable and the user only ever does things with it that one could also do with a slice or an array. This should catch a lot more cases, and (at least from looking at the tests) it does.

changelog: [`useless_vec`]: lint `vec!` invocations when a slice or an array would do (also considering local variables now)
2023-06-08 04:33:26 +00:00
bors
9ca1344d9a Auto merge of #10904 - lochetti:fix_10273, r=Centri3
`suspicious_else_formatting`: Don't warn if there is a comment between else and curly bracket

This PR fixes https://github.com/rust-lang/rust-clippy/issues/10273

The idea is that if the only thing after `else` and before `{` is a comment, we will not warn because, probably, the line break was "made" by rustfmt.

changelog: [`suspicious_else_formatting`]: Don't warn if the only thing between `else` and curly bracket is a comment
2023-06-08 04:18:08 +00:00
avborhanian
339cd14f27 Adds new lint arc_with_non_send_or_sync 2023-06-07 20:53:48 -07:00
Centri3
0e233492d3 use trait solver instead; created spaghetti code 2023-06-07 21:43:28 -05:00
Centri3
e68dbc3308 add excessive_nesting
Close code block in example
2023-06-07 18:34:34 -05:00
Centri3
97c10075ec add the excessive_* style lints 2023-06-07 18:22:50 -05:00
y21
9ff34acf21 actually don't lint for inclusive range 2023-06-08 00:34:23 +02:00
y21
2c7cf2cfa1 handle RangeInclusive function desugar 2023-06-07 22:57:15 +02:00
Renato Lochetti
3e8f53b51d
Don't warn if there is a comment between else and curly bracket 2023-06-07 09:42:37 +01:00
bors
7c34ec8947 Auto merge of #10896 - y21:eager-or-lazy-autoderef, r=blyxyas,xFrednet
consider autoderef through user-defined `Deref` in `eager_or_lazy`

Fixes #10462

This PR handles autoderef in the `eager_or_lazy` util module and stops suggesting to change lazy to eager if autoderef in an expression goes through user defined `Deref` impls, e.g.
```rs
struct S;
impl Deref for S {
  type Target = ();
  fn deref(&self) -> &Self::Target { &() }
}

let _ = Some(()).as_ref().unwrap_or_else(|| &S); // autoderef `&S` -> `&()`
```

changelog: [`unnecessary_lazy_evaluations`]: don't suggest changing lazy evaluation to eager if autoderef goes through user-defined `Deref`

r? `@xFrednet`  (because of the earlier review in #10864, might help for context here)
2023-06-07 07:14:12 +00:00
bors
f729147325 Auto merge of #10865 - Centri3:let_with_type_underscore_tracing, r=Jarcho
[`let_with_type_underscore`]: Don't emit on locals from procedural macros

closes #10498

changelog: [`let_with_type_underscore`]: Don't emit on locals from procedural macros
2023-06-07 05:02:42 +00:00
bors
c8a056547b Auto merge of #10564 - asquared31415:cast_doesnt_wrap, r=giraffate
make cast_possible_wrap work correctly for 16 bit {u,i}size

These changes make `cast_possible_wrap` aware of the different pointer widths and fixes the implementation to print the correct pointer widths.

Fixes #9337

changelog: `cast_possible_wrap` does not lint on `u8 as isize` or `usize as i8`, since these can never wrap.
`cast_possible_wrap` now properly considers 16 bit pointer size and prints the correct bit widths.
2023-06-06 23:54:27 +00:00
bors
cc8ead2cce Auto merge of #10570 - AlessioC31:redundant_type_annotations, r=xFrednet
Add redundant type annotations lint

Hello, I'm trying to add the `redundat_type_annotations` lint.

It's still WIP but I'd like to start gathering some feedbacks to be sure that I'm not doing things 100% wrong :)

Right now it still misses lints like:

- [x] `let foo: u32 = 5_u32`,
- [x] `let foo: String = STest2::func()`
- [x] `let foo: String = self.func()` (`MethodCall`)
- [x] refs
- [ ] Generics

I've some problems regarding the second example above, in the `init` part of the `Local` I have:

```rust
init: Some(
                Expr {
                    hir_id: HirId(DefId(0:24 ~ playground[e1bd]::main).58),
                    kind: Call(
                        Expr {
                            hir_id: HirId(DefId(0:24 ~ playground[e1bd]::main).59),
                            kind: Path(
                                TypeRelative(
                                    Ty {
                                        hir_id: HirId(DefId(0:24 ~ playground[e1bd]::main).61),
                                        kind: Path(
                                            Resolved(
                                                None,
                                                Path {
                                                    span: src/main.rs:77:21: 77:27 (#0),
                                                    res: Def(
                                                        Struct,
                                                        DefId(0:17 ~ playground[e1bd]::STest2),
                                                    ),
                                                    segments: [
                                                        PathSegment {
                                                            ident: STest2#0,
                                                            hir_id: HirId(DefId(0:24 ~ playground[e1bd]::main).60),
                                                            res: Def(
                                                                Struct,
                                                                DefId(0:17 ~ playground[e1bd]::STest2),
                                                            ),
                                                            args: None,
                                                            infer_args: true,
                                                        },
                                                    ],
                                                },
                                            ),
                                        ),
                                        span: src/main.rs:77:21: 77:27 (#0),
                                    },
                                    PathSegment {
                                        ident: get_numb#0,
                                        hir_id: HirId(DefId(0:24 ~ playground[e1bd]::main).62),
                                        res: Err,
                                        args: None,
                                        infer_args: true,
                                    },
                                ),
                            ),
                            span: src/main.rs:77:21: 77:37 (#0),
                        },
                        [],
                    ),
                    span: src/main.rs:77:21: 77:39 (#0),
                },
            ),
```

And I'm not sure how to get the return type of the function `STest2::func()` since the resolved path `DefId` points to the struct itself and not the function. Do you have any idea on how I could get this information in this case?

Thanks!

changelog: changelog: [`redundant_type_annotations`]: New lint to warn on redundant type annotations

fixes #9155
2023-06-06 21:10:29 +00:00
y21
05f78e530a allow the lint in a bunch of tests 2023-06-06 22:56:57 +02:00
asquared31415
7cd0ec58aa add more info link 2023-06-06 14:58:54 -04:00
y21
e70dd55fd6 account for autoderef in eager_or_lazy 2023-06-06 00:18:07 +02:00
Centri3
6ea7cd8ec7 Fix #10504, don't lint on derived code 2023-06-05 14:38:38 -05:00
bors
b033883e2b Auto merge of #10864 - y21:issue10437, r=blyxyas,xFrednet
[`unnecessary_lazy_eval`]: don't lint on types with deref impl

Fixes #10437.
This PR changes clippy's util module `eager_or_lazy` to also consider deref expressions whose type has a non-builtin deref impl and not suggest replacing it as that might have observable side effects.
A prominent example might be the `lazy_static` macro, which creates a newtype with a `Deref` impl that you need to go through to get access to the inner value. Going from lazy to eager can make a difference there.

changelog: [`unnecessary_lazy_eval`]: don't lint on types with non-builtin deref impl
2023-06-05 11:21:45 +00:00
bors
4895a40108 Auto merge of #10705 - Alexendoo:old-test-headers, r=flip1995
Add a test that checks for old style test headers

Follow up to #10669, we're pretty used to them so they're easy to slip through

changelog: none
2023-06-05 08:43:44 +00:00
Alessio Cosenza
29ab954a2b
Add support to returned refs from MethodCall 2023-06-05 10:22:45 +02:00
Alessio Cosenza
01b1057258
Add redundant type annotations lint 2023-06-05 10:22:42 +02:00
bors
ae880e41a8 Auto merge of #10873 - Alexendoo:redundant-clone-nursery, r=flip1995
Move `redundant_clone` to `nursery`

changelog: [`redundant_clone`]: Move to `nursery`

A bunch of FPs in `redundant_clone` have sprung up after upstream MIR changes: https://github.com/rust-lang/rust/pull/108944

- https://github.com/rust-lang/rust-clippy/issues/10870
- https://github.com/rust-lang/rust-clippy/issues/10577
- https://github.com/rust-lang/rust-clippy/issues/10545
- https://github.com/rust-lang/rust-clippy/issues/10517

r? `@flip1995`
2023-06-05 08:00:51 +00:00
Centri3
e24fc9af23 Fix missing_const_for_fn not checking ~const Destruct 2023-06-04 21:50:51 -05:00
bors
eacd095f76 Auto merge of #10826 - Centri3:endian_bytes, r=Manishearth
Add lints for disallowing usage of `to_xx_bytes` and `from_xx_bytes`

Adds `host_endian_bytes`, `little_endian_bytes` and `big_endian_bytes`

Closes #10765

v - not sure what to put here since this adds 3 lints
changelog: Add `host_endian_bytes`, `little_endian_bytes` and `big_endian_bytes` lints
2023-06-05 02:38:41 +00:00
bors
1841661c80 Auto merge of #10869 - Centri3:allow_attributes, r=Manishearth
[`allow_attributes`, `allow_attributes_without_reason`]: Ignore attributes from procedural macros

I use `lint_reasons` and `clap`, which is a bit overzealous when it comes to preventing warnings in its macros; it uses a ton of allow attributes on everything to, as ironic as it is, silence warnings. These two now ignore anything from procedural macros.

PS, I think `allow_attributes.rs` should be merged with `attrs.rs` in the future.

fixes #10377

changelog: [`allow_attributes`, `allow_attributes_without_reason`]: Ignore attributes from procedural macros
2023-06-05 02:02:19 +00:00
bors
4886937212 Auto merge of #10853 - MarcusGrass:fix-from-over-into-self, r=Alexendoo
Ignore fix for `from_over_into` if the target type contains a `Self` reference

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

This is my first time contributing here, and the fix is kind of ugly.
I've worked a bit with `quote` and was trying to figure out a way to replace the type in a better way than just a raw string-replace but couldn't quite figure out how to.

The only thing really required to fix this, is to replace all `Self` references with the type stated in the `from` variable, this isn't entirely simple to do with raw strings without creating a mess though.

We need to find and replace all `Self`'s in a variable with `from` but there could be an arbitrary amount, in a lot of different positions. As well as some type that contains the name self, like `SelfVarSelf` which shouldn't be replaced.

The strategy is essentially, if `"Self"` is surrounded on both sides by something that isn't alphanumeric, then we're golden, then trying to make that reasonably efficient.

I would not be offended if the solution is too messy to accept!

changelog: [from_over_into]: Replace Self with the indicated variable in suggestion and fix.
2023-06-04 17:53:54 +00:00
bors
58befc7de8 Auto merge of #10855 - Centri3:explicit_deref_methods, r=llogiq
Fix suggestion on fully qualified syntax

fixes #10850

changelog: [`explicit_deref_methods`]: Fix malformed suggestion on `Foo::deref(&foo)`
2023-06-04 14:40:50 +00:00
Centri3
b469e8ce21 Update allow_attributes_without_reason.rs 2023-06-03 18:35:53 -05:00
Centri3
70553711ae add test for ? desugaring 2023-06-03 18:34:12 -05:00
y21
5a7e33e5b2 add plural form to useless_conversion if depth > 0 2023-06-03 19:38:55 +02:00
bors
8a30f2f71a Auto merge of #10814 - y21:issue10743, r=llogiq
new lint: `explicit_into_iter_fn_arg`

Closes #10743.
This adds a lint that looks for `.into_iter()` calls in a call expression to a function that already expects an `IntoIterator`. In those cases, explicitly calling `.into_iter()` is unnecessary.
There were a few instances of this in clippy itself so I fixed those as well in this PR.

changelog: new lint [`explicit_into_iter_fn_arg`]
2023-06-03 15:57:36 +00:00
bors
2490de476a Auto merge of #10866 - est31:manual_let_else_pattern, r=Manishearth
manual_let_else: support struct patterns

This adds upon the improvements of #10797 and:

* Only prints `()` around `Or` patterns at the top level (fixing a regression of #10797)
* Supports multi-binding patterns: `let (u, v) = if let (Some(u_i), Ok(v_i)) = ex { (u_i, v_i) } else ...`
* Traverses through tuple patterns: `let v = if let (Some(v), None) = ex { v } else ...`
* Supports struct patterns: `let v = if let S { v, w, } = ex { (v, w) } else ...`

```
changelog: [`manual_let_else`]: improve pattern printing to support struct patterns
```

fixes #10708
fixes #10424
2023-06-03 14:25:39 +00:00
bors
52c235351a Auto merge of #10879 - Centri3:ptr_cast_constness, r=blyxyas,xFrednet
[`ptr_cast_constness`]: Only lint on casts which don't change type

fixes #10874

changelog: [`ptr_cast_constness`]: Only lint on casts which don't change type
2023-06-03 13:19:59 +00:00
Centri3
cd1d7a3c6f weird 2023-06-02 13:26:12 -05:00
Centri3
ad7c44b3e4 only lint when cast_from and cast_to's ty are the same 2023-06-02 13:14:16 -05:00
bors
c85ceeae3f Auto merge of #10821 - Centri3:unnecessary_operation_cast_underscore, r=dswij
Emit `unnecessary_cast` on raw pointers as well

Supersedes(?) #10782, since this and #10567 will cover the original issue.
Does not lint on type aliases or inferred types.

changelog: [`unnecessary_cast`]: Also emit on casts between raw pointers with the same type and constness
2023-06-02 17:23:56 +00:00
Alex Macleod
e29a68113f Move redundant_clone to nursery 2023-06-02 15:13:55 +00:00
est31
f538402701 Support struct patterns 2023-06-02 14:46:27 +02:00
est31
86d57b7bd4 Support multi-binding situations as well as tuple patterns 2023-06-02 14:46:27 +02:00
bors
7c448a6910 Auto merge of #10860 - ihciah:master, r=Manishearth
add checking for cfg(features = ...)

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

changelog: [`maybe_misused_cfg`]: check if `#[cfg(feature = "...")]` misused as `#[cfg(features = "...")]`

I've found that there is no indication when `#[cfg(features = "...")]` is used incorrectly, which can easily make mistakes hard to spot. When I searched for this code on github, I also found many misuse cases([link](https://github.com/search?q=%23%5Bcfg%28features+language%3ARust&type=code)).

PS: This clippy name is just a temporary name, it can be replaced with a better name.
2023-06-02 09:36:05 +00:00
ihciah
ad76687b2f add checking for cfg(features = ...) 2023-06-02 09:01:51 +00:00
Philipp Krones
aa3247c891
Merge remote-tracking branch 'upstream/master' into rustup 2023-06-02 10:17:55 +02:00
Centri3
143ff2dfc3 Use type snippet instead of init expr for proc macro check 2023-06-01 22:29:06 -05:00
Centri3
497f37793e Fix attr_search_pat for #[cfg_attr] 2023-06-01 21:26:41 -05:00
Centri3
ab70553a38 foiled again (forgot to run cargo test) 2023-06-01 20:32:08 -05:00
Centri3
0086b6ab0a don't lint allow_attributes on attributes from proc macros 2023-06-01 20:24:41 -05:00
Centri3
0cc1454db5 Fix #10498 2023-06-01 18:13:01 -05:00
y21
a239c8b52b [unnecessary_lazy_eval]: don't lint on types with deref impl 2023-06-02 00:06:34 +02:00
Centri3
eed466281c ignore Foo::deref altogether 2023-06-01 14:29:56 -05:00
est31
0a7366897d manual_let_else: only add () around PatKind::Or at the top level
At the top level, () are required, but on the levels below they are not.
2023-06-01 18:55:24 +02:00
MarcusGrass
b2c85b31bb
Move bail into lint to prevent no-linting, move to unfixable 2023-06-01 16:02:42 +02:00
MarcusGrass
16f1cf8fd4
Ignore from_over_into if it contains Self 2023-06-01 10:46:29 +02:00
Centri3
8188da3614 Fix suggestion on fully qualified syntax 2023-05-31 23:33:30 -05:00
Centri3
04b7cae37e refine output 2023-05-31 17:30:23 -05:00
Centri3
97a0ccc1d3 implement host_endian_bytes and the other two 2023-05-31 17:30:23 -05:00
Centri3
3ab6aeefb1 to_xx_bytes implemented, from_xx_bytes todo
Mentioned in #10765
2023-05-31 17:30:23 -05:00
y21
a859b0e6df don't lint enums, update note in lint description 2023-05-31 23:52:02 +02:00
y21
f74ec6b1b8 new lint: missing_field_in_debug
move some strings into consts, more tests

s/missing_field_in_debug/missing_fields_in_debug

dont trigger in macro expansions

make dogfood tests happy

minor cleanups

replace HashSet with FxHashSet

replace match_def_path with match_type

if_chain -> let chains, fix markdown, allow newtype pattern

fmt

consider string literal in `.field()` calls as used

don't intern defined symbol, remove mentions of 'debug_tuple'

special-case PD, account for field access through `Deref`
2023-05-31 23:52:02 +02:00
MarcusGrass
d4b388eb43
Add from_over_into replace for type in Self reference 2023-05-31 17:46:05 +02:00
bors
e85869578d Auto merge of #10845 - disco07:master, r=giraffate
nonminimal_bool fix double not

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

changelog: Fix [`nonminimal_bool`] false positive when `!!x`, `x` isn't boolean and implements `Not`
2023-05-31 13:36:09 +00:00
Urgau
1a5db18b11 Drop uplifted clippy::cast_ref_to_mut 2023-05-31 13:42:53 +02:00
disco07
e4927f98fa change booleans file and update tests 2023-05-31 00:17:26 +02:00
y21
d816eba09d fix new failing proc macro tests 2023-05-30 22:32:47 +02:00
y21
de1f410018 merge explicit_into_iter_fn_arg into useless_conversion 2023-05-30 22:32:26 +02:00
Charalampos Mitrodimas
288312463e [wildcard_imports] Modules that contain prelude are also allowed
This commit fixes #10846 by checking if the path segment contains the
word "prelude".

Signed-off-by: Charalampos Mitrodimas <charmitro@gmail.com>
2023-05-30 21:29:04 +03:00
disco07
d3534a6521 fix issues 10836 2023-05-30 07:43:10 +02:00
Alex Macleod
c10876e6c5 from_over_into: Show suggestions for non-Self expanded paths 2023-05-28 21:50:08 +00:00
Renato Lochetti
ffc2bc83b0
Fixing invalid_regex with invalid UTF8. Also, adding more test cases 2023-05-28 12:53:03 +01:00
bors
dc17e7317b Auto merge of #10797 - est31:manual_let_else_pattern, r=llogiq
Improve pattern printing for manual_let_else

* Address a formatting issue pointed out in https://github.com/rust-lang/rust-clippy/pull/10175/files#r1137091002
* Replace variables inside | patterns in the if let: `let v = if let V::A(v) | V::B(v) = v { v } else ...`
* Support nested patterns: `let v = if let Ok(Ok(Ok(v))) = v { v } else ...`
* Support tuple structs with more than one arg: `let v = V::W(v, _) = v { v } else ...`; note that more than one *capture* is still not supported, so it bails for `let (v, w) = if let E::F(vi, wi) = x { (vi, wi)}`
* Correctly handle .. in tuple struct patterns: `let v = V::X(v, ..) = v { v } else ...`

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

[lint_naming]: https://rust-lang.github.io/rfcs/0344-conventions-galore.html#lints

---

changelog: [`manual_let_else`]: improve variable name in suggestions

Closes #10431 as this PR is adding a test for the `mut` case.
2023-05-27 10:22:40 +00:00
bors
c9ddcf0d06 Auto merge of #10822 - Alexendoo:needless-else-cfg, r=llogiq
Ignore `#[cfg]`'d out code in `needless_else`

changelog: none (same release as #10810)

`#[cfg]` making things fun once more

This lead me to think about macro calls that expand to nothing as well, but apparently they produce an empty stmt in the AST so are already handled, added a test for that

r? `@llogiq`
2023-05-27 10:09:51 +00:00
Urgau
5a2094319b Drop uplifted clippy::invalid_utf8_in_unchecked 2023-05-27 00:16:47 +02:00
bors
f1fd4673bc Auto merge of #10813 - y21:issue10755, r=xFrednet
[`default_constructed_unit_structs`]: do not lint on type alias paths

Fixes #10755.

Type aliases cannot be used as a constructor, so this lint should not trigger in those cases.
I also changed `clippy_utils::is_ty_alias` to also consider associated types since [they kinda are type aliases too](48ec50ae39/compiler/rustc_resolve/src/late/diagnostics.rs (L1520)).

changelog: [`default_constructed_unit_structs`]: do not lint on type alias paths
2023-05-26 15:20:21 +00:00
disco07
0b507c6f04
redundant pattern matches! result 2023-05-26 15:38:38 +02:00
bors
05740adf6e Auto merge of #10807 - y21:issue10800, r=Jarcho
[`unused_async`]: do not consider `await` in nested `async` blocks as used

Fixes #10800.
This PR makes sure that `await` expressions inside of inner `async` blocks don't prevent the lint from triggering.
For example
```rs
async fn foo() {
  async {
    std::future::ready(()).await;
  }
}
```
Even though there *is* a `.await` expression in this function, it's contained in an async block, which means that the enclosing function doesn't need to be `async` too.

changelog: [`unused_async`]: do not consider `await` in nested `async` blocks as used
2023-05-26 00:30:24 +00:00
Centri3
d7a98f507a also ensure generics with the same type are linted 2023-05-25 04:17:36 -05:00
Centri3
d2de5769a1 add generics in test 2023-05-25 04:05:13 -05:00
Alex Macleod
021b7398e1 Ignore #[cfg]'d out code in needless_else 2023-05-24 21:45:46 +00:00
Centri3
94e586e85d actually appease CI
I should always run cargo test before committing 😅
2023-05-24 11:06:56 -05:00
Centri3
5adb270c8d ok 2023-05-24 11:02:35 -05:00
Centri3
7f7979f80b emit unnecessary_cast on raw pointers as well 2023-05-24 10:53:31 -05:00
y21
6a76101d3a update docs, simplify arg->param map, dont lint on chain 2023-05-24 15:59:12 +02:00
y21
516f4f6aef new lint: explicit_into_iter_fn_arg 2023-05-24 15:59:12 +02:00
Alex Macleod
47a024e81d Display the needless_return suggestion 2023-05-23 23:47:04 +00:00
bors
a0fd17d3f0 Auto merge of #10779 - Centri3:ptr_cast_constness, r=llogiq
Add new lint `ptr_cast_constness`

This adds a new lint which functions as the opposite side of the coin to `ptr_as_ptr`. Rather than linting only as casts that don't change constness, this lints only constness; suggesting to use `pointer::cast_const` or `pointer::cast_mut` instead.

changelog: new lint [`ptr_cast_constness`]
2023-05-23 21:40:50 +00:00
bors
97598e9e8f Auto merge of #10810 - samueltardieu:needless-else, r=llogiq
needless_else: new lint to check for empty `else` clauses

Empty `else` clauses are useless. They happen in the wild and are not linted yet: https://github.com/uutils/coreutils/pull/4880/files

`else` clauses containing or preceded by comments are not linted as the comments might be important.

changelog: [`needless_else`]: new lint
2023-05-23 21:28:40 +00:00
y21
8ef6240afb point to await expr in note 2023-05-23 17:22:23 +02:00
Centri3
5825b9e3e2 actually fix it 2023-05-23 00:35:00 -05:00
Centri3
f4b02aa374 fix #10776 2023-05-23 00:35:00 -05:00
bors
fe792d9f7d Auto merge of #10809 - nyurik:match-unsafe, r=Jarcho
Fix missing block for unsafe code

If a block is declared as unsafe, it needs an extra layer of curly braces around it.

Fixes #10808

This code adds handling for `UnsafeSource::UserProvided` block, i.e. `unsafe { ... }`. Note that we do not handle the `UnsafeSource::CompilerGenerated` as it seems to not be possible to generate that with the user code (?), or at least doesn't seem to be needed to be handled explicitly.

There is an issue with this code: it does not add an extra indentation for the unsafe blocks. I think this is a relatively minor concern for such an edge case, and should probably be done by a separate PR (fixing compile bug is more important than getting styling perfect especially when `rustfmt` will fix it anyway)

```rust
// original code
unsafe {
  ...
}

// code that is now generated by this PR
{ unsafe {
  ...
} }

// what we would ideally like to get
{
  unsafe {
    ...
  }
}
```

changelog: [`single_match`](https://rust-lang.github.io/rust-clippy/master/#single_match): Fix suggestion for `unsafe` blocks
2023-05-23 04:45:14 +00:00
Yuri Astrakhan
ed935de087 Run-rustfix 2023-05-22 23:00:28 -04:00
bors
ec2f2d5e47 Auto merge of #10806 - y21:issue10741, r=giraffate
[`large_stack_arrays`]: check array initializer expressions

Fixes #10741.
Prior to this PR, the lint only checked array repeat expressions (ie. `[T; n]`). Now it also checks array initializer expressions.

changelog: [`large_stack_arrays`]: check array initializer expressions
2023-05-23 00:14:01 +00:00
Yuri Astrakhan
9fd34e0c75 Use #[rustfmt::skip] 2023-05-22 20:02:45 -04:00
y21
8c82486ea9 [default_constructed_unit_structs]: do not lint type aliases 2023-05-22 16:13:23 +02:00
y21
3e1302fa0c [match_wild_err_arm]: do not lint in const contexts 2023-05-22 14:04:13 +02:00
Samuel "Sam" Tardieu
e6646eb5fd needless_else: new lint to check for empty else clauses 2023-05-22 11:52:26 +02:00
Yuri Astrakhan
e926148188 Fix unsafe blocks 2023-05-22 04:07:17 -04:00
Yuri Astrakhan
1c277d1be8 Unit tests highlighting unsafe match issue
These unit tests generate non-compilable code.  I did NOT `bless` them on purpose because the stderr output is not good.

I'm surprised we don't auto-compile the suggestions here - is this something that can be easily enabled?

See #10808
2023-05-22 02:48:14 -04:00
y21
1e73a9eb4b do not consider await in nested async blocks 2023-05-21 23:07:30 +02:00
y21
e9a98d925f add test case for #10741 2023-05-21 15:07:53 +02:00
Urgau
915ff71b7c Rename forget_ref lint to forgetting_references 2023-05-21 14:28:09 +02:00
Urgau
fdbfe0e249 Rename drop_ref lint to dropping_references 2023-05-21 14:16:41 +02:00
Urgau
234f2b67cb Rename forget_copy lint to forgetting_copy_types 2023-05-21 14:09:03 +02:00
Urgau
9b97ae98f8 Rename drop_copy lint to dropping_copy_types 2023-05-21 13:37:32 +02:00
Philipp Krones
b76b0aeb63 Merge commit '435a8ad86c7a33bd7ffb91c59039943408d3b6aa' into clippyup 2023-05-20 15:39:26 +02:00
Philipp Krones
96b32b1cb8
Merge remote-tracking branch 'upstream/master' into rustup 2023-05-20 15:32:20 +02:00
Guillaume Gomez
dbc76a7663 Add check for empty cfg all condition 2023-05-20 00:37:08 +02:00
Guillaume Gomez
fcf19481aa Add UI test for UNIQUE_CFG_CONDITION 2023-05-19 16:16:37 +02:00
bors
2a1dbbaec5 Auto merge of #10777 - Icxolu:unnecessary_collect, r=xFrednet
Enhance `needless_collect`: lint in method/function arguments that take an `IntoIterator`

Updates `needless_collect` to also lint `collect` calls in method/function arguments that take an `IntoIterator` (for example `Extend::extend`). Every `Iterator` trivially implements `IntoIterator` and collecting it only causes an unnecessary allocation.

---

changelog: Enhancement: [`needless_collect`]: Now also detects function arguments, taking a generic `IntoIterator`
[#10777](https://github.com/rust-lang/rust-clippy/pull/10777)
<!-- changelog_checked -->

fixes #10762
2023-05-19 12:26:43 +00:00
Jason Newcomb
58132cb3b0 Improve SpanlessEq
* Don't consider expansions of different macros to be the same, even if they expand to the same tokens
* Don't consider `cfg!` expansions to be equal if they check different configs.
2023-05-18 16:42:13 -04:00
Jason Newcomb
5351170744 Slightly refactor constant evaluation and add detection for empty macro expansion and cfged statements. 2023-05-18 15:43:33 -04:00
Jason Newcomb
0b3c2ed811 Search for inactive cfg attributes and empty macro expansion through
the entire block
2023-05-18 15:43:23 -04:00
Alex Macleod
cfa5aa2aad Don't suggest unnameable types in box_default, let_underscore_untyped 2023-05-18 18:51:27 +00:00
bors
22b319606f Auto merge of #10753 - disco07:master, r=xFrednet
redundant_pattern_matching

This PR try to solve this issue https://github.com/rust-lang/rust-clippy/pull/10726,
but it enter in conflict with another test.

changelog: none

Try to test this:
```
let _w = match x {
     Some(_) => true,
     _ => false,
};
```

this happen:
```
 error: match expression looks like `matches!` macro
   --> $DIR/match_expr_like_matches_macro.rs:21:14
    |
 LL |       let _w = match x {
    |  ______________^
 LL | |         Some(_) => true,
 LL | |         _ => false,
 LL | |     };
    | |_____^ help: try this: `matches!(x, Some(_))`

+error: redundant pattern matching, consider using `is_some()`
+  --> $DIR/match_expr_like_matches_macro.rs:21:14
+   |
+LL |       let _w = match x {
+   |  ______________^
+LL | |         Some(_) => true,
+LL | |         _ => false,
+LL | |     };
+   | |_____^ help: try this: `x.is_some()`
+   |
+   = note: `-D clippy::redundant-pattern-matching` implied by `-D warnings`
+
```
I need some help to fix this. Thanks
2023-05-18 09:52:27 +00:00
est31
ef38662d04 Some improvements to the manual_let_else lint suggestions
* Replace variables inside | patterns in the if let: let v = if let V::A(v) | V::B(v) = v { v } else ...
* Support nested patterns: let v = if let Ok(Ok(Ok(v))) = v { v } else ...
* Support tuple structs with more than one arg: let v = V::W(v, _) = v { v } else ...
* Correctly handle .. in tuple struct patterns: let v = V::X(v, ..) = v { v } else ...
2023-05-18 11:16:57 +02:00
bors
270cbeb735 Auto merge of #10674 - c410-f3r:macro-lint, r=Jarcho
Rename `integer_arithmetic`

The lack of official feedback in #10200 made me give up on pursuing the matter but after yet another use-case that is not handled by `integer_arithmetic` (#10615), I think it is worth trying again.

---

changelog: Move/Deprecation: Rename `integer_arithmetic` to `arithmetic_side_effects`
[#10674](https://github.com/rust-lang/rust-clippy/pull/10674)
<!-- changelog_checked -->
2023-05-18 05:26:33 +00:00
bors
815a07e667 Auto merge of #10725 - y21:issue9914, r=Jarcho
don't remove `dbg!` in arbitrary expressions

Fixes #9914

The `dbg_macro` lint replaces empty `dbg!` invocations with the empty string in its suggestion, which is not always valid code in certain contexts (e.g. `let _ = dbg!();` becomes `let _ = ;`). This PR changes it to `()`, which should always be valid where `dbg!()` is valid (`dbg!()` with no arguments evaluates to `()`).

It also special-cases "standalone" `dbg!();` expression statements, where it will suggest removing the whole statement entirely like it did before.

changelog: [`dbg_macro`]: don't remove `dbg!()` in arbitrary expressions as it sometimes results in syntax errors
2023-05-18 05:11:52 +00:00
bors
f3f6fd8920 Auto merge of #10775 - lochetti:fix_10723, r=xFrednet
Ignoring `let_underscore_untyped` warnings in code from proc macros

Don't linting let_underscore_untyped if code was generated by procedural macro.

This PR fixes https://github.com/rust-lang/rust-clippy/issues/10723

---

closes: https://github.com/rust-lang/rust-clippy/issues/10723

changelog: Fix: [`let_underscore_untyped`]: No longer lints inside proc macros
[#10775](https://github.com/rust-lang/rust-clippy/pull/10775)
<!-- changelog_checked -->
2023-05-18 01:59:38 +00:00
bors
223f5184ba Auto merge of #10682 - J-ZhengLi:issue10680, r=dswij
fix [`invalid_regex`] not recognizing new syntax introduced after regex-1.8.0

fixes: #10680

---

changelog: fix [`invalid_regex`] not recognizing new syntax introduced after regex-1.8.0

bump up `regex-syntax` dependency version to 0.7.0
2023-05-18 01:46:01 +00:00