Commit graph

8289 commits

Author SHA1 Message Date
Philipp Krones
98a244fc27
Formatting and naming 2020-04-19 20:40:25 +02:00
Philipp Krones
41115d994a
Formatting and naming 2020-04-19 20:38:07 +02:00
xiongmao86
d7f1a1ed2b Change note_span argument for span_lint_and_note. 2020-04-18 18:29:36 +08:00
xiongmao86
cf4e35339b Add an Option<Span> argument to span_lint_and_help. 2020-04-18 18:28:29 +08:00
xiongmao86
d03d3bd95b Fixes internal lint warning in code base. 2020-04-18 18:20:46 +08:00
xiongmao86
bdd32e7700 Implement collapsible_span_lint_calls lint. 2020-04-18 18:13:50 +08:00
bors
891e1a859b Auto merge of #5427 - pmk21:implicit-sat-sub, r=flip1995
Add lint named implicit_saturating_sub

Fixes: #5399
I've made a basic skeleton of the lint, would love more feedback on how to make it better.
changelog: Add lint [`implicit_saturating_sub`]
2020-04-18 09:05:41 +00:00
pmk21
1c1103561e Polished lint and tests 2020-04-18 12:03:52 +05:30
pmk21
4d03b4d2f0 Added final lint and tests 2020-04-18 12:02:13 +05:30
pmk21
7c52e51d79 Added basic lint and tests 2020-04-18 11:39:54 +05:30
bors
1c0e4e5b97 Auto merge of #5483 - alex-700:fix-redundant-pattern-matching, r=flip1995
fix redundant_pattern_matching lint

