]> git.lizzy.rs Git - rust.git/log
rust.git
2 years agoAuto merge of #8700 - youknowone:needless_match-false-positive, r=xFrednet
bors [Wed, 20 Apr 2022 17:16:39 +0000 (17:16 +0000)]
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.

2 years agoBetter documentation wording and add known problems section
bing [Wed, 20 Apr 2022 15:11:54 +0000 (23:11 +0800)]
Better documentation wording and add known problems section

2 years agoAuto merge of #8711 - kyoto7250:new-lint-bytes-count-to-len, r=giraffate
bors [Tue, 19 Apr 2022 12:44:07 +0000 (12:44 +0000)]
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()`

2 years agoRollup merge of #96142 - cjgillot:no-crate-def-index, r=petrochenkov
Dylan DPC [Tue, 19 Apr 2022 12:43:21 +0000 (14:43 +0200)]
Rollup merge of #96142 - cjgillot:no-crate-def-index, r=petrochenkov

Stop using CRATE_DEF_INDEX outside of metadata encoding.

`CRATE_DEF_ID` and `CrateNum::as_def_id` are almost always what we want.  We should not manipulate raw `DefIndex` outside of metadata encoding.

2 years agofix ICE
asquared31415 [Tue, 19 Apr 2022 02:19:34 +0000 (22:19 -0400)]
fix ICE

2 years agoadd checking type
kyoto7250 [Sat, 16 Apr 2022 08:53:22 +0000 (17:53 +0900)]
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

2 years agoadds lint logic and test for bytes_count_to_len
Chase Ruskin [Mon, 31 Jan 2022 00:16:10 +0000 (19:16 -0500)]
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

2 years agoAuto merge of #8707 - OneSignal:await-invalid-types, r=llogiq
bors [Mon, 18 Apr 2022 18:36:50 +0000 (18:36 +0000)]
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.

2 years agofixup! Add `await_holding_invalid_type` lint
Lily Mara [Mon, 18 Apr 2022 18:32:28 +0000 (11:32 -0700)]
fixup! Add `await_holding_invalid_type` lint

2 years agofixup! Add `await_holding_invalid_type` lint
Lily Mara [Mon, 18 Apr 2022 18:30:59 +0000 (11:30 -0700)]
fixup! Add `await_holding_invalid_type` lint

2 years agofixup! Add `await_holding_invalid_type` lint
Lily Mara [Mon, 18 Apr 2022 18:16:35 +0000 (11:16 -0700)]
fixup! Add `await_holding_invalid_type` lint

2 years agofixup! Add `await_holding_invalid_type` lint
Lily Mara [Mon, 18 Apr 2022 17:34:17 +0000 (10:34 -0700)]
fixup! Add `await_holding_invalid_type` lint

2 years agoUpdate clippy_lints/src/await_holding_invalid.rs
Lily Mara [Mon, 18 Apr 2022 17:32:11 +0000 (10:32 -0700)]
Update clippy_lints/src/await_holding_invalid.rs

Co-authored-by: llogiq <bogusandre@gmail.com>
2 years agoUpdate clippy_lints/src/await_holding_invalid.rs
Lily Mara [Mon, 18 Apr 2022 17:32:03 +0000 (10:32 -0700)]
Update clippy_lints/src/await_holding_invalid.rs

Co-authored-by: llogiq <bogusandre@gmail.com>
2 years agoUpdate clippy_lints/src/await_holding_invalid.rs
Lily Mara [Mon, 18 Apr 2022 17:31:57 +0000 (10:31 -0700)]
Update clippy_lints/src/await_holding_invalid.rs

Co-authored-by: llogiq <bogusandre@gmail.com>
2 years agoAuto merge of #8701 - xFrednet:0000-clippy-print-hir-attr, r=flip1995
bors [Mon, 18 Apr 2022 13:06:03 +0000 (13:06 +0000)]
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::hash::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

2 years agoUpdate lints
bing [Mon, 18 Apr 2022 06:48:34 +0000 (14:48 +0800)]
Update lints

2 years agoLess authoritative stable_sort_primitive message
bing [Mon, 18 Apr 2022 06:42:24 +0000 (14:42 +0800)]
Less authoritative stable_sort_primitive message

2 years agoFix needless_match false positive for if-let
Jeong YunWon [Fri, 15 Apr 2022 10:33:24 +0000 (19:33 +0900)]
Fix needless_match false positive for if-let

when the else block doesn't match to given expr

2 years agoAdd `#[clippy::print_hir]` attribute for debugging
xFrednet [Fri, 15 Apr 2022 09:37:58 +0000 (11:37 +0200)]
Add `#[clippy::print_hir]` attribute for debugging

