Commit Graph

3934 Commits

Author SHA1 Message Date
rail
ad9ad6f402 Don't negate resulted offsets when offset is subtraction by 0 2020-04-27 17:42:57 +12:00
Eduardo Broto
ce50e42ed6 Use the span of the attribute for the error message 2020-04-26 21:27:29 +02:00
Eduardo Broto
d24a106395 Apply suggestions from PR review
- Show just one error message with multiple suggestions in case of
  using multiple times an OS in target family position
- Only suggest #[cfg(unix)] when the OS is in the Unix family
- Test all the operating systems
2020-04-26 21:27:29 +02:00
Eduardo Broto
149f6d6046 Implement mismatched_target_os lint 2020-04-26 21:27:29 +02:00
CrazyRoka
b574941dcb Updated lint info in lib.rs 2020-04-26 18:11:21 +03:00
CrazyRoka
940c662654 Small lint update
- Changed lint category to `correctness`
- Moved main function to bottom in test file
- Added `FIXME` comment to `span_lint_and_sugg` to improve later
2020-04-26 18:00:51 +03:00
Philipp Hansch
eda73fe707
Fix cargo crash 2020-04-26 14:11:58 +02:00
Philipp Hansch
0a49935270
cargo dev fmt 2020-04-26 13:44:08 +02:00
Philipp Hansch
0480ff861a
More diagnostic items
In particular for:

* `VecDeque`
* `String`
* `Mutex`
* `HashMap`
* `HashSet`

cc https://github.com/rust-lang/rust/pull/71414 https://github.com/rust-lang/rust-clippy/issues/5393
2020-04-26 13:44:08 +02:00
Philipp Hansch
5b1622b324
rustup to https://github.com/rust-lang/rust/pull/70043 2020-04-26 10:12:14 +02:00
bors
07dd5fada9 Auto merge of #5511 - alex-700:fix-redundant-pattern-matching, r=flip1995
Fix redundant_pattern_matching lint

fixes #5504

changelog: Fix suggestion in `redundant_pattern_matching` for macros.
2020-04-25 21:41:56 +00:00
bors
44eb953adc Auto merge of #5525 - flip1995:issue_1654, r=phansch
Don't trigger while_let_on_iterator when the iterator is recreated every iteration

r? @phansch

Fixes #1654

changelog: Fix false positive in [`while_let_on_iterator`]
2020-04-25 21:29:03 +00:00
bors
a76bfd46c5 Auto merge of #5530 - ebroto:issue_5524, r=flip1995
map_clone: avoid suggesting `copied()` for &mut

changelog: map_clone: avoid suggesting `copied()` for &mut

Fixes #5524
2020-04-25 21:16:06 +00:00
Eduardo Broto
806d973adc map_clone: avoid suggesting copied() for &mut 2020-04-25 22:52:19 +02:00
Aleksei Latyshev
69fe6b4c98
fix redundant_pattern_matching lint
- now it gives correct suggestion in case of macros
- better tests
- remove a couple of non-relevant tests
2020-04-25 23:51:30 +03:00
Philipp Krones
a33d64a4c3
Rollup merge of #5505 - flip1995:avoid_running_lints, r=matthiaskrgr
Avoid running cargo+internal lints when not enabled

r? @matthiaskrgr

changelog: none
2020-04-25 21:06:27 +02:00
Philipp Krones
e1d13c34b0
Rollup merge of #5408 - dtolnay:matchbool, r=flip1995
Downgrade match_bool to pedantic

I don't quite buy the justification in https://rust-lang.github.io/rust-clippy/. The justification is:

> It makes the code less readable.

In the Rust codebases I've worked in, I have found people were comfortable using `match bool` (selectively) to make code more readable. For example, initializing struct fields is a place where the indentation of `match` can work better than the indentation of `if`:

```rust
let _ = Struct {
    v: {
        ...
    },
    w: match doing_w {
        true => ...,
        false => ...,
    },
    x: Nested {
        c: ...,
        b: ...,
        a: ...,
    },
    y: if doing_y {
        ...
    } else { // :(
        ...
    },
    z: ...,
};
```

Or sometimes people prefer something a bit less pithy than `if` when the meaning of the bool doesn't read off clearly from the condition:

```rust
if set.insert(...) {
    ... // ???
} else {
    ...
}

match set.insert(...) {
    // set.insert returns false if already present
    false => ...,
    true => ...,
}
```

Or `match` can be a better fit when the bool is playing the role more of a value than a branch condition:

```rust
impl ErrorCodes {
    pub fn from(b: bool) -> Self {
        match b {
            true => ErrorCodes::Yes,
            false => ErrorCodes::No,
        }
    }
}
```

And then there's plain old it's-1-line-shorter, which means we get 25% more content on a screen when stacking a sequence of conditions:

```rust
let old_noun = match old_binding.is_import() {
    true => "import",
    false => "definition",
};
let new_participle = match new_binding.is_import() {
    true => "imported",
    false => "defined",
};
```

Bottom line is I think this lint fits the bill better as a pedantic lint; I don't think linting on this by default is justified.

changelog: Remove match_bool from default set of enabled lints
2020-04-25 21:06:26 +02:00
flip1995
eadd9d24dc
Don't trigger while_let_on_iterator when the iterator is recreated every iteration 2020-04-25 20:51:02 +02:00
flip1995
fe25dbe549
Fix while_let_on_iterator suggestion and make it MachineApplicable 2020-04-25 20:00:00 +02:00
CrazyRoka
63b451ea25 Renamed lint to match_on_vec_items 2020-04-25 11:34:16 +03:00
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
Matthias Krüger
f9c1acbc45
rustup https://github.com/rust-lang/rust/pull/71215/ 2020-04-24 15:29:31 +02:00
David Tolnay
ef28361293
Downgrade match_bool to pedantic 2020-04-23 16:30:06 -07:00
lzutao
3f6f392730 predecessors_for will be removed soon
Co-Authored-By: ecstatic-morse <ecstaticmorse@gmail.com>
2020-04-23 09:09:09 +07:00
Lzu Tao
9ef9b7946f Rustup "Remove BodyAndCache" 2020-04-23 08:39:35 +07:00
flip1995
f31502f4bb
Only run (late) internal lints, when they are warn/deny/forbid 2020-04-22 20:51:58 +02:00
flip1995
14f596cb74
Only run cargo lints, when they are warn/deny/forbid 2020-04-22 20:32:37 +02: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
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
Shotaro Yamada
162cf261dc unit_arg suggestion may be incorrect 2020-04-17 10:26:58 +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
c20afbdfe0 Lint map_flatten if caller is an Option 2020-04-16 08:00:32 +02: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
Philipp Krones
a353f0f174
Rename dummy_hir_id -> parent_hir_id 2020-04-15 19:46:05 +02:00
Matthias Krüger
721549569c rustup https://github.com/rust-lang/rust/pull/71116 2020-04-15 18:58:44 +02:00
Marcin Serwin
ce372c17cd Change default many single char names threshold 2020-04-15 17:58:26 +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
Marcin Serwin
d3ebd06ec9 Make the single char threshold strict inequality 2020-04-15 13:35:44 +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
c6cc07a851 Auto merge of #5452 - phansch:match_def_path_refactor, r=matthiaskrgr
Refactor: Use rustc's `match_def_path`

This replaces our match_def_path implementation with the rustc one.

Note that we can't just use it in all call sites because of the
`&[&str]` / `&[Symbol]` difference in Clippy/rustc.

changelog: none
2020-04-15 05:42:52 +00:00
Philipp Hansch
9ec95af702
Refactor: Use rustc's match_def_path
This replaces our match_def_path implementation with the rustc one.

Note that we can't just use it in all call sites because of the
`&[&str]` / `&[Symbol]` difference in Clippy/rustc.
2020-04-15 07:23:13 +02:00
bors
81b3e7096b Auto merge of #5449 - phansch:diagnostic-items, r=matthiaskrgr
Make use of more diagnostic items

This makes use of some (not all) already existing diagnostic items. Specifically:

* 79982a2: `core::mem::uninitialized`, `core::mem::zeroed`, `alloc::sync::Arc`, `alloc::sync::Rc`
* 83874d0: `Option` and `Result`

cc #5393

changelog: none
2020-04-14 19:58:17 +00:00
bors
d236b30a1d Auto merge of #5457 - phansch:sym, r=matthiaskrgr
Cleanup: Use our `sym!` macro more

It's much shorter than Symbol::intern and the effect should still be clear

---

changelog: none
2020-04-14 12:30:14 +00:00
Matthias Krüger
c1f2da40ab rustup https://github.com/rust-lang/rust/pull/70643 2020-04-14 12:25:45 +02:00
bors
74e92566d5 Auto merge of #5453 - rabisg0:fix/redundant_clone, r=phansch
Fixes #5405: redundant clone false positive with arrays

Check whether slice elements implement Copy before suggesting to drop
the clone method

changelog: add a check for slice indexing on redundant_clone lint
2020-04-14 05:59:26 +00:00
bors
aa08c39b11 Auto merge of #5458 - phansch:is-proc-macro-attr, r=matthiaskrgr
Cleanup: Use rustc's is_proc_macro_attr

It's doing exactly the same: https://doc.rust-lang.org/nightly/nightly-rustc/src/rustc_ast/expand/mod.rs.html#8-12

changelog: none
2020-04-14 05:31:03 +00:00
bors
54344c78f4 Auto merge of #5448 - Emerentius:update_new_ret_no_self_docs, r=phansch
Update documentation for new_ret_no_self