- now it handles `while let` case  (related to #5462)
- better suggestions in `if let` case

changelog: Fix suggestion in `redundant_pattern_matching` and also apply this lint to the `while let` case
2020-04-17 19:29:17 +00:00
Aleksei Latyshev
092c4595fe
fix redundant_pattern_matching lint
- now it handles `while let` case
- better suggestions in `if let` case
2020-04-17 21:51:07 +03:00
bors
f1fb815603 Auto merge of #5423 - rkuhn:add_futures_not_send, r=flip1995
add lint futures_not_send

changelog: add lint futures_not_send

fixes #5379

~Remark: one thing that can (should?) still be improved is to directly include the error message from the `Send` check so that the programmer stays in the flow. Currently, getting the actual error message requires a restructuring of the code to make the `Send` constraint explicit.~
It now shows all unmet constraints for allowing the Future to be Send.
2020-04-17 16:04:14 +00:00
bors
52dacbc876 Auto merge of #5445 - logan-dev-oss:master, r=flip1995
Fixes issue #4892.

First contribution here 😊 ! Do not hesitate to correct me.

This PR is related to issue #4892 .

# Summary

```rust
-literal.method_call(args)
```
The main idea is to not trigger `clippy::precedence` when the method call is an odd function.

# Example

```rust
// should trigger lint
let _ = -1.0_f64.abs() //precedence of method call abs() and neg ('-') is ambiguous

// should not trigger lint
let _ = -1.0_f64.sin() // sin is an odd function => -sin(x) = sin(-x)
```

# Theory

Rust allows following literals:
- char
- string
- integers
- floats
- byte
- bool

Only integers/floats implements the relevant `std::ops::Neg`.
Following odd functions are implemented on i[8-128] and/or f[32-64]:
- `asin`
- `asinh`
- `atan`
- `atanh`
- `cbrt`
- `fract`
- `round`
- `signum`
- `sin`
- `sinh`
- `tan`
- `tanh `
- `to_degrees`
- `to_radians`

# Implementation

As suggested by `flip1995` in [comment](https://github.com/rust-lang/rust-clippy/issues/4892#issuecomment-568249683), this PR add a whitelist of odd functions and compare method call to the the whitelist before triggering lint.

changelog: Don't trigger [`clippy::precedence`] on odd functions.
2020-04-17 14:15:28 +00:00
Roland Kuhn
d2cbbff217 add lint futures_not_send 2020-04-17 13:54:05 +02:00
logan-dev-oss
66b855c30b Integrate more idiomatic rust changes. 2020-04-17 10:12:30 +02:00
logan-dev-oss
9c89cf00c0 Fix issue #4892. 2020-04-17 09:27:54 +02:00
bors
3ea8e5e856 Auto merge of #5482 - phansch:diag, r=matthiaskrgr
Cleanup: Rename 'db' variables to 'diag'

Did the same in rustc a while ago: https://github.com/rust-lang/rust/pull/65428

changelog: none
2020-04-17 07:24:13 +00:00
bors
82be9dc606 Auto merge of #5481 - sinkuu:no_as_ref, r=phansch
question_mark: don't add `as_ref()` for a call expression

If a call returns a `!Copy` value, it does so regardless of whether `as_ref()` is added. For example, `foo.into_option().as_ref()?` can be simplified to `foo.into_option()?`.

---

changelog: Improved `question_mark` lint suggestion so that it doesn't add redundant `as_ref()`
2020-04-17 06:19:47 +00:00
Philipp Hansch
eb7ad1c6cd
cargo dev fmt 2020-04-17 08:09:09 +02:00
Philipp Hansch
870ae36f85
Cleanup: Rename 'db' variable to 'diag' 2020-04-17 08:08:00 +02:00
Shotaro Yamada
f58bb5b234 question_mark: don't add as_ref() for a call expression 2020-04-17 13:09:02 +09:00
bors
8ae143fcd0 Auto merge of #5480 - sinkuu:unit_arg_app, r=flip1995
unit_arg suggestion is not really machine-applicable

This lint suggests replacing any code returining `()`-type with `()` literal, which can change the behavior. e.g. `Ok(do_something())` -> `OK(())`.

---

changelog: none
2020-04-17 01:40:59 +00:00
Shotaro Yamada
162cf261dc unit_arg suggestion may be incorrect 2020-04-17 10:26:58 +09:00
bors
eb9c15a6b3 Auto merge of #5479 - matthiaskrgr:readme_auto_fix, r=flip1995
readme: update to cargo clippy --fix command

changelog: none
2020-04-16 21:41:14 +00:00
bors
adf7c505e6 Auto merge of #5476 - ThibsG:FixMatchesInExternalMacros, r=flip1995
Do not lint in macros for match lints

Don't lint in macros for match lints, more precisely in `check_pat` and `check_local` where it was not the case.

changelog: none

fixes: #5362
2020-04-16 20:51:56 +00:00
bors
2f6b6ab8a1 Auto merge of #5475 - woshilapin:woshilapin-patch-1, r=flip1995
[fix] Minor typo in GH Actions 'clippy_dev'

changelog: minor: fixes file name in Github Actions workflow `clippy_dev.yml`

I was looking for something else and ended up on that typo, just thought I would fix it.
2020-04-16 20:29:19 +00:00
Matthias Krüger
65bc234c5c readme: update to cargo clippy --fix command 2020-04-16 22:19:11 +02:00
bors
c1c8bc6307 Auto merge of #5473 - Toxyxer:map-flatten-for-option, r=flip1995
Map flatten for option

Fixes #5175

changelog:
- Trigger the map_flatten lint when map is called on an option
- Add test for such case
2020-04-16 20:15:56 +00:00
bors
3704954bd1 Auto merge of #5474 - phansch:reenable-rustfmt, r=flip1995
Reenable rustfmt integration test

changelog: none
2020-04-16 19:39:28 +00:00
bors
da14f1e0ef Auto merge of #5478 - matthiaskrgr:apt_ci_debug_5477, r=phansch,flip1995
perform system upgrade fixes ci issue

Perhaps doing a system upgrade magically solves the problem?

changelog: none
2020-04-16 19:23:11 +00:00
Matthias Krüger
d181fde95e CI: performing system upgrade fixes broken apt deps on ubuntu 32bit
See #5477 for details
2020-04-16 21:03:59 +02:00
ThibsG
7fb94c2ac9 Do not lint in macros for match lints 2020-04-16 14:57:12 +02:00
Jean SIMARD
b5d62335a4
[fix] Minor typo in GH Actions 'clippy_dev' 2020-04-16 13:51:37 +02:00
Philipp Hansch
014c41547e
Reenable rustfmt integration test 2020-04-16 13:17:06 +02:00
Marcin Serwin
72a8fc24e6 Add test to map_flatten with an Option 2020-04-16 08:00:32 +02:00
Marcin Serwin
c20afbdfe0 Lint map_flatten if caller is an Option 2020-04-16 08:00:32 +02:00
bors
1765c5da90 Auto merge of #5363 - yaahc:clippy-fix, r=phansch,flip1995
add --fix support to `cargo-clippy`

Prior to this we had started work on integrating clippy as a subcommand directly into cargo in the form of `cargo clippy-preview` and `cargo fix --clippy`. In the course of that work it was decided that the best approach would be to strictly add the features clippy needed to cargo in order to insert `clippy-driver` only for workspace crates. This was accomplished by adding a `RUSTC_WORKSPACE_WRAPPER` env variable to cargo that will override the normal `RUSTC_WRAPPER` when both are present and the current crate is a workspace crate.

This change adds support to clippy to use this by setting the `RUSTC_WORKSPACE_WRAPPER` env variable instead `RUSTC_WRAPPER` and by detecting `--fix` as an arg and swapping out the `check` cargo command for `fix` when it is present.

WIP, here are the current issues that I still need to resolve

- [x] Detect if we're running on nightly rust
  - [x] Set `RUSTC_WORKSPACE_WRAPPER` on nightly, and `RUSTC_WRAPPER` on stable
  - [x] Error out on stable when `--fix` is specified, because stable currently hasn't landed the PR for `RUSTC_WORKSPACE_WRAPPER` so if we set this it just runs check and silently fails
- [ ] Update the help text
  - [ ] The current plan is to shell out to `cargo check --help` and then postprocess the output to mention clippy instead of check where appropriate and to add the extra info about `--fix` and the `-- -A lint` options.
- [x] tests?

changelog: add `--fix` arg to `cargo-clippy`
2020-04-15 22:38:42 +00:00
Jane Lusby
5cfb9ec1d7
Apply suggestions from code review
Co-Authored-By: Philipp Krones <hello@philkrones.com>
2020-04-15 14:25:42 -07:00
Jane Lusby
664ad33faf manually fixing formatting at this point lol 2020-04-15 13:08:33 -07:00
Jane Lusby
0397e46ea5 fmt 2020-04-15 13:04:04 -07:00
Jane Lusby
b3030e1b90 rename field 2020-04-15 12:31:40 -07:00
bors
6651c1b9b2 Auto merge of #5470 - flip1995:rollup-cvkuiza, r=flip1995
Rollup of 5 pull requests

Successful merges:

 - #5226 (Add lint for explicit deref and deref_mut method calls)
 - #5248 (Add lint on large non scalar const)
 - #5430 (Disallow bit-shifting in integer_arithmetic)
 - #5466 (large_enum_variant: Report sizes of variants)
 - #5468 (Zero single char names)

Failed merges:

r? @ghost

changelog: rollup
2020-04-15 18:22:37 +00:00
Philipp Krones
19183a6af5
Rollup merge of #5468 - Toxyxer:zero-single-char-names, r=flip1995
Zero single char names

Fixes: #4086

changelog:
- Make the inequality strict
2020-04-15 20:12:31 +02:00
Philipp Krones
071a5904eb
Rollup merge of #5466 - phansch:large-enum-variant-output, r=flip1995
large_enum_variant: Report sizes of variants

This reports the sizes of the largest and second-largest variants.

Closes #5459

changelog: `large_enum_variant`: Report the sizes of the largest and second-largest variants.
2020-04-15 20:12:30 +02:00
Philipp Krones
2538e63885
Rollup merge of #5430 - michaelsproul:integer-arithmetic, r=flip1995
Disallow bit-shifting in integer_arithmetic

Make the `integer_arithmetic` lint detect all the operations that are defined as being capable of overflow in the [Rust Reference](https://doc.rust-lang.org/reference/expressions/operator-expr.html#overflow), by also linting for bit-shifting operations (`<<`, `>>`).

changelog: Disallow bit-shifting in `integer_arithmetic`
2020-04-15 20:12:29 +02:00
Philipp Krones
ceea3c6a35
Rollup merge of #5248 - ThibsG:ConstValues, r=flip1995
Add lint on large non scalar const

This PR adds the new lint `non_scalar_const` that aims to warn against `const` declaration of large arrays. For performance, because of inlining, large arrays should be preferably declared as `static`.

Note: i made this one to warn on all const arrays, whether they are in a body function or not. I don't know if this is really necessary, i could just reduce this lint to variables out of function scope.

Fixes: #400

changelog: add new lint for large non-scalar types declared as const
2020-04-15 20:12:28 +02:00
Philipp Krones
3481bf4102
Rollup merge of #5226 - ThibsG:DerefExplicit1566, r=flip1995
Add lint for explicit deref and deref_mut method calls

This PR adds the lint `explicit_deref_method` that suggests replacing `deref()` and `deref_mut()` with `&*a` and `&mut *a`.

It doesn't lint inside macros.

This PR is the continuation of  #3258.

changelog: Add lint `explicit_deref_method`.

Fixes: #1566
2020-04-15 20:12:27 +02:00
bors
a9a4c8e630 Auto merge of #5467 - matthiaskrgr:rustup_43, r=flip1995
rustup https://github.com/rust-lang/rust/pull/71116

changelog: none
2020-04-15 17:46:24 +00:00
Philipp Krones
a353f0f174
Rename dummy_hir_id -> parent_hir_id 2020-04-15 19:46:05 +02:00