Commit graph

2117 commits

Author SHA1 Message Date
Andy Weiss
6c25c3c381 Lint for holding locks across await points
Fixes #4226

This introduces the lint await_holding_lock. For async functions, we iterate
over all types in generator_interior_types and look for types named MutexGuard,
RwLockReadGuard, or RwLockWriteGuard. If we find one then we emit a lint.
2020-04-21 21:07:43 -07:00
Matthias Krüger
7221db2dc3 fix crash on issue-69020-assoc-const-arith-overflow.rs
Fixes #5497
2020-04-20 23:01:34 +02:00
bors
6ce05bf849 Auto merge of #5332 - DevinR528:if-let-else-mutex, r=flip1995
If let else mutex

changelog: Adds lint to catch incorrect use of `Mutex::lock` in `if let` expressions with lock calls in any of the blocks.

closes: #5219
2020-04-20 20:21:33 +00:00
Devin R
3fbe321440 update stderr file 2020-04-20 15:47:08 -04:00
Devin R
489dd2e504 factor ifs into function, add differing mutex test 2020-04-20 15:08:44 -04:00
Devin R
a9f1bb43ef test for mutex eq, add another test case 2020-04-20 06:30:01 -04:00
Devin R
c6c77d9a42 use Visitor api to find Mutex::lock calls 2020-04-20 06:30:00 -04:00
Devin R
fca3537fa3 add note about update-all-refs script, revert redundant pat to master 2020-04-20 06:30:00 -04:00
Devin R
51c2325dd7 move closures to seperate fns, remove known problems 2020-04-20 06:30:00 -04:00
Devin R
40bbdffc89 use span_lint_and_help, cargo dev fmt 2020-04-20 06:30:00 -04:00
Devin R
139e2c6227 creating suggestion 2020-04-20 06:30:00 -04:00
Devin R
001a42e632 progress work on suggestion for auto fix 2020-04-20 06:29:59 -04:00
Eduardo Broto
00b4f2819f Implement unsafe_derive_deserialize lint 2020-04-19 23:26:17 +02:00
bors
6dcc8d5038 Auto merge of #5141 - xiongmao86:issue5095, r=flip1995
Fixes issue 5095

fixes #5095.

- [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: (internal) warn about collapsible `span_lint_and_then` calls.
2020-04-19 19:19:54 +00:00
flip1995
7aeb3a43c9
Update empty_enum.stderr 2020-04-19 21:00:25 +02:00
bors
2efc2d6366 Auto merge of #5491 - smklein:borrowed_box, r=flip1995
Fix issue #2907.

Update the "borrow box" lint to avoid recommending the following
conversion:

```
  // Old
  pub fn f(&mut Box<T>) {...}

  // New
  pub fn f(&mut T) {...}
```

Given a mutable reference to a box, functions may want to change
"which" object the Box is pointing at.

This change avoids recommending removing the "Box" parameter
for mutable references.

changelog: Don't trigger [`borrow_box`] lint on `&mut Box` references
2020-04-19 18:59:23 +00:00
Sean Klein
0ef5dee3b8 Fix issue #2907.
Update the "borrow box" lint to avoid recommending the following
conversion:

```
  // Old
  pub fn f(&mut Box<T>) {...}

  // New
  pub fn f(&mut T) {...}
```

Given a mutable reference to a box, functions may want to change
"which" object the Box is pointing at.

This change avoids recommending removing the "Box" parameter
for mutable references.
2020-04-19 10:56:15 -04:00
Shotaro Yamada
554f47bb48 Don't trigger toplevel_ref_arg for for loops 2020-04-19 22:56:47 +09: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
bdd32e7700 Implement collapsible_span_lint_calls lint. 2020-04-18 18:13:50 +08: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
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
Roland Kuhn
d2cbbff217 add lint futures_not_send 2020-04-17 13:54:05 +02:00
logan-dev-oss
9c89cf00c0 Fix issue #4892. 2020-04-17 09:27:54 +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
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
ThibsG
7fb94c2ac9 Do not lint in macros for match lints 2020-04-16 14:57:12 +02:00
Marcin Serwin
72a8fc24e6 Add test to map_flatten with an Option 2020-04-16 08:00:32 +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
ThibsG
3c2bbcf00e Better precedence case management + more tests 2020-04-15 17:18:12 +02:00
ThibsG
72b9ae2a10 Use only check_expr with parent expr and precedence 2020-04-15 17:18:12 +02:00
ThibsG
b6d4330550 Check for Deref trait impl + add fixed version 2020-04-15 17:18:12 +02:00
ThibsG
c1132434a7 Report using stmts and expr + tests 2020-04-15 17:18:12 +02:00
ThibsG
6b4ab82746 Global rework + fix imports 2020-04-15 17:18:12 +02:00
Tom Milligan
b2d986850d Working basic dereference clip 2020-04-15 17:18:12 +02:00
Philipp Hansch
69c3e9c90f
large_enum_variant: Report sizes of variants
This reports the sizes of the largest and second-largest variants.
2020-04-15 09:56:32 +02:00
bors
a96f874301 Auto merge of #5345 - Toxyxer:add-lint-for-float-in-array-comparison, r=flip1995
Add lint for float in array comparison

Fixes #4277
changelog:
- Added new handler for expression of index kind (e.g. `arr[i]`). It returns a constant when both array and index are constant, or when the array is constant and all values are equal.
- Trigger float_cmp and float_cmp_const lint when comparing arrays. Allow for comparison when one of the arrays contains only zeros or infinities.
- Added appropriate tests for such cases.
2020-04-15 06:39:11 +00:00
bors
3c77188c04 Auto merge of #5460 - phansch:fix_incorrect_tests, r=matthiaskrgr
result_map_unit_fn: Fix incorrect UI tests

`x` and the `HasResult` struct were missing in this file.

changelog: none
2020-04-14 19:33:11 +00:00
Philipp Hansch
9a52d52068
result_map_unit_fn: Fix incorrect UI tests
`x` and the `HasResult` struct were missing in this file.
2020-04-13 15:26:53 +02:00
Rabi Guha
ab3946d7e9 Fixes #5405: redundant clone false positive with arrays
Check whether slice elements implement Copy before suggesting to drop
the clone method
2020-04-13 11:43:42 +05:30
Michael Sproul
23df4a0183
Disallow bit-shifting in integer_arithmetic lint
With this change, the lint checks all operations that are defined as
being capable of overflow in the Rust Reference.
2020-04-13 13:23:59 +10:00
Dan B
a296058e50 Allow UUID style formatting for inconsistent_digit_grouping lint
This change adds a check to the `inconsistent_digit_grouping` to add a check for
NumericLiterals that follow the UUID format of 8-4-4-4-12.

If the NumericLiteral matches the UUID format, no further inconsistent grouping checks
will be performed.

Closes #5431
2020-04-12 01:24:37 +01:00
bors
5e8c0c5ae0 Auto merge of #5441 - rabisg0:fix/clone-on-copy, r=phansch
Check for clone-on-copy in argument positions

Earlier if arguments to method calls matched the above pattern they were
not reported. This patch ensures such arguments are checked as well.

Fixes #5436

changelog: apply clone_on_copy lint to func args as well
2020-04-10 21:49:26 +00:00
bors
0353f21d23 Auto merge of #5446 - rust-lang:gimme-a-second, r=flip1995
compare with the second largest instead of the smallest variant

This should make the lint less noisy for now. See [my comment](https://github.com/rust-lang/rust-clippy/issues/5418#issuecomment-610440898) to issue #5418.

---

changelog: none
2020-04-10 21:33:45 +00:00