changelog: Update documentation for lint new_ret_no_self to reflect that the return type must only contain `Self`, not be `Self`

The lint was changed to be more lenient than the documentation implies in PR #3338 (Related issue #3313)
2020-04-13 20:32:44 +00:00
Philipp Hansch
e47db677ac
Cleanup: Use rustc's is_proc_macro_attr
It's doing exactly the same: https://doc.rust-lang.org/nightly/nightly-rustc/src/rustc_ast/expand/mod.rs.html#8-12
2020-04-13 09:33:00 +02:00
Philipp Hansch
31c5664f25
Cleanup: Use our sym! macro more
It's much shorter that Symbol::intern and the result should still be
clear.
2020-04-13 08:57:34 +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
Philipp Hansch
a524be6df5
cargo dev fmt 2020-04-12 15:23:54 +02:00
Philipp Hansch
83874d0ee7
Make use of Option/Result diagnostic items 2020-04-12 15:23:07 +02:00
Philipp Hansch
79982a2813
Make use of some existing diagnostic items 2020-04-12 13:58:04 +02:00
Philipp Hansch
1d1b6d886b
Say that diagnostic items are preferred over paths 2020-04-12 13:58:04 +02:00
Sean Leather
c4e3ae4f7c
verbose_bit_mask: fix bit mask used in docs
Change the existing hex bit mask (`0x1111`) to a binary one (`0b1111`).

The former does not seem to have anything to do with trailing zeros and is
probably a typo.
2020-04-12 13:11:14 +02: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
Matthias Krüger
4352c8555b rustup https://github.com/rust-lang/rust/pull/70986 2020-04-11 10:01:23 +02:00
Matthias Krüger
f7bdead5ec rustup https://github.com/rust-lang/rust/pull/69745 2020-04-11 01:51:25 +02: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
Emerentius
ed72dc4119
Update documentation for new_ret_no_self
The lint was changed to be more lenient than the documentation implies in PR #3338.
Related issue #3313
2020-04-10 19:08:31 +02:00
Philipp Hansch
3ef1dab211
Rustup to https://github.com/rust-lang/rust/pull/70913 2020-04-10 19:03:34 +02:00
Andre Bogus
89f6012a4d compare with the second largest instead of the smallest variant 2020-04-10 17:01:56 +02:00
Philipp Krones
90fb50fabf
Revert "Downgrade new_ret_no_self to pedantic" 2020-04-09 19:38:20 +02:00
Rabi Guha
183c4abb22 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
2020-04-09 21:59:42 +05:30
ThibsG
629cc4ada3 Update doc generation script 2020-04-09 09:17:41 +02:00
ThibsG
380f7218b3 Add lint on large const arrays 2020-04-09 09:09:39 +02:00
Marcin Serwin
4449cc799b Make the epsilon note spanless 2020-04-09 08:18:52 +02:00
Marcin Serwin
4e01ca35a0 Split check_fn function 2020-04-09 08:11:46 +02:00
Marcin Serwin
f637c45f8b Indicate when arrays are compared in error message 2020-04-09 08:10:14 +02:00
Marcin Serwin
84ae3d8bc8 Make epsilon note spanless when comparing arrays 2020-04-09 08:10:14 +02:00
Marcin Serwin
d3167c63f8 Handle constant arrays with single value 2020-04-09 08:07:18 +02:00
Marcin Serwin
1bab67c72b Don't show comparison suggestion for arrays 2020-04-09 08:07:18 +02:00
Marcin Serwin
bcbb9d9acb Allow for const arrays of zeros 2020-04-09 08:05:51 +02:00
Marcin Serwin
621767136e Handle evaluating constant index expression 2020-04-09 08:05:51 +02:00
Marcin Serwin
2153abb412 Add handling of float arrays to miri_to_const 2020-04-09 08:05:51 +02:00
Marcin Serwin
03f584c0c7 Update field names in is_float 2020-04-09 08:05:51 +02:00
briankabiro
d4409350dc Add lint when comparing floats in an array
Finishes #4277
2020-04-09 08:05:51 +02:00
bors
c25f26d4ca Auto merge of #5411 - dtolnay:hasher, r=flip1995
Downgrade implicit_hasher to pedantic

