Commit Graph

12946 Commits

Author SHA1 Message Date
xFrednet
7c1e62d962
Added clippy::version attribute as lint metadata 2021-11-10 19:48:29 +01:00
bors
2e17035714 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`
2021-11-10 13:26:38 +00:00
dswij
a003ca6853 semicolon_if_nothing_returned now checks if the stmt ends with semicolon 2021-11-10 14:46:00 +08:00
dswij
e8861c807a Add semicolon_if_nothing_returned test for let-else stmts 2021-11-10 14:41:41 +08:00
bors
93f13d532f 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
2021-11-09 19:28:48 +00:00
bors
f69721f37c 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
2021-11-09 19:14:24 +00:00
Matthias Krüger
3b6b1ab0ec 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
2021-11-09 19:00:40 +01:00
5225225
6e84f00045 Check MSRV for bool to int from impl 2021-11-09 17:35:35 +00:00
5225225
96db1d6bea fix dogfood lint on clippy_utils 2021-11-09 17:30:15 +00:00
5225225
33822012ec Lint for bool to integer casts in cast_lossless 2021-11-09 17:30:15 +00:00
bors
c94d62b153 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
2021-11-09 12:37:49 +00:00
Serial
e54c341d05 Fix suggestion for deref expressions in redundant_pattern_matching 2021-11-09 07:25:09 -05:00
bors
36d547571c 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.
2021-11-09 11:16:38 +00:00
bors
0332a7bf0b 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.
2021-11-09 08:21:10 +00:00
bors
6536c586fe 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`
2021-11-09 05:33:16 +00:00
Michael Wright
8b7691551a matches: remove pub from some items
There is no reason for these to be `pub`. They aren't used anywhere
else.
2021-11-09 05:44:02 +02:00
Michael Wright
81fa758356 Improve variable naming 2 2021-11-09 05:44:02 +02:00
Michael Wright
c8f909ee54 Improve variable naming 2021-11-09 05:44:02 +02:00
Michael Wright
f829523340 Simplify range comparison code
Reword the `Kind` type so that the `cmp` function is simpler.
2021-11-09 05:44:02 +02:00
Michael Wright
949b25981c 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.
2021-11-09 05:44:02 +02:00
Michael Wright
98416d7f6c 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.
2021-11-09 05:44:02 +02:00
Serial
680923491a Fix explicit_counter_loop suggestion for non-usize types 2021-11-08 22:21:05 -05:00
bors
830f2205d4 Auto merge of #7944 - Serial-ATA:deprecated-cfg-attr-msrv, r=giraffate
Add MSRV to deprecated_cfg_attr

changelog: Add MSRV to [`deprecated_cfg_attr`]

closes: #7922
2021-11-09 00:58:37 +00:00
Serial
413d255916 Add MSRV to deprecated_cfg_attr 2021-11-08 17:53:50 -05:00
Deadbeef
6d23824ef4 Make select_* methods return Vec for TraitEngine 2021-11-08 23:35:23 +08:00
bors
94517d397c Auto merge of #7938 - camsteffen:visitors, r=xFrednet
Introduce `expr_visitor` and `expr_visitor_no_bodies`

changelog: none

A couple utils that satisfy a *lot* of visitor use cases. Factoring in every possible usage would be really big so I just focused on cleaning clippy_utils.
2021-11-08 13:39:58 +00:00
bors
6fcdf81939 Auto merge of #7945 - Serial-ATA:issue-7934, r=flip1995
Fix ICE in undocumented_unsafe_blocks

changelog: Fix ICE in [`undocumented_unsafe_blocks`]

closes: #7934
2021-11-08 10:48:34 +00:00
Joshua Nelson
ac9dd36856 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.
2021-11-08 01:22:28 +00:00
Serial
2c6f03d48b Fix ICE in undocumented_unsafe_blocks 2021-11-07 14:28:30 -05:00
Vadim Petrochenkov
c063203c2b ast: Fix naming conventions in AST structures
TraitKind -> Trait
TyAliasKind -> TyAlias
ImplKind -> Impl
FnKind -> Fn

All `*Kind`s in AST are supposed to be enums.

Tuple structs are converted to braced structs for the types above, and fields are reordered in syntactic order.

