Commit graph

17189 commits

Author SHA1 Message Date
Centri3
a434a7715d impl WithSearchPat for Ty 2023-06-06 22:16:02 -05: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
Centri3
e97f190a9d ty_search_pat 2023-06-06 18:05:15 -05: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
y21
566a365d4f make useless_vec smarter 2023-06-06 22:29:13 +02:00
asquared31415
7cd0ec58aa add more info link 2023-06-06 14:58:54 -04:00
bors
7ee3dcdb32 Auto merge of #10859 - MarcusGrass:let-and-ret-known-problems, r=giraffate
Bring up Rust lang #37612 as a known problem for let_and_return

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

I don't think conforming to this lint could trigger the issue immediately, only if subsequent code-changes go wrong, but I may be mistaken.

Since the lint can't trigger it by itself, just closing this issue might be reasonable, if not maybe this PR fixes it.

changelog: Update docs for `let_and_return`, mention rust-lang #37612
2023-06-06 00:09:09 +00:00
y21
1cf95a9d50 don't call type_of on generic params 2023-06-06 01:23:42 +02:00
y21
e70dd55fd6 account for autoderef in eager_or_lazy 2023-06-06 00:18:07 +02:00
Centri3
f68ee79864 Update trait_bounds.rs 2023-06-05 14:53:22 -05:00
Centri3
0250c51844 refactor 2023-06-05 14:46:47 -05:00
Centri3
6ea7cd8ec7 Fix #10504, don't lint on derived code 2023-06-05 14:38:38 -05:00
MarcusGrass
6f2497703e
Compact issue link
Co-authored-by: Takayuki Nakata <f.seasons017@gmail.com>
2023-06-05 15:48:57 +02: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
a9b468f2b5
Add Limitations section 2023-06-05 10:22:46 +02:00
Alessio Cosenza
29ab954a2b
Add support to returned refs from MethodCall 2023-06-05 10:22:45 +02:00
Alessio Cosenza
6f26df1c9a
Extract common logic to function 2023-06-05 10:22:45 +02:00
Alessio Cosenza
6776608f21
Move redundant_type_annotations to restriction 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
bors
8c0ed28c1c Auto merge of #10888 - Alexendoo:cargo-sparse-registry-env, r=flip1995
Remove `CARGO_UNSTABLE_SPARSE_REGISTRY` env from ci

changelog: none

Sparse registry is the default so we don't need these anymore
2023-06-05 07:24:52 +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
Alex Macleod
33b241dc7f Remove CARGO_UNSTABLE_SPARSE_REGISTRY env from ci
It is now the default to use the sparse registry
2023-06-04 18:01:56 +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
bors
167f249141 Auto merge of #10760 - NanthR:almost_standard_formulation, r=xFrednet
Standard lint formulations

A WIP that fixes #10660. Fix lints that don't conform to the standard formulation.

changelog: none
2023-06-04 10:48:03 +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
Centri3
05bfcbd911 remove tuple 2023-06-03 14:38:16 -05:00
Centri3
7fe200ed05 derive Copy/PartialEq for Prefix 2023-06-03 14:31:40 -05:00
bors
fdb0b04458 Auto merge of #10881 - y21:explicit-into-iter-fn-arg-followup, r=llogiq
[`useless_conversion`]: pluralize if there are multiple `.into_iter()` calls

context: https://github.com/rust-lang/rust-clippy/pull/10814#issuecomment-1575036086

changelog: [`useless_conversion`]: pluralize if there are multiple `.into_iter()` calls in the chain

r? `@llogiq`
2023-06-03 19:05:01 +00: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
bors
a97a94ab17 Auto merge of #10834 - whee:gh-pages-retain-filter-state, r=xFrednet
Use URL parameters for filter states

This fixes #8510 by storing Clippy Lints page filter configuration in the URL parameters.

This includes:
- Lint levels
- Lint groups
- Version filters

"Filter" was already present in the URL and its behavior is retained. There is existing support for passing a `sel` query parameter; this is also retained, but I am not sure if it used in the wild.

The URL parameters only get included if they are modified after loading the page.

I have these changes available here in case people want to play with it: https://whee.github.io/rust-clippy/master/

An example with levels, groups, and versions set (oddly):

https://whee.github.io/rust-clippy/master/#/?groups=pedantic,perf&levels=allow,warn&versions=gte:53,lte:57,eq:54

Adding a filter:

https://whee.github.io/rust-clippy/master/#/manual_str_repeat?groups=pedantic,perf&levels=allow,warn&versions=gte:53,lte:57,eq:54

---

changelog: Docs: [`Clippy's lint list`] now stores filter parameters in the URL, to allow easy sharing
[#10834](https://github.com/rust-lang/rust-clippy/pull/10834)
<!-- changelog_checked -->
2023-06-03 11:39:02 +00:00
Brian Hetro
ac279efdbc Clippy Lints page - Do not show filters in URL if configured as default values 2023-06-03 00:04:19 -04:00
Brian Hetro
2e4ef8e72c Clippy Lints page - Fix path watch triggering 2023-06-02 22:57:21 -04:00
Centri3
b1a21ae347 Update endian_bytes.rs 2023-06-02 14:38:03 -05:00
Centri3
a6c36556c8 use enum for prefix instead of &str 2023-06-02 14:35:54 -05:00
Raghul Nanth A
50c93bbfd2 refactor(test): Move attribute to lint level 2023-06-03 00:00:45 +05:30
Raghul Nanth A
7ac15f9000 Add lint to check lint formulation messages
Fix lints that don't conform to the standard formulation
2023-06-03 00:00:30 +05:30
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