2 years agoAuto merge of #8665 - InfRandomness:option_take_on_temporary, r=llogiq
bors [Sun, 17 Apr 2022 18:34:16 +0000 (18:34 +0000)]
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

2 years agoAuto merge of #95779 - cjgillot:ast-lifetimes-undeclared, r=petrochenkov
bors [Sun, 17 Apr 2022 12:56:19 +0000 (12:56 +0000)]
Auto merge of #95779 - cjgillot:ast-lifetimes-undeclared, r=petrochenkov

Report undeclared lifetimes during late resolution.

First step in https://github.com/rust-lang/rust/pull/91557

We reuse the rib design of the current resolution framework. Specific `LifetimeRib` and `LifetimeRibKind` types are introduced. The most important variant is `LifetimeRibKind::Generics`, which happens each time we encounter something which may introduce generic lifetime parameters. It can be an item or a `for<...>` binder. The `LifetimeBinderKind` specifies how this rib behaves with respect to in-band lifetimes.

r? `@petrochenkov`

2 years agoStop using CRATE_DEF_INDEX.
Camille GILLOT [Fri, 15 Apr 2022 17:27:53 +0000 (19:27 +0200)]
Stop using CRATE_DEF_INDEX.

`CRATE_DEF_ID` and `CrateNum::as_def_id` are almost always what we want.

2 years agoBless clippy.
Camille GILLOT [Fri, 1 Apr 2022 17:18:10 +0000 (19:18 +0200)]
Bless clippy.

2 years agoAuto merge of #95655 - kckeiks:create-hir-crate-items-query, r=cjgillot
bors [Sun, 17 Apr 2022 08:06:53 +0000 (08:06 +0000)]
Auto merge of #95655 - kckeiks:create-hir-crate-items-query, r=cjgillot

Refactor HIR item-like traversal (part 1)

Issue  #95004

- Create hir_crate_items query which traverses tcx.hir_crate(()).owners to return a hir::ModuleItems
- use tcx.hir_crate_items in tcx.hir().items() to return an iterator of hir::ItemId
- use tcx.hir_crate_items to introduce a tcx.hir().par_items(impl Fn(hir::ItemId)) to traverse all items in parallel;

Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
cc `@cjgillot`

2 years agoAuto merge of #8709 - matthiaskrgr:lintcheckfix, r=llogiq
bors [Sat, 16 Apr 2022 10:22:08 +0000 (10:22 +0000)]
Auto merge of #8709 - matthiaskrgr:lintcheckfix, r=llogiq

lintcheck: fix --fix

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

changelog: none

2 years agoAuto merge of #8706 - lupd:cast-abs-to-unsigned, r=xFrednet
bors [Sat, 16 Apr 2022 09:12:15 +0000 (09:12 +0000)]
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

2 years agoAuto merge of #8698 - xFrednet:0000-changelog-1-61, r=flip1995
bors [Sat, 16 Apr 2022 08:26:27 +0000 (08:26 +0000)]
Auto merge of #8698 - xFrednet:0000-changelog-1-61, r=flip1995

Changelog for Rust 1.61 :octopus:

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

---

changelog: none

2 years agoChangelog for Rust 1.61 :octopus:
xFrednet [Wed, 13 Apr 2022 21:14:35 +0000 (23:14 +0200)]
Changelog for Rust 1.61 :octopus:

2 years agoAuto merge of #94468 - Amanieu:global_asm_sym, r=nagisa
bors [Sat, 16 Apr 2022 04:46:01 +0000 (04:46 +0000)]
Auto merge of #94468 - Amanieu:global_asm_sym, r=nagisa

Implement sym operands for global_asm!

Tracking issue: #93333

