]> git.lizzy.rs Git - rust.git/log
rust.git
2 years agoIgnore associated items in trait *implementations* when considering type complexity
Maybe Waffle [Wed, 8 Dec 2021 11:27:49 +0000 (14:27 +0300)]
Ignore associated items in trait *implementations* when considering type complexity

2 years agoUpdate tests for type_complexity lint
Maybe Waffle [Thu, 25 Nov 2021 09:47:29 +0000 (12:47 +0300)]
Update tests for type_complexity lint

2 years agoIgnore associated types in traits when considering type complexity
Maybe Waffle [Thu, 25 Nov 2021 08:50:57 +0000 (11:50 +0300)]
Ignore associated types in traits when considering type complexity

2 years agoAuto merge of #8028 - dswij:8016, r=flip1995
bors [Thu, 25 Nov 2021 08:10:55 +0000 (08:10 +0000)]
Auto merge of #8028 - dswij:8016, r=flip1995

Add more descriptive help info for `needless_question_mark`

closes #8016

changelog: [`needless_question_mark`] help suggestion now explains what should be changed

2 years agoAdd more descriptive help info for `needless_question_mark`
Dharma Saputra Wijaya [Thu, 25 Nov 2021 01:10:50 +0000 (09:10 +0800)]
Add more descriptive help info for `needless_question_mark`

2 years agoAuto merge of #8025 - flip1995:rustup, r=flip1995
bors [Tue, 23 Nov 2021 10:27:12 +0000 (10:27 +0000)]
Auto merge of #8025 - flip1995:rustup, r=flip1995

Rustup

Re-sync, because I didn't get to syncing things back to rustc.

r? `@ghost`

changelog: none

2 years agoBump nightly version -> 2021-11-23
flip1995 [Tue, 23 Nov 2021 10:22:49 +0000 (11:22 +0100)]
Bump nightly version -> 2021-11-23

2 years agoMerge remote-tracking branch 'upstream/master' into rustup
flip1995 [Tue, 23 Nov 2021 10:22:34 +0000 (11:22 +0100)]
Merge remote-tracking branch 'upstream/master' into rustup

2 years agoAuto merge of #7980 - dswij:7870, r=xFrednet
bors [Tue, 23 Nov 2021 08:20:57 +0000 (08:20 +0000)]
Auto merge of #7980 - dswij:7870, r=xFrednet

Fix FP on `if_then_some_else_none` when there is early return

closes #7870

changelog: [`if_then_some_else_none`] now does not fire when there is early return

2 years agoFix FP on `if_then_some_else_none` when there is early return
dswij [Tue, 16 Nov 2021 05:39:52 +0000 (13:39 +0800)]
Fix FP on `if_then_some_else_none` when there is early return

2 years agoAuto merge of #8007 - birkenfeld:octal_escapes, r=xFrednet
bors [Mon, 22 Nov 2021 20:29:53 +0000 (20:29 +0000)]
Auto merge of #8007 - birkenfeld:octal_escapes, r=xFrednet

Add new lint `octal_escapes`

This checks for sequences in strings that would be octal character
escapes in C, but are not supported in Rust.  It suggests either
to use the `\x00` escape, or an equivalent hex escape if the octal
was intended.

Fixes #7981

---

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

changelog: Add new lint [`octal_escapes`], which checks for literals like `"\033[0m"`.

2 years agooctal_escapes: note on print!() format strings
Georg Brandl [Mon, 22 Nov 2021 20:02:03 +0000 (21:02 +0100)]
octal_escapes: note on print!() format strings

2 years agooctal_escapes: emit only one lint for all cases found each literal
Georg Brandl [Mon, 22 Nov 2021 17:18:16 +0000 (18:18 +0100)]
octal_escapes: emit only one lint for all cases found each literal

2 years ago`octal_escapes`: updates from review, fix byte string prefix
Georg Brandl [Sun, 21 Nov 2021 15:06:19 +0000 (16:06 +0100)]
`octal_escapes`: updates from review, fix byte string prefix

2 years agoAuto merge of #7989 - couchand:2021-11/toolchain-missing-components, r=flip1995
bors [Mon, 22 Nov 2021 09:48:06 +0000 (09:48 +0000)]
Auto merge of #7989 - couchand:2021-11/toolchain-missing-components, r=flip1995

Add missing components to rust-toolchain file

Somehow these basic components are missing from the toolchain file...

changelog: none

