Commit Graph

17078 Commits

Author SHA1 Message Date
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
bors
ff3b49cfcb Auto merge of #10907 - Alexendoo:dev-new-lint-late-passes, r=Jarcho
Direct towards late passes in `cargo dev new_lint`

changelog: none

This would be the tooling part of #9311

- `--pass late` is now the default
- It prints a message recommending the use of a late pass if you choose `--pass early`
2023-06-10 18:29:29 +00: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
bors
9011c4d248 Auto merge of #10918 - Centri3:patch-2, r=xFrednet
Fix `excessive_nesting` example

whoops 😅

changelog: none
2023-06-10 13:06:44 +00: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
Catherine
d1957b87c8
Update excessive_nesting.rs 2023-06-09 16:29:34 -05:00
Catherine
b7fedb88cf
Update excessive_nesting.rs 2023-06-09 16:28:01 -05: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
85002b09a1 handle exponent without digits 2023-06-09 05:21:24 +02: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
bors
e2c655b4c0 Auto merge of #10909 - Alexendoo:useless-for-in-vec, r=llogiq
Fix `useless_vec` suggestion in `for _ in vec![..]`

Fixes https://github.com/rust-lang/rust/issues/111034
Fixes #2256

changelog: [`useless_vec`]: Fix suggestion in `for _ in vec![..]`
2023-06-08 17:52:25 +00:00
Alex Macleod
96697d2ee7 Fix useless_vec suggestion in for _ in vec![..] 2023-06-08 17:27:12 +00:00
Alex Macleod
46808be16f Direct towards late passes in cargo dev new_lint 2023-06-08 15:56:42 +00:00
Centri3
6afb3555d3 remove revisions 2023-06-08 10:15:58 -05: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
avborhanian
20548eba6c Swapping to matches macro. 2023-06-08 00:38:18 -07: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
8330887e1b Updating documentation and lint formatting. 2023-06-07 20:53:52 -07:00
avborhanian
339cd14f27 Adds new lint arc_with_non_send_or_sync 2023-06-07 20:53:48 -07:00
Centri3
5da34559ee Check if from proc macro and better tests 2023-06-07 18:34:34 -05:00
Centri3
725399a178 move to complexity but don't lint by default 2023-06-07 18:34:34 -05:00
Centri3
378d77584a work with lint attributes 2023-06-07 18:34:34 -05:00
Centri3
493a23e957 check non-inline modules, ignore all macros 2023-06-07 18:34:34 -05:00
Centri3
88143ac295 decided against reinventing the wheel 2023-06-07 18:34:34 -05:00
Catherine
a9da61b115 couple more notes 2023-06-07 18:34:34 -05:00
Centri3
e68dbc3308 add excessive_nesting
Close code block in example
2023-06-07 18:34:34 -05:00
Centri3
4af3ac1cd8 change it to nursery category 2023-06-07 18:22:50 -05:00
Centri3
97c10075ec add the excessive_* style lints 2023-06-07 18:22:50 -05:00
bors
2360f80143 Auto merge of #10897 - y21:issue10887, r=Alexendoo
[`missing_fields_in_debug`]: don't ICE when self type is a generic param

Fixes #10887

This PR fixes an ICE that happens when the implementor (self type) of a `Debug` impl is a generic parameter.
The lint calls `TyCtxt::type_of` with that self type, which ICEs when called with generic parameters, so this just adds a quick check before getting there to ignore them.

That can only happen inside of core itself (afaik) because the orphan rules forbid defining an impl such as `impl<T> Debug for T` outside of core, so I'm not sure how to add a test for this.
It seems like this impl in particular caused this: https://doc.rust-lang.org/stable/std/fmt/trait.Debug.html#impl-Debug-for-F

changelog: [`missing_fields_in_debug`]: don't ICE on blanket `Debug` impl in core
2023-06-07 22:35:52 +00: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
y21
7af77f74da don't allow as_slice for now 2023-06-07 08:54:32 +02: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
Centri3
ba1fb74bf1 check for _ instead 2023-06-06 21:01:14 -05: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