Also, mutable AST visitor now correctly visit spans in defaultness, unsafety, impl polarity and constness.
2021-11-07 21:38:17 +08:00
bors
07f4f7c2dd Auto merge of #7917 - Alexendoo:cargo-dev-lint, r=giraffate
Add `cargo dev lint` to manually run clippy on a file

I found the manual run command really useful, this makes it a bit easier to type

Not sure if this belongs in the changelog or not

changelog: Add `cargo dev lint` to manually run clippy on a file
2021-11-07 06:06:26 +00:00
Gary Guo
0cb9ac2d96 Give inline const separate DefKind 2021-11-07 03:59:06 +00:00
Cameron Steffen
9a8919d823 Fix Clippy with changed format_args! 2021-11-06 16:03:32 -05:00
bors
e3d1e60ed9 Auto merge of #7894 - Serial-ATA:extend-author-lint, r=camsteffen
Extend author lint

changelog: none

* Print float and int suffixes
* Print labels
* Struct field checks
* Repeat length expression check
* Destructure method calls
* Destructure closures
2021-11-06 20:08:32 +00:00
Alex Macleod
b5bae09184 Add cargo dev lint to manually run clippy on a file
I found the manual run command really useful, this makes it a bit easier
to type
2021-11-06 17:20:15 +00:00
Serial
c96cd359f5 Extend author lint 2021-11-06 03:08:14 -04:00
Cameron Steffen
2c7b7e8c56 Remove if let check for match_ref_pats 2021-11-05 14:50:23 -05:00
Cameron Steffen
5239a90f70 Factor in some expr_visitor usages 2021-11-05 14:39:39 -05:00
Cameron Steffen
73501daa39 Add expr_visitor util 2021-11-05 14:16:56 -05:00
Cameron Steffen
1c4dd8d3eb Remove trim_semicolon 2021-11-05 11:39:50 -05:00
bors
445c83f8f3 Auto merge of #7937 - flip1995:rustfmt-skip-artefact, r=Manishearth
Remove rustfmt::skip attribute from register_plugins function

r? `@Manishearth` since you added this in #540 😄

changelog: none
2021-11-05 15:34:46 +00:00
bors
9a60a93cac Auto merge of #7897 - camsteffen:in-macro, r=flip1995
Replace `in_macro` usage with `from_expansion`

changelog: none

Generally replace `in_macro(span)` with `span.from_expansion()`. If we're just trying to avoid expanded code, this seems more appropriate because any kind of expanded code is prone to false positives. One place I did not touch is `macro_use.rs`. I think this lint could use a rewrite so I moved `in_macro` there, the only place it is still used.
2021-11-05 14:42:32 +00:00
Cameron Steffen
5b1b6a2276 Edit docs about macros 2021-11-05 09:27:22 -05:00
bors
85e25923e1 Auto merge of #7909 - mikerite:fix-7816, r=camsteffen
Fix false negative in [`match_overlapping_arms`]

changelog: Fix false negative in [`match_overlapping_arms`]
2021-11-05 14:16:38 +00:00
Cameron Steffen
14d54f0f6e Use Span::from_expansion instead of in_macro 2021-11-05 08:50:17 -05:00
flip1995
93ffc9d233
Remove rustfmt::skip attribute from register_plugins function 2021-11-05 10:54:37 +00:00
flip1995
e674d0a599 Merge commit 'e18101137866b79045fee0ef996e696e68c920b4' into clippyup 2021-11-04 12:52:36 +00:00
bors
84a4ab7f3f Auto merge of #7928 - xFrednet:rust-90354-deploy-clippy-docs, r=flip1995
Reference `clippy_utils` docs on nightly-rustc and some other documentation updates

The `clippy_utils` crate is now part of the nightly-rustc documentation. See [**very beautiful documentation**](https://doc.rust-lang.org/nightly/nightly-rustc/clippy_utils/). This PR references them in our documentation and updates some other documentation.

changelog: none
2021-11-04 12:27:50 +00:00
xFrednet
540515220d
Added note about the usage of clippy_utils::path 2021-11-04 13:27:08 +01:00
bors
e181011378 Auto merge of #7929 - flip1995:rustup, r=flip1995
Rustup

r? `@ghost`

changelog: none
2021-11-04 12:07:07 +00:00