2 years agoAuto merge of #8009 - xFrednet:8004-suboptimal-flops-in-const, r=giraffate
bors [Mon, 22 Nov 2021 00:01:49 +0000 (00:01 +0000)]
Auto merge of #8009 - xFrednet:8004-suboptimal-flops-in-const, r=giraffate

Allow `suboptimal_flops` in const functions

This PR allows `clippy::suboptimal_flops` in constant functions. The check also effects the `clippy::imprecise_flops` lint logic. However, this doesn't have any effects as all functions checked for are not const and can therefore not be found in such functions.

---

changelog: [`suboptimal_flops`]: No longer triggers in constant functions

Closes: rust-lang/rust-clippy#8004
2 years agoAuto merge of #7997 - surechen:Fixes_7915, r=giraffate
bors [Sun, 21 Nov 2021 23:48:24 +0000 (23:48 +0000)]
Auto merge of #7997 - surechen:Fixes_7915, r=giraffate

Fixes shadow_same's false positive for #7915

Fix shadow_same's false positive for async function's params(Fixes #7915):

Example Code:
```rust
#![deny(clippy::shadow_same)]

pub async fn foo(_a: i32) {
}
```
Output:
```
error: `_a` is shadowed by itself in `_a
```

Hir:
```rust
pub async fn foo(_a: i32)
 ->
     /*impl Trait*/ #[lang = "from_generator"](move |mut _task_context|
                                                   {
                                                       let _a = _a;
                                                       { let _t = { }; _t }
                                                   })
```

Skip checking async function's params.

changelog: Fix shadow_same's false positive for async function's params

2 years agoclippy: Fix pattern_type_mismatch for loop
Cameron Steffen [Fri, 19 Nov 2021 18:23:52 +0000 (12:23 -0600)]
clippy: Fix pattern_type_mismatch for loop

2 years agoFix Clippy with changed for loop desugar
Cameron Steffen [Wed, 27 Oct 2021 14:48:06 +0000 (09:48 -0500)]
Fix Clippy with changed for loop desugar

2 years agoFixes #7915
surechen [Fri, 19 Nov 2021 08:46:34 +0000 (16:46 +0800)]
Fixes #7915

Fix shadow_same's positive false for async function's params:

Example Code:
```rust
#![deny(clippy::shadow_same)]

pub async fn foo(_a: i32) {
}
```
Output:
```
error: `_a` is shadowed by itself in `_a
```

Hir:
```rust
pub async fn foo(_a: i32)
 ->
     /*impl Trait*/ #[lang = "from_generator"](move |mut _task_context|
                                                   {
                                                       let _a = _a;
                                                       { let _t = { }; _t }
                                                   })
```

Skip checking async function's params.

changelog: Fix shadow_same's positive false for async function's params

2 years agoAuto merge of #8011 - birkenfeld:double_backticks, r=xFrednet
bors [Sat, 20 Nov 2021 17:50:50 +0000 (17:50 +0000)]
Auto merge of #8011 - birkenfeld:double_backticks, r=xFrednet

Avoid inline hints with double backticks for `doc-markdown`

The easiest route here was to ensure that the suggestion is always shown on
its own line, where no additional backticks are added by the diagnostic formatter.

Fixes #8002

---

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

changelog: Avoid inline hints with double backticks for `doc-markdown`

2 years agoAvoid inline hints with double backticks for `doc-markdown`
Georg Brandl [Sat, 20 Nov 2021 17:13:24 +0000 (18:13 +0100)]
Avoid inline hints with double backticks for `doc-markdown`

2 years agoAllow `suboptimal_flops` in const functions
xFrednet [Sat, 20 Nov 2021 14:04:08 +0000 (15:04 +0100)]
Allow `suboptimal_flops` in const functions

2 years agoAuto merge of #8000 - Jarcho:nightly_fmt, r=llogiq
bors [Sat, 20 Nov 2021 14:06:17 +0000 (14:06 +0000)]
Auto merge of #8000 - Jarcho:nightly_fmt, r=llogiq

Don't check for a nightly toolchain in fmt test

changelog: None

2 years agoAdd new lint `octal_escapes`
Georg Brandl [Sat, 20 Nov 2021 10:23:49 +0000 (11:23 +0100)]
Add new lint `octal_escapes`

This checks for sequences in strings that would be octal character
escapes in C, but are not supported in Rust.  It suggests either
to use the `\x00` escape, or an equivalent hex escape if the octal
was intended.

