Commit graph

3808 commits

Author SHA1 Message Date
CrazyRoka
b0115fb996 Removed unnecessary code, added support for vector references 2020-04-25 00:52:02 +03:00
CrazyRoka
96e2bc80f5 Added lint match_vec_item 2020-04-24 22:45:15 +03:00
Andy Weiss
8b052d3142 span_lint_and_note now takes an Option<Span> for the note_span instead of just a span 2020-04-21 21:28:23 -07:00
Andy Weiss
d6e55e97ff Make lint also capture blocks and closures, adjust language to mention other mutex types 2020-04-21 21:07:43 -07:00
Andy Weiss
54e7f7e5f2 don't test the code in the lint docs 2020-04-21 21:07:43 -07:00
Andy Weiss
2dc8c083f5 Switch to matching against full paths instead of just the last element of the path 2020-04-21 21:07:43 -07:00
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
489dd2e504 factor ifs into function, add differing mutex test 2020-04-20 15:08:44 -04:00
Eduardo Broto
b7f85e8706 Apply suggestions from PR review
* Move the lint to pedantic
* Import used types instead of prefixing with `hir::`
2020-04-20 20:05:15 +02:00
Devin R
d1b1a4c5eb update span_lint_and_help call to six args 2020-04-20 06:49:59 -04:00
Devin R
a9f1bb43ef test for mutex eq, add another test case 2020-04-20 06:30:01 -04:00
Devin R
ae820924c4 use if chain 2020-04-20 06:30:01 -04:00
Devin R
4cebe2bf84 cargo dev fmt 2020-04-20 06:30:01 -04:00
Devin R
7242fa5e41 fix map import to rustc_middle 2020-04-20 06:30:01 -04:00
Devin R
1ee04e4f55 fix internal clippy warnings 2020-04-20 06:30:01 -04:00
Devin R
930619b484 change visitor name to OppVisitor 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
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
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
bors
e5fe56de7f Auto merge of #5489 - phansch:node-id-hir-id, r=flip1995
Cleanup: `node_id` -> `hir_id`

This removes some more `node_id` terminology from Clippy and replaces one occurrence of `as_local_node_id` with `as_local_hir_id`, which should be doing the same for that particular case.

changelog: none
2020-04-19 18:09:34 +00:00
bors
6ed2ae8685 Auto merge of #5488 - phansch:future-not-send-ret-ty, r=flip1995
Cleanup: future_not_send: use `utils::return_ty` function

changelog: none
2020-04-19 17:50:33 +00:00
Philipp Hansch
c3c00e5028
Cleanup: node_id -> hir_id 2020-04-19 17:04:14 +02: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
Philipp Hansch
502a66de3d
Cleanup: future_not_send: use return_ty method 2020-04-19 14:00:03 +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
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
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