]> git.lizzy.rs Git - rust.git/log
rust.git
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 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 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 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

2 years agoAdd lint to check for invalid `clippy:version` attributes
xFrednet [Thu, 21 Oct 2021 21:00:31 +0000 (23:00 +0200)]
Add lint to check for invalid `clippy:version` attributes

2 years agoAdded `clippy::version` attribute to all normal lints
xFrednet [Thu, 21 Oct 2021 19:06:26 +0000 (21:06 +0200)]
Added `clippy::version` attribute to all normal lints

So, some context for this, well, more a story. I'm not used to scripting, I've never really scripted anything, even if it's a valuable skill. I just never really needed it. Now, `@flip1995` correctly suggested using a script for this in `rust-clippy#7813`...

And I decided to write a script using nushell because why not? This was a mistake... I spend way more time on this than I would like to admit. It has definitely been more than 4 hours. It shouldn't take that long, but me being new to scripting and nushell just wasn't a good mixture... Anyway, here is the script that creates another script which adds the versions. Fun...

Just execute this on the `gh-pages` branch and the resulting `replacer.sh` in `clippy_lints` and it should all work.

```nu
mv v0.0.212 rust-1.00.0;
mv beta rust-1.57.0;
mv master rust-1.58.0;

let paths = (open ./rust-1.58.0/lints.json | select id id_span | flatten | select id path);
let versions = (
    ls | where name =~ "rust-" | select name | format {name}/lints.json |
    each { open $it | select id | insert version $it | str substring "5,11" version} |
    group-by id | rotate counter-clockwise id version |
    update version {get version | first 1} | flatten | select id version);
$paths | each { |row|
    let version = ($versions | where id == ($row.id) | format {version})
    let idu = ($row.id | str upcase)
    $"sed -i '0,/($idu),/{s/pub ($idu),/#[clippy::version = "($version)"]\n    pub ($idu),/}' ($row.path)"
} | str collect ";" | str find-replace --all '1.00.0' 'pre 1.29.0' | save "replacer.sh";
```

And this still has some problems, but at this point I just want to be done -.-

2 years agoManually add `clippy::version` attribute to deprecated lints
xFrednet [Sun, 17 Oct 2021 14:57:13 +0000 (16:57 +0200)]
Manually add `clippy::version` attribute to deprecated lints

2 years agoDocument new `clippy::version` attribute and make it mandatory
xFrednet [Sun, 17 Oct 2021 13:02:12 +0000 (15:02 +0200)]
Document new `clippy::version` attribute and make it mandatory

2 years agoAdd clippy version to Clippy's lint list
xFrednet [Tue, 12 Oct 2021 21:01:44 +0000 (23:01 +0200)]
Add clippy version to Clippy's lint list

2 years agoAdded `clippy::version` attribute as lint metadata
xFrednet [Tue, 12 Oct 2021 20:51:44 +0000 (22:51 +0200)]
Added `clippy::version` attribute as lint metadata

2 years agoAuto merge of #7955 - dswij:let-else-early-return, r=giraffate
bors [Wed, 10 Nov 2021 13:26:38 +0000 (13:26 +0000)]
Auto merge of #7955 - dswij:let-else-early-return, r=giraffate

Fix `semicolon_if_nothing_returned` FP on `let-else` stmts

closes #7912

`semicolon_if_nothing_returned` now additionally checks if the statements ends in `;` , this will also prevent `let-else` statements to be linted.

changelog: fix [`semicolon_if_nothing_returned`] FP  firing on `let-else`

2 years ago`semicolon_if_nothing_returned` now checks if the stmt ends with semicolon
dswij [Wed, 10 Nov 2021 06:46:00 +0000 (14:46 +0800)]
`semicolon_if_nothing_returned` now checks if the stmt ends with semicolon

2 years agoAdd `semicolon_if_nothing_returned` test for `let-else` stmts
dswij [Wed, 10 Nov 2021 06:41:41 +0000 (14:41 +0800)]
Add `semicolon_if_nothing_returned` test for `let-else` stmts

2 years agoAuto merge of #7951 - mikerite:matches-20211109, r=llogiq
bors [Tue, 9 Nov 2021 19:28:48 +0000 (19:28 +0000)]
Auto merge of #7951 - mikerite:matches-20211109, r=llogiq

`match_overlapping_arm` refactoring

The main purpose of this pull request is to remove the unneeded and scary `unimplented!()` in the `match_arm_overlapping` code.

The rest is gratuitous refactoring.

changelog: none

2 years agoAuto merge of #7950 - Serial-ATA:issue-7920, r=llogiq
bors [Tue, 9 Nov 2021 19:14:24 +0000 (19:14 +0000)]
Auto merge of #7950 - Serial-ATA:issue-7920, r=llogiq

Fix `explicit_counter_loop` suggestion for non-usize types

changelog: Add a new suggestion for non-usize types in [`explicit_counter_loop`]

closes: #7920

2 years agoRollup merge of #89561 - nbdd0121:const_typeck, r=nikomatsakis
Matthias Krüger [Tue, 9 Nov 2021 18:00:40 +0000 (19:00 +0100)]
Rollup merge of #89561 - nbdd0121:const_typeck, r=nikomatsakis

Type inference for inline consts

Fixes #78132
Fixes #78174
Fixes #81857
Fixes #89964

Perform type checking/inference of inline consts in the same context as the outer def, similar to what is currently done to closure.

Doing so would require `closure_base_def_id` of the inline const to return the outer def, and since `closure_base_def_id` can be called on non-local crate (and thus have no HIR available), a new `DefKind` is created for inline consts.