This PR is pretty much a complete rewrite of `sym` operand support for inline assembly so that the same implementation can be shared by `asm!` and `global_asm!`. The main changes are:
- At the AST level, `sym` is represented as a special `InlineAsmSym` AST node containing a path instead of an `Expr`.
- At the HIR level, `sym` is split into `SymStatic` and `SymFn` depending on whether the path resolves to a static during AST lowering (defaults to `SynFn` if `get_early_res` fails).
  - `SymFn` is just an `AnonConst`. It runs through typeck and we just collect the resulting type at the end. An error is emitted if the type is not a `FnDef`.
  - `SymStatic` directly holds a path and the `DefId` of the `static` that it is pointing to.
- The representation at the MIR level is mostly unchanged. There is a minor change to THIR where `SymFn` is a constant instead of an expression.
- At the codegen level we need to apply the target's symbol mangling to the result of `tcx.symbol_name()` depending on the target. This is done by calling the LLVM name mangler, which handles all of the details.
  - On Mach-O, all symbols have a leading underscore.
  - On x86 Windows, different mangling is used for cdecl, stdcall, fastcall and vectorcall.
  - No mangling is needed on other platforms.

r? `@nagisa`
cc `@eddyb`

2 years agolintcheck: fix --fix
Matthias Krüger [Fri, 15 Apr 2022 22:56:28 +0000 (00:56 +0200)]
lintcheck: fix --fix

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

2 years agofixup! Add `await_holding_invalid_type` lint
Lily Mara [Fri, 15 Apr 2022 21:54:19 +0000 (14:54 -0700)]
fixup! Add `await_holding_invalid_type` lint

2 years agofixup! Add `await_holding_invalid_type` lint
Lily Mara [Fri, 15 Apr 2022 21:45:58 +0000 (14:45 -0700)]
fixup! Add `await_holding_invalid_type` lint

2 years agoAdd `await_holding_invalid_type` lint
Lily Mara [Thu, 14 Apr 2022 23:52:10 +0000 (16:52 -0700)]
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.

2 years agoAuto merge of #8705 - cpw2n5:spellcheck, r=Manishearth
bors [Fri, 15 Apr 2022 21:20:02 +0000 (21:20 +0000)]
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.

2 years agocollapsible <> collspible
whodi [Fri, 15 Apr 2022 19:28:48 +0000 (15:28 -0400)]
collapsible <> collspible

2 years agoshound -> should
whodi [Fri, 15 Apr 2022 19:20:54 +0000 (15:20 -0400)]
shound -> should

2 years agoinitialization misspell
whodi [Fri, 15 Apr 2022 19:00:44 +0000 (15:00 -0400)]
initialization misspell

2 years agoinfallible <> infalliable in filename
whodi [Fri, 15 Apr 2022 18:33:53 +0000 (14:33 -0400)]
infallible <> infalliable in filename

2 years agoadding spell checking
whodi [Fri, 15 Apr 2022 18:25:55 +0000 (14:25 -0400)]
adding spell checking

2 years agoFix formatting of `cast_abs_to_unsigned` docs
dlup [Fri, 15 Apr 2022 20:34:44 +0000 (16:34 -0400)]
Fix formatting of `cast_abs_to_unsigned` docs

2 years agoRollup merge of #94849 - ouz-a:master4, r=oli-obk
Dylan DPC [Fri, 15 Apr 2022 18:50:44 +0000 (20:50 +0200)]
Rollup merge of #94849 - ouz-a:master4, r=oli-obk

Check var scope if it exist

Fixes #92893.

Added helper function to check the scope of a variable, if it doesn't have a scope call delay_span_bug, which avoids us trying to get a block/scope that doesn't exist.

Had to increase `ROOT_ENTRY_LIMIT` was getting tidy error

2 years agoclippy: Update full path to `CString`
Vadim Petrochenkov [Fri, 15 Apr 2022 13:52:58 +0000 (16:52 +0300)]
clippy: Update full path to `CString`

2 years agoAuto merge of #8702 - youknowone:fix-typo, r=xFrednet
bors [Fri, 15 Apr 2022 10:38:47 +0000 (10:38 +0000)]
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

2 years agoFix typo in comment
Jeong YunWon [Fri, 15 Apr 2022 10:33:16 +0000 (19:33 +0900)]
Fix typo in comment

2 years agoAuto merge of #8563 - Jarcho:let_unit_1502, r=Jarcho
bors [Fri, 15 Apr 2022 01:57:52 +0000 (01:57 +0000)]
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

