]>
git.lizzy.rs Git - rust.git/log
Alex Macleod [Sat, 23 Apr 2022 11:23:18 +0000 (12:23 +0100)]
ignore `redundant_pub_crate` in `useless_attribute`
bors [Fri, 22 Apr 2022 17:11:53 +0000 (17:11 +0000)]
Auto merge of #8731 - Alexendoo:dogfood-allow-unknown-lints, r=xFrednet
dogfood: allow unknown lints when not running with `internal` feature
changelog: none
https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/unknown.20lint.20in.20test.20dogfood_clippy
It's only a warning so this wasn't causing the test to fail, but if you had another error somewhere or used `--nocapture` the extra warnings would be shown
Alex Macleod [Fri, 22 Apr 2022 12:05:53 +0000 (13:05 +0100)]
dogfood: allow unknown lints when not running with `internal` feature
bors [Fri, 22 Apr 2022 09:57:00 +0000 (09:57 +0000)]
Auto merge of #8717 - Alexendoo:manual-split-once-manual-iter, r=dswij,xFrednet
`manual_split_once`: lint manual iteration of `SplitN`
changelog: `manual_split_once`: lint manual iteration of `SplitN`
Now lints:
```rust
let mut iter = "a.b.c".splitn(2, '.');
let first = iter.next().unwrap();
let second = iter.next().unwrap();
let mut iter = "a.b.c".splitn(2, '.');
let first = iter.next()?;
let second = iter.next()?;
let mut iter = "a.b.c".rsplitn(2, '.');
let first = iter.next().unwrap();
let second = iter.next().unwrap();
let mut iter = "a.b.c".rsplitn(2, '.');
let first = iter.next()?;
let second = iter.next()?;
```
It suggests (minus leftover whitespace):
```rust
let (first, second) = "a.b.c".split_once('.').unwrap();
let (first, second) = "a.b.c".split_once('.')?;
let (second, first) = "a.b.c".rsplit_once('.').unwrap();
let (second, first) = "a.b.c".rsplit_once('.')?;
```
Currently only lints if the statements are next to each other, as detecting the various kinds of shadowing was tricky, so the following won't lint
```rust
let mut iter = "a.b.c".splitn(2, '.');
let something_else = 1;
let first = iter.next()?;
let second = iter.next()?;
```
bors [Thu, 21 Apr 2022 18:05:14 +0000 (18:05 +0000)]
Auto merge of #8729 - Serial-ATA:issue-7318, r=Manishearth
Fix missing whitespace in `collapsible_else_if` suggestion
changelog: Fix missing whitespace in [`collapsible_else_if`] suggestion
closes #7318
Serial [Thu, 21 Apr 2022 17:42:55 +0000 (13:42 -0400)]
Fix missing whitespace in `collapsible_else_if` suggestion
Alex Macleod [Mon, 18 Apr 2022 12:28:23 +0000 (13:28 +0100)]
`manual_split_once`: lint manual iteration of `SplitN`
bors [Thu, 21 Apr 2022 08:03:31 +0000 (08:03 +0000)]
Auto merge of #8571 - PyroTechniac:empty-drop, r=flip1995
add `empty_drop`
Closes #8352
changelog: New lint [`empty_drop`]
Gryffon Bellish [Fri, 25 Mar 2022 19:31:52 +0000 (15:31 -0400)]
Add empty_drop lint
bors [Thu, 21 Apr 2022 00:27:13 +0000 (00:27 +0000)]
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`
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.
bing [Wed, 20 Apr 2022 15:11:54 +0000 (23:11 +0800)]
Better documentation wording and add known problems section
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()`
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
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
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.
Lily Mara [Mon, 18 Apr 2022 18:32:28 +0000 (11:32 -0700)]
fixup! 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
Lily Mara [Mon, 18 Apr 2022 18:16:35 +0000 (11:16 -0700)]
fixup! 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
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>
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>
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>
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
bing [Mon, 18 Apr 2022 06:48:34 +0000 (14:48 +0800)]
Update lints
bing [Mon, 18 Apr 2022 06:42:24 +0000 (14:42 +0800)]
Less authoritative stable_sort_primitive message
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
xFrednet [Fri, 15 Apr 2022 09:37:58 +0000 (11:37 +0200)]
Add `#[clippy::print_hir]` attribute for debugging
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
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
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
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
xFrednet [Wed, 13 Apr 2022 21:14:35 +0000 (23:14 +0200)]
Changelog for Rust 1.61 :octopus:
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(?)
Lily Mara [Fri, 15 Apr 2022 21:54:19 +0000 (14:54 -0700)]
fixup! 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
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.
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.
whodi [Fri, 15 Apr 2022 19:28:48 +0000 (15:28 -0400)]
collapsible <> collspible
whodi [Fri, 15 Apr 2022 19:20:54 +0000 (15:20 -0400)]
shound -> should
whodi [Fri, 15 Apr 2022 19:00:44 +0000 (15:00 -0400)]
initialization misspell
whodi [Fri, 15 Apr 2022 18:33:53 +0000 (14:33 -0400)]
infallible <> infalliable in filename
whodi [Fri, 15 Apr 2022 18:25:55 +0000 (14:25 -0400)]
adding spell checking
dlup [Fri, 15 Apr 2022 20:34:44 +0000 (16:34 -0400)]
Fix formatting of `cast_abs_to_unsigned` docs
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
Jeong YunWon [Fri, 15 Apr 2022 10:33:16 +0000 (19:33 +0900)]
Fix typo in comment
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
Jason Newcomb [Tue, 5 Apr 2022 01:54:34 +0000 (21:54 -0400)]
Allow more complex expressions in `let_unit_value`
Jason Newcomb [Thu, 17 Mar 2022 23:53:28 +0000 (19:53 -0400)]
Move `let_unit_value` back into `style`
Jason Newcomb [Thu, 17 Mar 2022 23:44:12 +0000 (19:44 -0400)]
Don't lint `let_unit_value` when needed for type inferenece
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!`
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!`
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
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
infrandomness [Mon, 11 Apr 2022 15:15:53 +0000 (17:15 +0200)]
Modify lint description
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
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()`)
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
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
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()``
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
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()
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
Peter Jaszkowiak [Mon, 4 Apr 2022 03:40:58 +0000 (21:40 -0600)]
New lint `format_add_strings`
Peter Jaszkowiak [Fri, 1 Apr 2022 04:28:59 +0000 (22:28 -0600)]
assertions_on_constants: ignore indirect `cfg!`
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
xFrednet [Sun, 10 Apr 2022 17:03:16 +0000 (19:03 +0200)]
Add `usize` cast to `clippy::manual_bits` suggestion
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 ...`
Yoav Lavi [Tue, 12 Apr 2022 09:09:34 +0000 (11:09 +0200)]
pub_use
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`
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.
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
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.
kyoto7250 [Tue, 12 Apr 2022 13:55:48 +0000 (22:55 +0900)]
fix unnecessary_to_owned about msrv
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`]
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.
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`
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
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.
kyoto7250 [Tue, 12 Apr 2022 00:49:00 +0000 (09:49 +0900)]
refactor: Put together an if statement
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
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)`
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
Alex Macleod [Mon, 11 Apr 2022 17:54:44 +0000 (18:54 +0100)]
Fix subtraction overflow in `cast_possible_truncation`
Jason Newcomb [Mon, 11 Apr 2022 17:18:27 +0000 (13:18 -0400)]
Fix ICE in `undocumented_unsafe_blocks`
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.
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.
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
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`
Yoav Lavi [Mon, 11 Apr 2022 11:05:42 +0000 (13:05 +0200)]
unnecessary_owned_empty_string -> unnecessary_owned_empty_strings
Yoav Lavi [Thu, 7 Apr 2022 18:21:47 +0000 (20:21 +0200)]
unnecessary_string_new
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
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;
```
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
Alex Macleod [Sun, 10 Apr 2022 13:02:58 +0000 (14:02 +0100)]
Check for loops/closures in `local_used_after_expr`
Jason Newcomb [Sun, 10 Apr 2022 04:54:41 +0000 (00:54 -0400)]
Compare inline constants by their bodies rather than value in `SpanlessEq`
Andy Kurnia [Sat, 9 Apr 2022 17:07:01 +0000 (01:07 +0800)]
fix typo
bors [Sat, 9 Apr 2022 14:57:06 +0000 (14:57 +0000)]
Auto merge of #8664 - yoav-lavi:main, r=xFrednet
Allow passing `--remove` to `cargo dev setup <SUBCOMMAND>`
changelog: none
Allows passing `--remove` to `cargo dev setup <SUBCOMMAND>` as an alternative to `cargo dev remove ...`
Fixes https://github.com/rust-lang/rust-clippy/issues/8663
Yoav Lavi [Fri, 8 Apr 2022 13:02:49 +0000 (15:02 +0200)]
Allow passing --remove to `cargo dev setup <SUBCOMMAND>`
add missing args
unque name not needed
more descriptive help
formatting fixes
missing quote
bors [Sat, 9 Apr 2022 11:58:18 +0000 (11:58 +0000)]
Auto merge of #8669 - kyoto7250:fix_comments_in_test_split_once, r=xFrednet
fix comments in test for split_once
This PR fixed comments in test.
`split_once` was stabilized in 1.52, so I think the comments maybe be wrong.
ref:
https://doc.rust-lang.org/std/string/struct.String.html#method.split_once
thank you in advance.
changelog: none