Commit Graph

13818 Commits

Author SHA1 Message Date
bors
a9d31e71be Auto merge of #8571 - PyroTechniac:empty-drop, r=flip1995
add `empty_drop`

Closes #8352

changelog: New lint [`empty_drop`]
2022-04-21 08:03:31 +00:00
Gryffon Bellish
8de3fb159d
Add empty_drop lint 2022-04-21 10:03:01 +02:00
bors
4c25880f0c Auto merge of #8716 - binggh:stable-sort-message-update, r=giraffate
Less authoritative stable_sort_primitive message

fixes #8241

Hey all - first contribution here so I'm deciding to start with something small.

Updated the linked message to be less authoritative as well as moved the lint grouping from `perf` to `pedantic` as suggested by `@camsteffen` under the issue.

changelog: [`stable_sort_primitive`]: emit less authoritative message and move to `pedantic`
2022-04-21 00:27:13 +00:00
bors
f99ad82f9e Auto merge of #8700 - youknowone:needless_match-false-positive, r=xFrednet
Fix needless_match false positive for if-let when the else block doesn't match to given expr

<!--

Thank you for making Clippy better!

We're collecting our changelog from pull request descriptions.
If your PR only includes internal changes, you can just write
`changelog: none`. Otherwise, please write a short comment
explaining your change. Also, it's helpful for us that
the lint name is put into brackets `[]` and backticks `` ` ` ``,
e.g. ``[`lint_name`]``.

If your PR fixes an issue, you can add "fixes #issue_number" into this
PR description. This way the issue will be automatically closed when
your PR is merged.

If you added a new lint, here's a checklist for things that will be
checked during review or continuous integration.

- \[ ] Followed [lint naming conventions][lint_naming]
- \[ ] Added passing UI tests (including committed `.stderr` file)
- \[x] `cargo test` passes locally
- \[x] 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

Note that you can skip the above if you are just opening a WIP PR in
order to get feedback.

Delete this line and everything above before opening your PR.

--->

fix #8695

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

changelog: Fixed ``[`needless_match`]`` false positive when else block expression differs.
2022-04-20 17:16:39 +00:00
bing
1b6b802b99 Better documentation wording and add known problems section 2022-04-20 23:11:54 +08:00
bors
e17b97c8e0 Auto merge of #8711 - kyoto7250:new-lint-bytes-count-to-len, r=giraffate
Take over: New lint bytes count to len

take over #8375
close #8083

This PR adds new lint about  considering replacing `.bytes().count()` with `.len()`.

Thank you in advance.

---

r! `@Manishearth`

changelog: adds new lint [`bytes_count_to_len`] to consider replacing `.bytes().count()` with `.len()`
2022-04-19 12:44:07 +00:00
kyoto7250
f19387d237 add checking type
adding test patterns

cargo dev bless

fix comment

add ;

delete :

fix suggestion code

and update stderr in tests.

use match_def_path when checking method name
2022-04-19 10:48:12 +09:00
Chase Ruskin
df1ec91d95 adds lint logic and test for bytes_count_to_len
formats code with

fixes single match clippy error to replace with if let

swaps ident.name.as_str to ident.name == sym for count fn
2022-04-19 10:48:10 +09:00
bors
cbdf17c884 Auto merge of #8707 - OneSignal:await-invalid-types, r=llogiq
Add `await_holding_invalid_type` lint

changelog: [`await_holding_invalid_type`]