2 years agoAllow more complex expressions in `let_unit_value`
Jason Newcomb [Tue, 5 Apr 2022 01:54:34 +0000 (21:54 -0400)]
Allow more complex expressions in `let_unit_value`

2 years agoMove `let_unit_value` back into `style`
Jason Newcomb [Thu, 17 Mar 2022 23:53:28 +0000 (19:53 -0400)]
Move `let_unit_value` back into `style`

2 years agoDon't lint `let_unit_value` when needed for type inferenece
Jason Newcomb [Thu, 17 Mar 2022 23:44:12 +0000 (19:44 -0400)]
Don't lint `let_unit_value` when needed for type inferenece

2 years agoAuto merge of #8614 - pitaj:fix-7597, r=giraffate
bors [Thu, 14 Apr 2022 23:58:51 +0000 (23:58 +0000)]
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!`

2 years agoUpdate issue-92893.stderr
ouz-a [Thu, 14 Apr 2022 20:42:15 +0000 (23:42 +0300)]
Update issue-92893.stderr

2 years agoReimplement lowering of sym operands for asm! so that it also works with global_asm!
Amanieu d'Antras [Tue, 1 Mar 2022 00:50:56 +0000 (00:50 +0000)]
Reimplement lowering of sym operands for asm! so that it also works with global_asm!

2 years agoAuto merge of #8626 - pitaj:format_add_string, r=llogiq
bors [Thu, 14 Apr 2022 14:29:22 +0000 (14:29 +0000)]
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!`

2 years agoAuto merge of #8677 - xFrednet:8213-manual-bits-suggestion, r=giraffate
bors [Thu, 14 Apr 2022 12:59:23 +0000 (12:59 +0000)]
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

2 years agoAdd tests and docs
infrandomness [Tue, 12 Apr 2022 17:34:55 +0000 (19:34 +0200)]
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

2 years agoModify lint description
infrandomness [Mon, 11 Apr 2022 15:15:53 +0000 (17:15 +0200)]
Modify lint description

2 years agoIntroduce new lint check
infrandomness [Sun, 10 Apr 2022 21:42:33 +0000 (23:42 +0200)]
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

2 years agoSwap type checked expression
infrandomness [Sun, 10 Apr 2022 08:59:43 +0000 (10:59 +0200)]
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()`)

2 years agoDelete unused variable `y` in test
infrandomness [Sat, 9 Apr 2022 16:35:18 +0000 (18:35 +0200)]
Delete unused variable `y` in test

This fixes the errors occuring while running the ui tests

2 years agoSwap the category of the lint
infrandomness [Fri, 8 Apr 2022 19:59:59 +0000 (21:59 +0200)]
Swap the category of the lint

This changes the lint from the suspicious category to the complexity category

2 years agoSwap span_lint for span_lint_and_sugg
infrandomness [Fri, 8 Apr 2022 19:54:44 +0000 (21:54 +0200)]
Swap span_lint for span_lint_and_sugg

This implements a machine applicable suggestion to any matched usage of
`.as_ref().take()``

2 years agoImplement checks to the expression
infrandomness [Fri, 8 Apr 2022 19:27:01 +0000 (21:27 +0200)]
Implement checks to the expression

The implemented checks are for checking if the expression is either of
type `Option` and isn't a syntactical place

2 years agoIntroduce option_take_on_temporary lints
infrandomness [Fri, 8 Apr 2022 18:07:19 +0000 (20:07 +0200)]
Introduce option_take_on_temporary lints

This lint checks if Option::take() is used on a temporary value (a value
that is not of type &mut Option and that is not a Place expression) to
suggest omitting take()

2 years agoUpdate lint description of `clippy::manual_bits` to include the `as usize` cast
Fridtjof Stoldt [Thu, 14 Apr 2022 05:02:59 +0000 (07:02 +0200)]
Update lint description  of `clippy::manual_bits` to include the `as usize` cast

2 years agoNew lint `format_add_strings`
Peter Jaszkowiak [Mon, 4 Apr 2022 03:40:58 +0000 (21:40 -0600)]
New lint `format_add_strings`

2 years agoassertions_on_constants: ignore indirect `cfg!`
Peter Jaszkowiak [Fri, 1 Apr 2022 04:28:59 +0000 (22:28 -0600)]
assertions_on_constants: ignore indirect `cfg!`