2 years agoDon't check for a nightly toolchain in fmt test
Jason Newcomb [Sat, 20 Nov 2021 00:43:31 +0000 (19:43 -0500)]
Don't check for a nightly toolchain in fmt test

2 years agoAuto merge of #7984 - phansch:disallowed-type-rename, r=xFrednet
bors [Fri, 19 Nov 2021 13:39:08 +0000 (13:39 +0000)]
Auto merge of #7984 - phansch:disallowed-type-rename, r=xFrednet

Pluralize `disallowed_type` lint

This was brought up in [Zulip] and is also mentioned in the lint naming
conventions. Since this is still a nursery lint, I think there shouldn't
be any problem in renaming it.

[Zulip]: rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/disallow_type.20vs.20disallowed-types

changelog: Rename nursery lint [`disallowed_type`] to [`disallowed_types`].

2 years agoAuto merge of #7996 - togami2864:test-map-or-none, r=Manishearth
bors [Fri, 19 Nov 2021 07:47:39 +0000 (07:47 +0000)]
Auto merge of #7996 - togami2864:test-map-or-none, r=Manishearth

Add test case for RESULT_MAP_OR_INTO_OPTION

just added test case for RESULT_MAP_OR_INTO_OPTION.
changelog: none

2 years agofix stderr
togami2864 [Fri, 19 Nov 2021 07:17:17 +0000 (16:17 +0900)]
fix stderr

2 years agoadd test case for result_map_or_into_option
togami2864 [Fri, 19 Nov 2021 07:12:46 +0000 (16:12 +0900)]
add test case for result_map_or_into_option

2 years agoAuto merge of #7977 - Jarcho:multi_needless_borrow, r=xFrednet
bors [Thu, 18 Nov 2021 23:35:03 +0000 (23:35 +0000)]
Auto merge of #7977 - Jarcho:multi_needless_borrow, r=xFrednet

Improve `needless_borrow` lint

fixes: #5327
fixes: #1726
fixes: #1212

This is merging `needless_borrow` into the `dereference` pass in preparation for `explicit_auto_deref`. `explicit_auto_deref` needs to implement most of what `needless_borrow` implements in order to work.

There is a minor regression here where `let x: &str = &x.deref()` will trigger `needless_borrow` without triggering `explicit_deref_methods`. Removing the redundant borrow will cause `explicit_deref_methods` to trigger. This will be fixed when `explicit_auto_deref` is implemented.

changelog: Lint `needless_borrow` when a borrow is auto-derefed more than once
changelog: Lint `needless_borrow` in the trailing expression of a block for a match arm

2 years agoAdd missing components to rust-toolchain file
Andrew Dona-Couch [Wed, 17 Nov 2021 15:20:12 +0000 (10:20 -0500)]
Add missing components to rust-toolchain file

2 years agoAlso pluralize disallowed_method(s) lint
flip1995 [Thu, 18 Nov 2021 13:08:48 +0000 (14:08 +0100)]
Also pluralize disallowed_method(s) lint

To stay consistent with the sister lint disallowed_type, also rename the
disallowed_method lint to disallowed_methods.

2 years agoPluralize disallowed_type lint filenames
Philipp Hansch [Wed, 17 Nov 2021 06:47:43 +0000 (07:47 +0100)]
Pluralize disallowed_type lint filenames

This way they match up with the pluralized lint name as well.

2 years agoPluralize disallowed_type lint
Philipp Hansch [Wed, 17 Nov 2021 06:39:21 +0000 (07:39 +0100)]
Pluralize disallowed_type lint

This was brought up in [Zulip] and is also mentioned in the lint naming
conventions. Since this is still a nursery lint, I think there shouldn't
be any problem in renaming it.

[Zulip]: https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/disallow_type.20vs.20disallowed-types

2 years agoAuto merge of #7994 - flip1995:rustup, r=flip1995
bors [Thu, 18 Nov 2021 11:31:49 +0000 (11:31 +0000)]
Auto merge of #7994 - flip1995:rustup, r=flip1995

Rustup

r? `@ghost`

changelog: none

2 years agoBump nightly version -> 2021-11-18
flip1995 [Thu, 18 Nov 2021 11:22:22 +0000 (12:22 +0100)]
Bump nightly version -> 2021-11-18