From the [documentation](https://rust-lang.github.io/rust-clippy/master/index.html#implicit_hasher), this lint is intended to suggest:

```diff
- pub fn foo(map: &mut HashMap<i32, i32>) { }

+ pub fn foo<S: BuildHasher>(map: &mut HashMap<i32, i32, S>) { }
```

I think this is pedantic. I get that this lint can benefit core libraries like serde, but that's exactly the use case for pedantic lints; a library like serde will [enable clippy_pedantic](fd6741f4b0/src/lib.rs (L304)) and take the time to go through everything possible. Similar for libraries doing a libz blitz style checkup before committing to a 1.0 release; it would make sense to run through all the available pedantic lints then.

But otherwise, for most codebases and certainly for industrial codebases, the above suggested change just makes the codebase more obtuse for questionable benefit.

changelog: Remove implicit_hasher from default set of enabled lints
2020-04-08 17:14:09 +00:00
bors
940bbd6aa4 Auto merge of #5437 - rabisg0:should-impl-trait, r=flip1995
Check fn header along with decl when suggesting to implement trait

When checking for functions that are potential candidates for trait
implementations check the function header to make sure modifiers like
asyncness, constness and safety match before triggering the lint.

Fixes #5413, #4290

changelog: check fn header along with decl for should_implement_trait
2020-04-08 16:55:47 +00:00
Rabi Guha
c2e5534157 Check fn header along with decl when suggesting to implement trait
When checking for functions that are potential candidates for trait
implementations check the function header to make sure modifiers like
asyncness, constness and safety match before triggering the lint.

Fixes #5413, #4290
2020-04-08 21:24:20 +05:30
David Tolnay
5f92faec6d
Downgrade implicit_hasher to pedantic 2020-04-08 08:43:20 -07:00
David Tolnay
899a1b5598
Move cognitive_complexity to nursery 2020-04-08 08:37:20 -07:00
Philipp Krones
79d152190c
Rollup merge of #5425 - xiongmao86:issue5367, r=flip1995
Ehance opt_as_ref_deref lint.

- [x] Added passing UI tests (including committed `.stderr` file)
- [x] `cargo test` passes locally
- [x] Run `cargo dev fmt`

Lint on opt.as_ref().map(|x| &**x). Fixes #5367.

changelog: lint on opt.as_ref().map(|x| &**x)
2020-04-08 15:50:28 +02:00
Philipp Krones
8fc592a8e7
Rollup merge of #5424 - jpospychala:suspicious_op_assign_impl, r=flip1995
Incorrect suspicious_op_assign_impl

fixes #5255

changelog: In suspicious_op_assign_impl ignore all operators in expression if it's part of AssignOp
2020-04-08 15:50:26 +02:00
Philipp Krones
7cb5180dfb
Rollup merge of #5420 - dtolnay:newret, r=flip1995
Downgrade new_ret_no_self to pedantic

As motivated by #5418. This is the second most widely suppressed Clippy style lint, and [this grep.app search](https://grep.app/search?q=%5C%5Ballow%5C%28.%2Aclippy%3A%3Anew_ret_no_self%5Cb&regexp=true&case=true&filter[lang][0]=Rust) shows a large number of diverse reasonable signatures for a `new` method.

changelog: Remove new_ret_no_self from default set of enabled lints
2020-04-08 15:50:24 +02:00
Philipp Krones
2011d9a783
Rollup merge of #5419 - dtolnay:unreadable, r=flip1995
Downgrade unreadable_literal to pedantic

As motivated by #5418. This is the top most commonly suppressed Clippy style lint, which indicates that the community has decided they don't share Clippy's opinion on the best style of this.

I've left the lint in as pedantic, though it could be that "restriction" would be better -- I can see this lint being useful as an opt-in restriction in some codebases.

changelog: Remove unreadable_literal from default set of enabled lints
2020-04-08 15:50:23 +02:00
Philipp Krones
a1e49f962c
Rollup merge of #5415 - nickrtorres:master, r=flip1995
Add new lint for `Result<T, E>.map_or(None, Some(T))`

Fixes #5414

PR Checklist
---
- [x] Followed lint naming conventions (the name is a bit awkward, but it seems to conform)
- [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

`Result<T, E>` has an [`ok()`](https://doc.rust-lang.org/std/result/enum.Result.html#method.ok) method that adapts a `Result<T,E>` into an `Option<T>`.
It's possible to get around this adapter by writing `Result<T,E>.map_or(None, Some)`.

This lint is implemented as a new variant of the existing [`option_map_none` lint](https://github.com/rust-lang/rust-clippy/pull/2128)
2020-04-08 15:50:20 +02:00
Philipp Krones
5ea4771433
Rollup merge of #5412 - dtolnay:tostring, r=flip1995
Downgrade inefficient_to_string to pedantic

From the [documentation](https://rust-lang.github.io/rust-clippy/master/index.html#inefficient_to_string):

> ```diff
> - ["foo", "bar"].iter().map(|s| s.to_string());
>
> + ["foo", "bar"].iter().map(|&s| s.to_string());
> ```

I feel like saving 10 nanoseconds from the formatting machinery isn't worth asking the programmer to insert extra `&` / `*` noise in the *vast* majority of cases. This is a pedantic lint.

changelog: Remove inefficient_to_string from default set of enabled lints
2020-04-08 15:50:19 +02:00