2 years agoAuto merge of #8676 - Alexendoo:local-used-across-loop, r=xFrednet
bors [Thu, 14 Apr 2022 04:44:33 +0000 (04:44 +0000)]
Auto merge of #8676 - Alexendoo:local-used-across-loop, r=xFrednet

Check for loops/closures in `local_used_after_expr`

Follow up to #8646, catches when a local is used multiple times because it's in a loop or a closure

changelog: none

2 years agoAuto merge of #95968 - davidtwco:translation-lazy-fallback, r=oli-obk
bors [Wed, 13 Apr 2022 21:04:19 +0000 (21:04 +0000)]
Auto merge of #95968 - davidtwco:translation-lazy-fallback, r=oli-obk

errors: lazily load fallback fluent bundle

Addresses (hopefully) https://github.com/rust-lang/rust/pull/95667#issuecomment-1094794087.

Loading the fallback bundle in compilation sessions that won't go on to emit any errors unnecessarily degrades compile time performance, so lazily create the Fluent bundle when it is first required.

r? `@ghost` (just for perf initially)

2 years agoAdd `usize` cast to `clippy::manual_bits` suggestion
xFrednet [Sun, 10 Apr 2022 17:03:16 +0000 (19:03 +0200)]
Add `usize` cast to `clippy::manual_bits` suggestion

2 years agoAuto merge of #8670 - yoav-lavi:main, r=giraffate
bors [Wed, 13 Apr 2022 13:03:51 +0000 (13:03 +0000)]
Auto merge of #8670 - yoav-lavi:main, r=giraffate

`pub_use` restriction

[`pub_use`]

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

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

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

changelog: Adds a lint called `pub_use` that restricts the usage of `pub use ...`

2 years agopub_use
Yoav Lavi [Tue, 12 Apr 2022 09:09:34 +0000 (11:09 +0200)]
pub_use

2 years agoAuto merge of #94255 - b-naber:use-mir-constant-in-thir, r=oli-obk
bors [Wed, 13 Apr 2022 07:50:56 +0000 (07:50 +0000)]
Auto merge of #94255 - b-naber:use-mir-constant-in-thir, r=oli-obk

Use mir constant in thir instead of ty::Const

This is blocked on https://github.com/rust-lang/rust/pull/94059 (does include its changes, the first two commits in this PR correspond to those changes) and https://github.com/rust-lang/rust/pull/93800 being reinstated (which had to be reverted). Mainly opening since `@lcnr` offered to give some feedback and maybe also for a perf-run (if necessary).

This currently contains a lot of duplication since some of the logic of `ty::Const` had to be copied to `mir::ConstantKind`, but with the introduction of valtrees a lot of that functionality will disappear from `ty::Const`.

Only the last commit contains changes that need to be reviewed here. Did leave some `FIXME` comments regarding future implementation decisions and some things that might be incorrectly implemented.

r? `@oli-obk`

2 years agoerrors: lazily load fallback fluent bundle
David Wood [Tue, 12 Apr 2022 08:34:40 +0000 (09:34 +0100)]
errors: lazily load fallback fluent bundle

Loading the fallback bundle in compilation sessions that won't go on to
emit any errors unnecessarily degrades compile time performance, so
lazily create the Fluent bundle when it is first required.

Signed-off-by: David Wood <david.wood@huawei.com>
2 years agoAuto merge of #8692 - kyoto7250:fixing_unnecessary_to_owned, r=giraffate
bors [Wed, 13 Apr 2022 00:57:08 +0000 (00:57 +0000)]
Auto merge of #8692 - kyoto7250:fixing_unnecessary_to_owned, r=giraffate

fix unnecessary_to_owned about msrv

This PR fixes ``[`unnecessary_owned`]``.

## What

```rust
# sample code
fn _msrv_1_35() {
    #![clippy::msrv = "1.35"]
    let _ = &["x"][..].to_vec().into_iter();
}

fn _msrv_1_36() {
    #![clippy::msrv = "1.36"]
    let _ = &["x"][..].to_vec().into_iter();
}
```

If we will check this code using clippy, ``[`unnecessary_owned`]`` will modify the code as follows.