2 years agoMerge remote-tracking branch 'upstream/master' into rustup
flip1995 [Thu, 18 Nov 2021 11:22:00 +0000 (12:22 +0100)]
Merge remote-tracking branch 'upstream/master' into rustup

2 years agoAuto merge of #7992 - togami2864:fix-typo, r=giraffate
bors [Thu, 18 Nov 2021 08:46:52 +0000 (08:46 +0000)]
Auto merge of #7992 - togami2864:fix-typo, r=giraffate

fix typo

just fixed typo

changelog: none

2 years agofix typo
togami2864 [Thu, 18 Nov 2021 08:37:00 +0000 (17:37 +0900)]
fix typo

2 years agorustc: Remove `#[rustc_synthetic]`
Vadim Petrochenkov [Thu, 18 Nov 2021 05:25:27 +0000 (13:25 +0800)]
rustc: Remove `#[rustc_synthetic]`

This function parameter attribute was introduced in https://github.com/rust-lang/rust/pull/44866 as an intermediate step in implementing `impl Trait`, it's not necessary or used anywhere by itself.

2 years agoAuto merge of #7968 - Jarcho:manual_map_unsafe, r=xFrednet
bors [Wed, 17 Nov 2021 16:20:04 +0000 (16:20 +0000)]
Auto merge of #7968 - Jarcho:manual_map_unsafe, r=xFrednet

Fix `manual_map` with unsafe functions

fixes: #7820
changelog: Fix `manual_map` suggestion when used with unsafe functions and unsafe blocks

2 years agoAuto merge of #7971 - togami2864:fix/option-map-or-none, r=llogiq
bors [Wed, 17 Nov 2021 16:01:55 +0000 (16:01 +0000)]
Auto merge of #7971 - togami2864:fix/option-map-or-none, r=llogiq

fix suggestion in option_map_or_none

fix: #7960
changelog: change suggestion in the lint rule `option_map_or_none`

2 years agofix suggestion message
togami2864 [Wed, 17 Nov 2021 15:43:49 +0000 (00:43 +0900)]
fix suggestion message

2 years agoAddition `manual_map` test for `unsafe` blocks
Jason Newcomb [Wed, 17 Nov 2021 15:39:53 +0000 (10:39 -0500)]
Addition `manual_map` test for `unsafe` blocks

2 years agoMinor simplification to `manual_map`
Jason Newcomb [Wed, 17 Nov 2021 15:36:13 +0000 (10:36 -0500)]
Minor simplification to `manual_map`

2 years agocheck whether stmts is empty or not in block
togami2864 [Wed, 17 Nov 2021 15:36:11 +0000 (00:36 +0900)]
check whether stmts is empty or not in block

2 years agoAuto merge of #7988 - giraffate:fix_ice_on_undocumented_unsafe_blocks, r=flip1995
bors [Wed, 17 Nov 2021 15:24:07 +0000 (15:24 +0000)]
Auto merge of #7988 - giraffate:fix_ice_on_undocumented_unsafe_blocks, r=flip1995

Fix ICE on `undocumented_unsafe_blocks`

fix https://github.com/rust-lang/rust-clippy/issues/7979

changelog: Fix ICE on `undocumented_unsafe_blocks`

2 years agoadd multi-line test case
togami2864 [Wed, 17 Nov 2021 15:13:55 +0000 (00:13 +0900)]
add multi-line test case

2 years agoAuto merge of #7898 - F3real:unit_struct, r=camsteffen
bors [Wed, 17 Nov 2021 14:09:51 +0000 (14:09 +0000)]
Auto merge of #7898 - F3real:unit_struct, r=camsteffen

Don't show no_effect warning on unit structs implementing fn_once

Fixes #7792

changelog: Don't show [`no_effect`] or [`unecessary_operation`] warning for unit struct implementing FnOnce

2 years agoFix ICE on `undocumented_unsafe_blocks`
Takayuki Nakata [Wed, 17 Nov 2021 13:35:01 +0000 (22:35 +0900)]
Fix ICE on `undocumented_unsafe_blocks`

2 years agoAuto merge of #7896 - surechen:fix_manual_split_once, r=camsteffen
bors [Wed, 17 Nov 2021 01:46:58 +0000 (01:46 +0000)]
Auto merge of #7896 - surechen:fix_manual_split_once, r=camsteffen

Fix for #7889 and add new lint needless_splitn

fixes: #7889
1. Fix the problem of manual_split_once changing the original behavior.
2. Add a new lint needless_splitn.