The type of the generated anon const can capture lifetime of outer def, so we couldn't just use the typeck result as the type of the inline const's def. Closure has a similar issue, and it uses extra type params `CK, CS, U` to capture closure kind, input/output signature and upvars. I use a similar approach for inline consts, letting it have an extra type param `R`, and then `typeof(InlineConst<[paremt generics], R>)` would just be `R`. In borrowck region requirements are also propagated to the outer MIR body just like it's currently done for closure.

With this PR, inline consts in expression position are quitely usable now; however the usage in pattern position is still incomplete -- since those does not remain in the MIR borrowck couldn't verify the lifetime there. I have left an ignored test as a FIXME.

Some disucssions can be found on [this Zulip thread](https://rust-lang.zulipchat.com/#narrow/stream/260443-project-const-generics/topic/inline.20consts.20typeck).
cc `````@spastorino````` `````@lcnr`````
r? `````@nikomatsakis`````

`````@rustbot````` label A-inference F-inline_const T-compiler

2 years agoCheck MSRV for bool to int from impl
5225225 [Tue, 9 Nov 2021 17:35:35 +0000 (17:35 +0000)]
Check MSRV for bool to int from impl

2 years agofix dogfood lint on clippy_utils
5225225 [Mon, 8 Nov 2021 22:03:06 +0000 (22:03 +0000)]
fix dogfood lint on clippy_utils

2 years agoLint for bool to integer casts in `cast_lossless`
5225225 [Mon, 8 Nov 2021 20:44:50 +0000 (20:44 +0000)]
Lint for bool to integer casts in `cast_lossless`

2 years agoAuto merge of #7949 - Serial-ATA:issue-7921, r=flip1995
bors [Tue, 9 Nov 2021 12:37:49 +0000 (12:37 +0000)]
Auto merge of #7949 - Serial-ATA:issue-7921, r=flip1995

Fix suggestion for deref expressions in redundant_pattern_matching

changelog: Fix suggestion for deref expressions in [`redundant_pattern_matching`]

closes: #7921

2 years agoFix suggestion for deref expressions in redundant_pattern_matching
Serial [Mon, 8 Nov 2021 23:31:18 +0000 (18:31 -0500)]
Fix suggestion for deref expressions in redundant_pattern_matching

2 years agoAuto merge of #90700 - fee1-dead:select-returns-vec, r=davidtwco
bors [Tue, 9 Nov 2021 11:16:38 +0000 (11:16 +0000)]
Auto merge of #90700 - fee1-dead:select-returns-vec, r=davidtwco

Make `select_*` methods return `Vec` for `TraitEngine`

This reduces some complexity as an empty vec means no errors and non-empty vec means errors occurred.

2 years agoAuto merge of #87337 - jyn514:lint-error, r=oli-obk,flip1995
bors [Tue, 9 Nov 2021 08:21:10 +0000 (08:21 +0000)]
Auto merge of #87337 - jyn514:lint-error, r=oli-obk,flip1995

Don't abort compilation after giving a lint error

The only reason to use `abort_if_errors` is when the program is so broken that either:
1. later passes get confused and ICE
2. any diagnostics from later passes would be noise

This is never the case for lints, because the compiler has to be able to deal with `allow`-ed lints.
So it can continue to lint and compile even if there are lint errors.

Closes https://github.com/rust-lang/rust/issues/82761. This is a WIP because I have a feeling it will exit with 0 even if there were lint errors; I don't have a computer that can build rustc locally at the moment.

2 years agoAuto merge of #90485 - camsteffen:fmt-args-less-bind, r=m-ou-se
bors [Tue, 9 Nov 2021 05:33:16 +0000 (05:33 +0000)]
Auto merge of #90485 - camsteffen:fmt-args-less-bind, r=m-ou-se

Don't destructure args tuple in format_args!

This allows Clippy to parse the HIR more simply since `arg0` is changed to `_args.0`. (cc rust-lang/rust-clippy#7843). From rustc's perspective, I think this is something between a lateral move and a tiny improvement since there are fewer bindings.

r? `@m-ou-se`

2 years agomatches: remove `pub` from some items
Michael Wright [Tue, 9 Nov 2021 03:44:02 +0000 (05:44 +0200)]
matches: remove `pub` from some items

There is no reason for these to be `pub`. They aren't used anywhere
else.

2 years agoImprove variable naming 2
Michael Wright [Tue, 9 Nov 2021 03:44:02 +0000 (05:44 +0200)]
Improve variable naming 2

2 years agoImprove variable naming
Michael Wright [Tue, 9 Nov 2021 03:44:02 +0000 (05:44 +0200)]
Improve variable naming

2 years agoSimplify range comparison code
Michael Wright [Tue, 9 Nov 2021 03:44:02 +0000 (05:44 +0200)]
Simplify range comparison code

Reword the `Kind` type so that the `cmp` function is simpler.

2 years agoChange `Bound` to `EndBound`
Michael Wright [Tue, 9 Nov 2021 03:44:02 +0000 (05:44 +0200)]
Change `Bound` to `EndBound`

Only the end bounds of ranges can actually be included or excluded. This
commit changes the SpannedRange type to reflect that. Update `Kind::value`
to and `Kind::cmp` for this change. `Kind::cmp` gets flipped to check value
first and then the bound details and is much shorter.

2 years agoRemove `unimplemented!()` case in matches code
Michael Wright [Tue, 9 Nov 2021 03:44:02 +0000 (05:44 +0200)]
Remove `unimplemented!()` case in matches code

This unbounded case never actually happens because `all_ranges(..)` uses
the scrutinee type bounds for open ranges. Switch to our own `Bound`
enum so that we don't have this case.

2 years agoFix explicit_counter_loop suggestion for non-usize types
Serial [Tue, 9 Nov 2021 03:09:26 +0000 (22:09 -0500)]
Fix explicit_counter_loop suggestion for non-usize types