```rust
error: unnecessary use of `to_vec`
  --> $DIR/unnecessary_to_owned.rs:219:14
   |
LL |     let _ = &["x"][..].to_vec().into_iter();
   |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `["x"][..].iter().copied()`

error: unnecessary use of `to_vec`
  --> $DIR/unnecessary_to_owned.rs:224:14
   |
LL |     let _ = &["x"][..].to_vec().into_iter();
   |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `["x"][..].iter().copied()`
```

This is incorrect. Because `Iterator::copied` was estabilished in 1.36.

## Why

This bug was caused by not separating "copied" and "clone" by reference to msrv.

https://github.com/rust-lang/rust-clippy/blob/89ee6aa6e32df974ef9dbb3c825afbdce441e856/clippy_lints/src/methods/unnecessary_to_owned.rs#L195

So, I added a conditional branch and described the corresponding test.

Thank you in advance.

changelog: fix wrong suggestions about msrv in [`unnecessary_to_owned`]

r! `@giraffate`

2 years agoAuto merge of #8647 - Jarcho:mut_from_ref_6326, r=giraffate
bors [Wed, 13 Apr 2022 00:38:54 +0000 (00:38 +0000)]
Auto merge of #8647 - Jarcho:mut_from_ref_6326, r=giraffate

Only lint `mut_from_ref` when unsafe code is used

fixes #6326

changelog: Only lint `mut_from_ref` when unsafe code is used.

2 years agoAuto merge of #8645 - Jarcho:manual_non_exhaustive_5714, r=Jarcho
bors [Tue, 12 Apr 2022 18:38:45 +0000 (18:38 +0000)]
Auto merge of #8645 - Jarcho:manual_non_exhaustive_5714, r=Jarcho

Don't lint `manual_non_exhaustive` when the enum variant is used

fixes #5714

changelog: Don't lint `manual_non_exhaustive` when the enum variant is used

2 years agoAuto merge of #8690 - mucinoab:DoNot-rest_pat_in_fully_bound_structs-OnNonExhaustive...
bors [Tue, 12 Apr 2022 16:14:13 +0000 (16:14 +0000)]
Auto merge of #8690 - mucinoab:DoNot-rest_pat_in_fully_bound_structs-OnNonExhaustive, r=Manishearth

Do not trigger ``[`rest_pat_in_fully_bound_structs`]`` on `#[non_exhaustive]` structs

fixes #8029

Just adds an additional check to ensure that the`ty::VariantDef` is not marked as `#[non_exhaustive]`.

changelog: Do not apply ``[`rest_pat_in_fully_bound_structs`]`` on structs marked as non exhaustive.

2 years agofix unnecessary_to_owned about msrv
kyoto7250 [Tue, 12 Apr 2022 13:55:48 +0000 (22:55 +0900)]
fix unnecessary_to_owned about msrv

2 years agoAuto merge of #8691 - flip1995:infinite_recursion_only_in_recursion, r=llogiq
bors [Tue, 12 Apr 2022 13:33:54 +0000 (13:33 +0000)]
Auto merge of #8691 - flip1995:infinite_recursion_only_in_recursion, r=llogiq

Prevent infinite (exponential) recursion in only_used_in_recursion

This simplifies the visitor code a bit and prevents checking expressions
multiple times. I still think this lint should be removed for now,
because its code isn't really tested.

Fixes #8689

**NOTE:** Before merging this, we should talk about removing and revisiting this lint. See my comment in #8689

changelog: prevent infinite recursion in [`only_used_in_recursion`]

2 years agoPrevent infinite (exponential) recursion in only_used_in_recursion
flip1995 [Tue, 12 Apr 2022 13:27:28 +0000 (15:27 +0200)]
Prevent infinite (exponential) recursion in only_used_in_recursion

This simplifies the visitor code a bit and prevents checking expressions
multiple times. I still think this lint should be removed for now,
because its code isn't really tested.

2 years agoAuto merge of #8686 - Jarcho:undocumented_unsafe_blocks_8681, r=flip1995
bors [Tue, 12 Apr 2022 07:17:57 +0000 (07:17 +0000)]
Auto merge of #8686 - Jarcho:undocumented_unsafe_blocks_8681, r=flip1995

Fix ICE in `undocumented_unsafe_blocks`

fixes #8681

changelog: Fix ICE in `undocumented_unsafe_blocks`