This lint allows users to create a denylist of types which are not allowed to be
held across await points. This is essentially a re-implementation of the
language-level [`must_not_suspend`
lint](https://github.com/rust-lang/rust/issues/83310). That lint has a lot of
work still to be done before it will reach Rust stable, and in the meantime
there are a lot of types which can trip up developers if they are used
improperly.

I originally implemented this specifically for `tracing::span::Entered`, until I discovered #8434 and read the commentary on that PR. Given this implementation is fully user configurable, doesn't tie clippy to any one particular crate, and introduces no additional dependencies, it seems more appropriate.
2022-04-18 18:36:50 +00:00
Lily Mara
05086858c4 fixup! Add await_holding_invalid_type lint 2022-04-18 11:32:28 -07:00
Lily Mara
8eccbbed68 fixup! Add await_holding_invalid_type lint 2022-04-18 11:30:59 -07:00
Lily Mara
7e26edce65 fixup! Add await_holding_invalid_type lint 2022-04-18 11:16:35 -07:00
Lily Mara
a511072c2c fixup! Add await_holding_invalid_type lint 2022-04-18 10:34:25 -07:00
Lily Mara
ee3ebb35f4
Update clippy_lints/src/await_holding_invalid.rs
Co-authored-by: llogiq <bogusandre@gmail.com>
2022-04-18 10:32:11 -07:00
Lily Mara
228ce783bc
Update clippy_lints/src/await_holding_invalid.rs
Co-authored-by: llogiq <bogusandre@gmail.com>
2022-04-18 10:32:03 -07:00
Lily Mara
6d0baf2b16
Update clippy_lints/src/await_holding_invalid.rs
Co-authored-by: llogiq <bogusandre@gmail.com>
2022-04-18 10:31:57 -07:00
bors
95de4dcb5e Auto merge of #8701 - xFrednet:0000-clippy-print-hir-attr, r=flip1995
Rework `#[clippy::dump]` attribute for debugging

Hey `@rust-lang/clippy,` this adds a new `#[clippy::print_hir]` attribute that prints the node to the console using `{:#?}`. Personally, I use print debugging quite a lot while working on Clippy, and this is a simple shortcut that also works in the playground (Once this has been synced). The question is now, if we want to have this attribute. Are there any concerns? I think it's similar to our `#[clippy::author]` attribute.

I haven't added a test, as the `.stdout` file would require updates with every HIR change inside rustc. Here are some examples, for the current implementation

<details>
<summary>`do_something(&map);`</summary>

```rs
Expr {
    hir_id: HirId {
        owner: DefId(0:7 ~ aaa[995b]::main),
        local_id: 21,
    },
    kind: Call(
        Expr {
            hir_id: HirId {
                owner: DefId(0:7 ~ aaa[995b]::main),
                local_id: 17,
            },
            kind: Path(
                Resolved(
                    None,
                    Path {
                        span: tests/ui/aaa.rs:23:5: 23:17 (#0),
                        res: Def(
                            Fn,
                            DefId(0:6 ~ aaa[995b]::do_something),
                        ),
                        segments: [
                            PathSegment {
                                ident: do_something#0,
                                hir_id: Some(
                                    HirId {
                                        owner: DefId(0:7 ~ aaa[995b]::main),
                                        local_id: 16,
                                    },
                                ),
                                res: Some(
                                    Err,
                                ),
                                args: None,
                                infer_args: true,
                            },
                        ],
                    },
                ),
            ),
            span: tests/ui/aaa.rs:23:5: 23:17 (#0),
        },
        [
            Expr {
                hir_id: HirId {
                    owner: DefId(0:7 ~ aaa[995b]::main),
                    local_id: 20,
                },
                kind: AddrOf(
                    Ref,
                    Not,
                    Expr {
                        hir_id: HirId {
                            owner: DefId(0:7 ~ aaa[995b]::main),
                            local_id: 19,
                        },
                        kind: Path(
                            Resolved(
                                None,
                                Path {
                                    span: tests/ui/aaa.rs:23:19: 23:22 (#0),
                                    res: Local(
                                        HirId {
                                            owner: DefId(0:7 ~ aaa[995b]::main),
                                            local_id: 15,
                                        },
                                    ),
                                    segments: [
                                        PathSegment {
                                            ident: map#0,
                                            hir_id: Some(
                                                HirId {
                                                    owner: DefId(0:7 ~ aaa[995b]::main),
                                                    local_id: 18,
                                                },
                                            ),
                                            res: Some(
                                                Local(
                                                    HirId {
                                                        owner: DefId(0:7 ~ aaa[995b]::main),
                                                        local_id: 15,
                                                    },
                                                ),
                                            ),
                                            args: None,
                                            infer_args: true,
                                        },
                                    ],
                                },
                            ),
                        ),
                        span: tests/ui/aaa.rs:23:19: 23:22 (#0),
                    },
                ),
                span: tests/ui/aaa.rs:23:18: 23:22 (#0),
            },
        ],
    ),
    span: tests/ui/aaa.rs:23:5: 23:23 (#0),
}
```
</details>

<details>
<summary>`use std::collections::HashMap;`</summary>

```rs
Item {
    ident: HashMap#0,
    def_id: DefId(0:5 ~ aaa[995b]::{misc#1}),
    kind: Use(
        Path {
            span: tests/ui/aaa.rs:8:5: 8:30 (#0),
            res: Def(
                Struct,
                DefId(1:1294 ~ std[928b]::collections:#️⃣:map::HashMap),
            ),
            segments: [
                PathSegment {
                    ident: std#0,
                    hir_id: Some(
                        HirId {
                            owner: DefId(0:5 ~ aaa[995b]::{misc#1}),
                            local_id: 1,
                        },
                    ),
                    res: Some(
                        Def(
                            Mod,
                            DefId(1:0 ~ std[928b]),
                        ),
                    ),
                    args: None,
                    infer_args: false,
                },
                PathSegment {
                    ident: collections#0,
                    hir_id: Some(
                        HirId {
                            owner: DefId(0:5 ~ aaa[995b]::{misc#1}),
                            local_id: 2,
                        },
                    ),
                    res: Some(
                        Def(
                            Mod,
                            DefId(1:1193 ~ std[928b]::collections),
                        ),
                    ),
                    args: None,
                    infer_args: false,
                },
                PathSegment {
                    ident: HashMap#0,
                    hir_id: Some(
                        HirId {
                            owner: DefId(0:5 ~ aaa[995b]::{misc#1}),
                            local_id: 3,
                        },
                    ),
                    res: Some(
                        Err,
                    ),
                    args: None,
                    infer_args: false,
                },
            ],
        },
        Single,
    ),
    vis: Spanned {
        node: Inherited,
        span: tests/ui/aaa.rs:8:1: 8:1 (#0),
    },
    span: tests/ui/aaa.rs:8:1: 8:31 (#0),
}
```

</details>

<details>
<summary>`"100"`</summary>

```rs
Expr {
    hir_id: HirId {
        owner: DefId(0:7 ~ aaa[995b]::main),
        local_id: 27,
    },
    kind: Lit(
        Spanned {
            node: Str(
                "100",
                Cooked,
            ),
            span: tests/ui/aaa.rs:28:9: 28:14 (#0),
        },
    ),
    span: tests/ui/aaa.rs:28:9: 28:14 (#0),
}
```
</details>

---

changelog: Added `[clippy::print_hir]` to inspect rustc's internal representation
2022-04-18 13:06:03 +00:00
bing
7a73e09e35 Update lints 2022-04-18 14:48:34 +08:00
bing
7a4d07105f Less authoritative stable_sort_primitive message 2022-04-18 14:42:24 +08:00
Jeong YunWon
b94e24e95f Fix needless_match false positive for if-let
when the else block doesn't match to given expr
2022-04-18 14:33:13 +09:00
xFrednet
ccedc64e3a
Add #[clippy::print_hir] attribute for debugging 2022-04-18 00:51:28 +02:00
bors
e5ebece910 Auto merge of #8665 - InfRandomness:option_take_on_temporary, r=llogiq
Introduce needless_option_take lint

- \[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`

Fixes #8618

changelog: Introduce [`needless_option_take`] lint
2022-04-17 18:34:16 +00:00
bors
0f4f9ecdb3 Auto merge of #8709 - matthiaskrgr:lintcheckfix, r=llogiq
lintcheck: fix --fix

looks like --allow-no-vcs does no longer exist(?)

changelog: none
2022-04-16 10:22:08 +00:00
bors
b2959dbf69 Auto merge of #8706 - lupd:cast-abs-to-unsigned, r=xFrednet
Fix formatting of `cast_abs_to_unsigned` docs

The "use instead" section of the example was not being formatted as Rust code, and the "configuration" documentation was being formatted as Rust code.

changelog: `[cast_abs_to_unsigned]` Fix example/configuration formatting
2022-04-16 09:12:15 +00:00
bors
3abd2c08ab Auto merge of #8698 - xFrednet:0000-changelog-1-61, r=flip1995
Changelog for Rust 1.61 🐙

roses are red,
violets are blue,
this changelog,
is no longer a todo!

---

changelog: none
2022-04-16 08:26:27 +00:00
xFrednet
af721036af
Changelog for Rust 1.61 🐙 2022-04-16 10:25:25 +02:00
Matthias Krüger
5b35bd9c3e lintcheck: fix --fix
looks like --allow-no-vcs does no longer exist(?)
2022-04-16 00:56:28 +02:00
Lily Mara
534419282e fixup! Add await_holding_invalid_type lint 2022-04-15 14:54:19 -07:00
Lily Mara
3cd8b5a5ef fixup! Add await_holding_invalid_type lint 2022-04-15 14:45:58 -07:00
Lily Mara
4844325faf Add await_holding_invalid_type lint
changelog: [`await_holding_invalid_type`]

This lint allows users to create a denylist of types which are not allowed to be
held across await points. This is essentially a re-implementation of the
language-level [`must_not_suspend`
lint](https://github.com/rust-lang/rust/issues/83310). That lint has a lot of
work still to be done before it will reach Rust stable, and in the meantime
there are a lot of types which can trip up developers if they are used
improperly.
2022-04-15 14:39:10 -07:00
bors
9938daf5bc Auto merge of #8705 - cpw2n5:spellcheck, r=Manishearth
Spellcheck

I'm brand new to this so any feedback will be helpful. I set the project up locally and ran a spellcheck on it. The code changes should only be spelling corrections. I ran the build and tests and they came back successful locally.

changelog: Various spelling corrections in comments and code.
2022-04-15 21:20:02 +00:00
whodi
e475dde097 collapsible <> collspible 2022-04-15 14:19:01 -07:00
whodi
73b7cb9c49 shound -> should 2022-04-15 14:19:01 -07:00
whodi
2be7ad5b39 initialization misspell 2022-04-15 14:19:00 -07:00
whodi
fb1934b63f infallible <> infalliable in filename 2022-04-15 14:18:09 -07:00
whodi
29ef80c78a adding spell checking 2022-04-15 14:18:09 -07:00
dlup
d1a78f3ea5 Fix formatting of cast_abs_to_unsigned docs 2022-04-15 16:34:44 -04:00
bors
c0fce5a847 Auto merge of #8702 - youknowone:fix-typo, r=xFrednet
Fix typo in comment

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

changelog: none
2022-04-15 10:38:47 +00:00
Jeong YunWon
b592cc659b Fix typo in comment 2022-04-15 19:33:16 +09:00
bors
0bc93b67f5 Auto merge of #8563 - Jarcho:let_unit_1502, r=Jarcho
Don't lint `let_unit_value` when needed for type inferenece

fixes: #1502

Pinging `@dtolnay.` I think this is enough to fix the issue. Do you have a good list crates to test this on?

changelog: Don't lint `let_unit_value` when needed for type inference
2022-04-15 01:57:52 +00:00
Jason Newcomb
70f7c624e4 Allow more complex expressions in let_unit_value 2022-04-14 21:34:33 -04:00
Jason Newcomb
48bcc1d95f Move let_unit_value back into style 2022-04-14 21:33:32 -04:00
Jason Newcomb
d68ac9ccce Don't lint let_unit_value when needed for type inferenece 2022-04-14 21:32:51 -04:00
bors
80bcd9bc6e Auto merge of #8614 - pitaj:fix-7597, r=giraffate
assertions_on_constants: ignore indirect `cfg!`

Fixes #7597

changelog: [`assertions_on_constants`] ignore constants indirectly based on `cfg!`
2022-04-14 23:58:51 +00:00
bors
aade96f902 Auto merge of #8626 - pitaj:format_add_string, r=llogiq
New lint `format_add_strings`

Closes #6261

changelog: Added [`format_add_string`]: recommend using `write!` instead of appending the result of  `format!`
2022-04-14 14:29:22 +00:00
bors
ecb3c3fc7e Auto merge of #8677 - xFrednet:8213-manual-bits-suggestion, r=giraffate
Add `usize` cast to `clippy::manual_bits` suggestion

A fix for the suggestion from https://github.com/rust-lang/rust-clippy/pull/8213

changelog: [`manual_bits`]: The suggestion now includes a cast for proper type conversion
2022-04-14 12:59:23 +00:00
infrandomness
2903b56f17 Add tests and docs
This adds test to make sure correct behavior of lint
- The first test's option variable is not a temporary variable
- The second test does not make usage of `take()`
- The third test makes usage of `take()` and uses a temporary variable
2022-04-14 13:16:46 +02:00
infrandomness
822993675f Modify lint description 2022-04-14 13:16:34 +02:00
infrandomness
76268c0d55 Introduce new lint check
This checks if the expression has one of `core`, `option`, `Option` or
`as_ref` in its path, this avoids false positives
2022-04-14 13:16:20 +02:00
infrandomness
b52bc9b96b Swap type checked expression
Instead of type checking the entire expression (causing a false
positive), only type check for a subset of the expression (the receiver of
the matched function: `take()`)
2022-04-14 13:16:20 +02:00