changelog: Fix the problem of manual_split_once changing the original behavior and add a new lint needless_splitn.

2 years agofixes: #7889
surechen [Fri, 29 Oct 2021 03:32:37 +0000 (11:32 +0800)]
fixes: #7889

1. Fix the problem of manual_split_once changing the original behavior.
2. Add a new lint needless_splitn.

changelog: Fix the problem of manual_split_once changing the original behavior and add a new lint needless_splitn.

2 years agoDon't show no_effect warning on unit structs implementing fn* traits
F3real [Tue, 16 Nov 2021 23:50:07 +0000 (00:50 +0100)]
Don't show no_effect warning on unit structs implementing fn* traits

2 years agoAuto merge of #7982 - Blckbrry-Pi:master, r=llogiq
bors [Tue, 16 Nov 2021 23:01:02 +0000 (23:01 +0000)]
Auto merge of #7982 - Blckbrry-Pi:master, r=llogiq

Fix `needless_collect`'s tendency to suggest code requiring multiple mutable borrows of the same value.

Fixes error specified in #7975.

changelog: [`needless_collect`] no longer suggests removal of `collect` when removal would create code requiring mutably borrowing a value multiple times.

2 years agoFix readability suggestions.
Skyler Calaman [Tue, 16 Nov 2021 16:29:26 +0000 (11:29 -0500)]
Fix readability suggestions.

1. Make the lifetime contained in LateContext `'tcx`.
2. Fix `'txc` to `'tcx` because it was a typo.
3. Refactor `IterFunctionVisitor`'s `visit_block` method to be more readable.
4. Replace uses of `rustc_middle::ty::TyKind` with `rustc::middle::ty`, and remove the `#[allow(...)]`.

(Thank you llogiq for all these suggestions!)

2 years agoSuccessfully generalize prevention of suggestions causing multiple mutable borrows.
Skyler Calaman [Tue, 16 Nov 2021 14:18:49 +0000 (09:18 -0500)]
Successfully generalize prevention of suggestions causing multiple mutable borrows.

Also add some more tests to check that it's working.

2 years agoresolve CI
togami2864 [Tue, 16 Nov 2021 14:07:19 +0000 (23:07 +0900)]
resolve CI

2 years agoAuto merge of #7639 - Jarcho:whitelist_cheap_functions, r=camsteffen
bors [Tue, 16 Nov 2021 03:12:30 +0000 (03:12 +0000)]
Auto merge of #7639 - Jarcho:whitelist_cheap_functions, r=camsteffen

Improve heuristic for eagerness suggestion

Still to be done:

* a more complete list of cheap functions
* a way to limit the complexity of cheap expressions

changelog: Improve heuristics for `or_fun_call` and `unnecessary_lazy_evaluations`

2 years agoImprove heuristics for determining whether eager of lazy evaluation is preferred
Jason Newcomb [Tue, 17 Aug 2021 20:22:48 +0000 (16:22 -0400)]
Improve heuristics for determining whether eager of lazy evaluation is preferred

2 years agoImprove `needless_borrow` lint.
Jason Newcomb [Mon, 15 Nov 2021 16:58:25 +0000 (11:58 -0500)]
Improve `needless_borrow` lint.

* Lint when a borrow is auto dereferenced more than once
* Lint when the expression is used as the expression of a block for a match arm

Moves `needless_borrow` and `ref_binding_to_reference` to `dereference`
lint pass in preperation for `explicit_auto_deref` lint.

2 years agomove the let statement out of the macro
togami2864 [Mon, 15 Nov 2021 18:02:08 +0000 (03:02 +0900)]
move the let statement out of the macro

2 years agofix fmt
togami2864 [Mon, 15 Nov 2021 17:53:35 +0000 (02:53 +0900)]
fix fmt

2 years agoadd comment
togami2864 [Mon, 15 Nov 2021 17:30:54 +0000 (02:30 +0900)]
add comment

2 years agofix a bug that the closure arguments are not displayed
togami2864 [Mon, 15 Nov 2021 17:29:02 +0000 (02:29 +0900)]
fix a bug that the closure arguments are not displayed

2 years agoadd reduce_unit_expression
togami2864 [Mon, 15 Nov 2021 17:06:31 +0000 (02:06 +0900)]
add reduce_unit_expression