2 years agoDo not apply `rest_pat_in_fully_bound_structs` on `#[non_exhaustive]` structs
Bruno A. Muciño [Tue, 12 Apr 2022 03:47:04 +0000 (22:47 -0500)]
Do not apply `rest_pat_in_fully_bound_structs` on `#[non_exhaustive]` structs

2 years agoAuto merge of #8688 - kyoto7250:adding_condition_for_map_clone, r=giraffate
bors [Tue, 12 Apr 2022 01:11:54 +0000 (01:11 +0000)]
Auto merge of #8688 - kyoto7250:adding_condition_for_map_clone, r=giraffate

adding condition for map_clone message

This PR fixes the message about `map_clone`.

if msrv >= 1.36, the message is correct.

```bash
$ cat main.rs
fn main() {
  let x: Vec<&i32> = vec![&1, &2];
  let y: Vec<_>  = x.iter().map(|i| *i).collect();
  println!("{:?}", y);
}

$ cargo clippy
warning: you are using an explicit closure for copying elements
 --> main.rs:3:20
  |
3 |   let y: Vec<_>  = x.iter().map(|i| *i).collect();
  |                    ^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `copied` method: `x.iter().copied()`
  |
  = note: `#[warn(clippy::map_clone)]` on by default
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#map_clone

warning: `test` (build script) generated 1 warning
warning: `test` (bin "test") generated 1 warning (1 duplicate)
    Finished dev [unoptimized + debuginfo] target(s) in 0.00s
```

but, if msrv < 1.36, the suggestion is `cloned`, but the message is `copying`.
```bash
$ cat clippy.toml
msrv = "1.35"

$ cargo clippy
warning: you are using an explicit closure for copying elements
 --> main.rs:3:20
  |
3 |   let y: Vec<_>  = x.iter().map(|i| *i).collect();
  |                    ^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `cloned` method: `x.iter().cloned()`
```

I think  the separation of messages will make it more user-friendly.

thank you in advance.

changelog: Fixed a message in map_clone.

2 years agorefactor: Put together an if statement
kyoto7250 [Tue, 12 Apr 2022 00:49:00 +0000 (09:49 +0900)]
refactor: Put together an if statement

2 years agoadding condition for map_clone message
kyoto7250 [Mon, 11 Apr 2022 19:03:48 +0000 (04:03 +0900)]
adding condition for map_clone message

if msrv < 1.36, the message tells , but the suggestion is

2 years agoAuto merge of #8624 - pitaj:is_digit_ascii_radix, r=xFrednet
bors [Mon, 11 Apr 2022 18:56:21 +0000 (18:56 +0000)]
Auto merge of #8624 - pitaj:is_digit_ascii_radix, r=xFrednet

New lint `is_digit_ascii_radix`

Closes #6399

changelog: Added [`is_digit_ascii_radix`]: recommend `is_ascii_digit()` or `is_ascii_hexdigit()` in place of `is_digit(10)` and `is_digit(16)`

2 years agoAuto merge of #8687 - Alexendoo:cast-possible-truncation-overflow, r=xFrednet
bors [Mon, 11 Apr 2022 18:40:14 +0000 (18:40 +0000)]
Auto merge of #8687 - Alexendoo:cast-possible-truncation-overflow, r=xFrednet

Fix subtraction overflow in `cast_possible_truncation`

changelog: Fix false negative due to subtraction overflow in `cast_possible_truncation`

I *think* a false negative is the worst that can happen from this

2 years agoFix subtraction overflow in `cast_possible_truncation`
Alex Macleod [Mon, 11 Apr 2022 17:54:44 +0000 (18:54 +0100)]
Fix subtraction overflow in `cast_possible_truncation`

2 years agoFix ICE in `undocumented_unsafe_blocks`
Jason Newcomb [Mon, 11 Apr 2022 17:18:27 +0000 (13:18 -0400)]
Fix ICE in `undocumented_unsafe_blocks`

2 years agoAuto merge of #8667 - Jarcho:proc_macro_check, r=flip1995
bors [Mon, 11 Apr 2022 16:41:51 +0000 (16:41 +0000)]
Auto merge of #8667 - Jarcho:proc_macro_check, r=flip1995

Don't lint various match lints when expanded by a proc-macro

fixes #4952

As always for proc-macro output this is a hack-job of a fix. It would be really nice if more proc-macro authors would set spans correctly.

changelog: Don't lint various lints on proc-macro output.

2 years agoAuto merge of #8673 - Jarcho:same_functions_8139, r=Manishearth
bors [Mon, 11 Apr 2022 15:36:55 +0000 (15:36 +0000)]
Auto merge of #8673 - Jarcho:same_functions_8139, r=Manishearth

Fix `same_functions_in_if_condition` FP

fixes #8139

changelog: Don't consider `Foo<{ SomeConstant }>` and `Foo<{ SomeOtherConstant }>` to be the same, even if the constants have the same value.

2 years agoAuto merge of #8668 - Jarcho:iter_with_drain_8538, r=Manishearth
bors [Mon, 11 Apr 2022 15:20:01 +0000 (15:20 +0000)]
Auto merge of #8668 - Jarcho:iter_with_drain_8538, r=Manishearth

Don't lint `iter_with_drain` on references

fixes #8538
changelog: Don't lint `iter_with_drain` on references

2 years agoAdd new `Deinit` statement kind
Jakob Degen [Tue, 5 Apr 2022 21:14:59 +0000 (17:14 -0400)]
Add new `Deinit` statement kind

2 years agoAuto merge of #8660 - yoav-lavi:squashed-master, r=flip1995
bors [Mon, 11 Apr 2022 11:12:33 +0000 (11:12 +0000)]
Auto merge of #8660 - yoav-lavi:squashed-master, r=flip1995

`unnecessary_owned_empty_strings`

[`unnecessary_owned_empty_strings`]

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

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

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

changelog: Adds `unnecessary_owned_empty_strings`, a lint that detects passing owned empty strings to a function expecting `&str`

2 years agounnecessary_owned_empty_string -> unnecessary_owned_empty_strings
Yoav Lavi [Mon, 11 Apr 2022 11:05:42 +0000 (13:05 +0200)]
unnecessary_owned_empty_string -> unnecessary_owned_empty_strings

2 years agounnecessary_string_new
Yoav Lavi [Thu, 7 Apr 2022 18:21:47 +0000 (20:21 +0200)]
unnecessary_string_new

2 years agoAuto merge of #8671 - andy-k:fix-typo, r=flip1995
bors [Mon, 11 Apr 2022 09:22:37 +0000 (09:22 +0000)]
Auto merge of #8671 - andy-k:fix-typo, r=flip1995

fix typo

fix typo in #8630

changelog: none

2 years agoAuto merge of #8631 - Alexendoo:splitn-overlap, r=xFrednet
bors [Sun, 10 Apr 2022 17:45:19 +0000 (17:45 +0000)]
Auto merge of #8631 - Alexendoo:splitn-overlap, r=xFrednet

Remove overlap between `manual_split_once` and `needless_splitn`

changelog: Remove overlap between [`manual_split_once`] and [`needless_splitn`]. Fixes some incorrect `rsplitn` suggestions for [`manual_split_once`]

Things that can trigger `needless_splitn` no longer trigger `manual_split_once`, e.g.

```rust
s.[r]splitn(2, '=').next();
s.[r]splitn(2, '=').nth(0);
s.[r]splitn(3, '=').next_tuple();
```

Fixes some suggestions:

```rust
let s = "should not match";

s.rsplitn(2, '.').nth(1);
// old -> Some("should not match")
Some(s.rsplit_once('.').map_or(s, |x| x.0));
// new -> None
s.rsplit_once('.').map(|x| x.0);

s.rsplitn(2, '.').nth(1)?;
// old -> "should not match"
s.rsplit_once('.').map_or(s, |x| x.0);
// new -> early returns
s.rsplit_once('.')?.0;
```

2 years agoRemove overlap between `manual_split_once` and `needless_splitn`
Alex Macleod [Mon, 4 Apr 2022 15:30:38 +0000 (16:30 +0100)]
Remove overlap between `manual_split_once` and `needless_splitn`

Also fixes some incorrect suggestions for rsplitn

2 years agoCheck for loops/closures in `local_used_after_expr`
Alex Macleod [Sun, 10 Apr 2022 13:02:58 +0000 (14:02 +0100)]
Check for loops/closures in `local_used_after_expr`