2 years agoAuto merge of #7974 - matthiaskrgr:7973_opt_map_or_else_dont_expand_sugg_macro, r...
bors [Mon, 15 Nov 2021 10:27:29 +0000 (10:27 +0000)]
Auto merge of #7974 - matthiaskrgr:7973_opt_map_or_else_dont_expand_sugg_macro, r=flip1995

option_if_let_else: don't expand macros in suggestion

Fixes #7973

changelog: don't expand macros in suggestion of clippy::option_if_let_else

2 years agoadd test case for option_map_or_none
togami2864 [Mon, 15 Nov 2021 06:47:57 +0000 (15:47 +0900)]
add test case for option_map_or_none

2 years agoAuto merge of #7957 - surechen:fix_for_7854, r=giraffate
bors [Mon, 15 Nov 2021 00:50:28 +0000 (00:50 +0000)]
Auto merge of #7957 - surechen:fix_for_7854, r=giraffate

Support suggestion for #7854

I think the detection of parking_lot's mutex and rwlock is valuable, so submit this pr, please help judge and review, thank you.

Make let_underscore_lock support parking_lot.(Fixes #7854)

changelog: Make let_underscore_lock support parking_lot

2 years agoSupport suggestion for #7854
surechen [Thu, 11 Nov 2021 01:59:31 +0000 (09:59 +0800)]
Support suggestion for #7854

I think the detection of parking_lot's mutex and rwlock is valuable, so submit this pr, please help judge and review, thank you.

Make let_underscore_lock support parking_lot.

changelog: Make let_underscore_lock support parking_lot

2 years agoFix specific code outlined in issue #7975.
Skyler Calaman [Sun, 14 Nov 2021 23:18:43 +0000 (18:18 -0500)]
Fix specific code outlined in issue #7975.

Still needs to generalize to other mixes of let bindings, `map` method calls, etc.

2 years agooption_if_let_else: don't expand macros in suggestion
Matthias Krüger [Sat, 13 Nov 2021 22:16:02 +0000 (23:16 +0100)]
option_if_let_else: don't expand macros in suggestion

Fixes #7973

changelog: don't expand macros in suggestion of clippy::option_if_let_else

2 years agofix suggestion in option_map_or_none
togami2864 [Sat, 13 Nov 2021 13:38:28 +0000 (22:38 +0900)]
fix suggestion in option_map_or_none

2 years agoAuto merge of #7969 - togami2864:fix-typo, r=xFrednet
bors [Sat, 13 Nov 2021 11:17:38 +0000 (11:17 +0000)]
Auto merge of #7969 - togami2864:fix-typo, r=xFrednet

fix typo

just fixed typo

changelog: none

2 years agofix typo
togami2864 [Sat, 13 Nov 2021 06:23:33 +0000 (15:23 +0900)]
fix typo

2 years agoFix `manual_map` suggestion when used with unsafe functions and unsafe blocks.
Jason Newcomb [Sat, 13 Nov 2021 00:12:17 +0000 (19:12 -0500)]
Fix `manual_map` suggestion when used with unsafe functions and unsafe blocks.

2 years agoAuto merge of #7966 - Alexendoo:batch-rustfmt, r=camsteffen
bors [Fri, 12 Nov 2021 21:48:37 +0000 (21:48 +0000)]
Auto merge of #7966 - Alexendoo:batch-rustfmt, r=camsteffen

Run rustfmt on batches of multiple files

changelog: none

This gives `cargo dev fmt` a nice speed boost, down from 90s (because old) on my laptop and 120s (because windows) on my desktop to ~5s on both

250 at a time was to give windows a good amount of headroom (failed at ~800, https://github.com/rust-lang/rust/issues/40384)

Also adds rustfmt to the toolchain file and has the clippy_dev workflow test using the pinned version as a follow up to #7963

2 years agoRun rustfmt on batches of multiple files
Alex Macleod [Fri, 12 Nov 2021 16:41:08 +0000 (16:41 +0000)]
Run rustfmt on batches of multiple files

2 years agoRun clippy_dev workflow on current rust-toolchain
Alex Macleod [Fri, 12 Nov 2021 18:54:31 +0000 (18:54 +0000)]
Run clippy_dev workflow on current rust-toolchain

2 years agoAdd rustfmt component to rust-toolchain
Alex Macleod [Fri, 12 Nov 2021 18:54:08 +0000 (18:54 +0000)]
Add rustfmt component to rust-toolchain

2 years agoAuto merge of #7948 - 5225225:castlosslessbool, r=llogiq
bors [Fri, 12 Nov 2021 18:17:18 +0000 (18:17 +0000)]
Auto merge of #7948 - 5225225:castlosslessbool, r=llogiq

Lint for bool to integer casts in `cast_lossless`

The lint description says

> Checks for casts between *numerical* types that may be replaced by safe conversion functions.

Which is strictly speaking being violated here, but it seems within the spirit of the lint. I think it is still a useful lint to have, and having a different lint for just this feels excessive. Thoughts?

Fixes #7947

changelog: Lint for bool to integer casts in [`cast_lossless`]

2 years agoChange cast_lossless message for bools only
5225225 [Fri, 12 Nov 2021 17:01:35 +0000 (17:01 +0000)]
Change cast_lossless message for bools only

2 years agoAuto merge of #7963 - Jarcho:dev_fmt, r=flip1995
bors [Fri, 12 Nov 2021 09:43:09 +0000 (09:43 +0000)]
Auto merge of #7963 - Jarcho:dev_fmt, r=flip1995

Use rustfmt version from `rust-toolchain`

changelog: None

2 years agoUse rustfmt version from `rust-toolchain`
Jason Newcomb [Fri, 12 Nov 2021 02:14:40 +0000 (21:14 -0500)]
Use rustfmt version from `rust-toolchain`

2 years agoAuto merge of #7956 - camsteffen:author, r=llogiq
bors [Thu, 11 Nov 2021 19:33:06 +0000 (19:33 +0000)]
Auto merge of #7956 - camsteffen:author, r=llogiq

Author improvements

changelog: none

Various aspects of the author implementation are re-imagined to be much less repetitive. Also fixes some bugs. I hope this makes author more fun to work on for future contributors.

The last commit is pretty heavy but I tried to at least separate some changes so that the test file diffs per commit are simple.

2 years agoAuto merge of #7643 - xFrednet:7569-splits-for-slices, r=camsteffen
bors [Thu, 11 Nov 2021 16:42:57 +0000 (16:42 +0000)]
Auto merge of #7643 - xFrednet:7569-splits-for-slices, r=camsteffen

New lint `index_refutable_slice` to avoid slice indexing

A new lint to check for slices that could be deconstructed to avoid indexing. This lint should hopefully prevent some panics in other projects and ICEs for us. See #7569 for an example

The implementation specifically checks for immutable bindings in `if let` statements to slices and arrays. Then it checks if these bindings are only used for value access using indices and that these indices are lower than the configured limit. I did my best to keep the implementation small, however the check was sadly quite complex. Now it's around 300 lines for the implementation and the rest are test.

---

Optional future improvements:
* Check for these instances also in `match` statements
* Check for mutable slice bindings that could also be destructed

---

changelog: New lint [`index_refutable_slice`]

I've already fixed a bunch of lint triggers in #7638 to make this PR smaller

Closes: #7569
2 years agoNew `index_refutable_slice` lint
xFrednet [Tue, 31 Aug 2021 17:17:24 +0000 (19:17 +0200)]
New `index_refutable_slice` lint

* Finding pattern slices for `avoidable_slice_indexing`
* `avoidable_slice_indexing` analysing slice usage
* Add configuration to `avoidable_slice_indexing`
* Emitting `avoidable_slice_indexing` with suggestions
* Dogfooding and fixing bugs
* Add ui-toml test for `avoidable_slice_indexing`
* Correctly suggest `ref` keywords for `avoidable_slice_indexing`
* Test and document `mut` for `avoid_slice_indexing`
* Handle macros with `avoidable_slice_indexing` lint
* Ignore slices with sub patterns in `avoidable_slice_indexing`
* Update lint description for `avoidable_slice_indexing`
* Move `avoidable_slice_indexing` to nursery
* Added more tests for `avoidable_slice_indexing`
* Update documentation and message for `avoidable_slice_indexing`
* Teach `avoidable_slice_indexing` about `HirId`s and `Visitors`
* Rename lint to `index_refutable_slice` and connected config

2 years agoMake author DRYer
Cameron Steffen [Fri, 5 Nov 2021 22:05:04 +0000 (17:05 -0500)]
Make author DRYer

2 years agoAuto merge of #7813 - xFrednet:6492-lint-version, r=flip1995
bors [Thu, 11 Nov 2021 12:38:04 +0000 (12:38 +0000)]
Auto merge of #7813 - xFrednet:6492-lint-version, r=flip1995

Add Clippy version to Clippy's lint list

Hey, hey, the semester is finally over, and I wanted to get back into hacking on Clippy. It has also been some time since our metadata collection monster has been feed. So, this PR adds a new attribute `clippy::version` to document which version a lint was stabilized. I considered using `git blame` but that would be very hacky and probably not accurate.

I'm also thinking that this attribute can be used to have a `clippy::nightly` lint group which is allow-by-default that delays setting the actual lint group until the defined version is reached. Just something to consider regarding #6623 :upside_down_face:

This PR only adds the version to 4 lints to keep it reviewable. I'll do a followup PR to add the version to other lints if the implementation is accepted :upside_down_face:

![image](https://user-images.githubusercontent.com/17087237/137118859-0aafdfdf-7595-4289-8ba4-33d58eb6991d.png)

Also, mobile approved xD

![image](https://user-images.githubusercontent.com/17087237/137118944-833cf7fb-a4a1-45d6-9af8-32c951822360.png)

---

r? `@flip1995`

cc: #7172

closes: #6492

changelog: [Clippy's lint list](https://rust-lang.github.io/rust-clippy/master/index.html) now displays the version a lint was added. :tada:

---

Example lint declaration after this update:

```rs
declare_clippy_lint! {
    /// [...]
    ///
    /// ### Example
    /// ```rust
    /// // Bad
    /// let x = 3.14;
    /// // Good
    /// let x = std::f32::consts::PI;
    /// ```
    #[clippy::version = "pre 1.29.0"]
    pub APPROX_CONSTANT,
    correctness,
    "the approximate of a known float constant (in `std::fXX::consts`)"
}
```

2 years agoNew internal lint to make `clippy::version` attribute mandatory
xFrednet [Thu, 11 Nov 2021 11:54:53 +0000 (12:54 +0100)]
New internal lint to make  `clippy::version` attribute mandatory

2 years agoAuto merge of #7877 - dswij:no-std-fp, r=camsteffen
bors [Thu, 11 Nov 2021 05:31:11 +0000 (05:31 +0000)]
Auto merge of #7877 - dswij:no-std-fp, r=camsteffen

[`swap`] lints now check if there is `no_std` or `no_core` attribute

Closes #7858

changelog: [`swap`] lints now check if there is `no_std` or `no_core` attribute

2 years agoAdd test for `swap` lint when `no_std` is present
dswij [Mon, 25 Oct 2021 04:32:53 +0000 (12:32 +0800)]
Add test for `swap` lint when `no_std` is present

Adds additional test to check for `swap` suggestion when `no_std` is present

2 years agoCheck for no_std and no_core attribute in `swap` lint
dswij [Mon, 25 Oct 2021 04:29:05 +0000 (12:29 +0800)]
Check for no_std and no_core attribute in `swap` lint

This commit adds a `no_std` and `no_core` check on `swap` lint and additionally suggest `core::mem::swap` whenever possible.
Remove warning if both `std` and `core` is not present.

2 years agoRefactor utils on checking attribute
dswij [Mon, 25 Oct 2021 03:59:18 +0000 (11:59 +0800)]
Refactor utils on checking attribute

Moved out reusable pieces from `is_automatically_derived` and
`any_parent_is_automatically_derived`.

2 years agoauthor: Remove needless `ref`s
Cameron Steffen [Wed, 10 Nov 2021 21:59:49 +0000 (15:59 -0600)]
author: Remove needless `ref`s

2 years agoauthor: reorder match arm
Cameron Steffen [Mon, 8 Nov 2021 23:47:33 +0000 (17:47 -0600)]
author: reorder match arm

2 years agoauthor: fix some bugs
Cameron Steffen [Wed, 10 Nov 2021 21:42:49 +0000 (15:42 -0600)]
author: fix some bugs

2 years agoauthor: name qpath consistently
Cameron Steffen [Mon, 8 Nov 2021 23:05:37 +0000 (17:05 -0600)]
author: name qpath consistently

2 years agoAddress review feedback
xFrednet [Wed, 10 Nov 2021 19:08:38 +0000 (20:08 +0100)]
Address review feedback

2 years agoUpdated version label and style on Clippy's lint list
xFrednet [Tue, 2 Nov 2021 16:49:12 +0000 (17:49 +0100)]
Updated version label and style on Clippy's lint list