Commit graph

8388 commits

Author SHA1 Message Date
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
bors
34763a5f36 Auto merge of #5442 - rust-lang:revert-5420-newret, r=Manishearth
Revert "Downgrade new_ret_no_self to pedantic"

Reverts rust-lang/rust-clippy#5420

This got through with the big rollup merge, where I didn't recheck every PR of the rollup. Reverting because of the reason given in https://github.com/rust-lang/rust-clippy/pull/5420#issuecomment-610744974 by @joshtriplett

changelog: Move new_ret_no_self back to style category
2020-04-09 19:06:26 +00: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
c7b5e30423 Add float cmp const tests for arrays 2020-04-09 08:08:36 +02:00
Marcin Serwin
3c738b2286 Add float cmp tests for arrays 2020-04-09 08:08:36 +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
b4ff774d72 Update stderr of float_cmp test 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
0d00eafd32 Add tests for float in array comparison 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
bors
7bfdee56af Auto merge of #5428 - dtolnay:cognitive, r=flip1995
Move cognitive_complexity to nursery

As discussed in https://github.com/rust-lang/rust-clippy/issues/5418#issuecomment-610054361; Clippy's current understanding of cognitive complexity is not good enough yet at analyzing code for understandability to have this lint be enabled by default.

changelog: Remove cognitive_complexity from default set of enabled lints
2020-04-08 16:38:00 +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
bors
f8308c811f Auto merge of #5438 - flip1995:rollup-pi762oy, r=flip1995
Rollup of 11 pull requests

Successful merges:

 - #5406 (Fix update_lints)
 - #5409 (Downgrade let_unit_value to pedantic)
 - #5410 (Downgrade trivially_copy_pass_by_ref to pedantic)
 - #5412 (Downgrade inefficient_to_string to pedantic)
 - #5415 (Add new lint for `Result<T, E>.map_or(None, Some(T))`)
 - #5417 (Update doc links and mentioned names in docs)
 - #5419 (Downgrade unreadable_literal to pedantic)
 - #5420 (Downgrade new_ret_no_self to pedantic)
 - #5422 (CONTRIBUTING.md: fix broken triage link)
 - #5424 (Incorrect suspicious_op_assign_impl)
 - #5425 (Ehance opt_as_ref_deref lint.)

Failed merges:

 - #5345 (Add lint for float in array comparison)
 - #5411 (Downgrade implicit_hasher to pedantic)
 - #5428 (Move cognitive_complexity to nursery)

r? @ghost

changelog: rollup
2020-04-08 14:17:47 +00:00
flip1995
381f9cb34e
Run fmt and update test 2020-04-08 16:00:03 +02: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
b42bd1954a
Rollup merge of #5422 - nickrtorres:contributing-triage, r=flip1995
CONTRIBUTING.md: fix broken triage link

Fixes #5421
2020-04-08 15:50:25 +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
f84b72bf3a
Rollup merge of #5417 - flip1995:doc_update, r=flip1995
Update doc links and mentioned names in docs

changelog: none
2020-04-08 15:50:21 +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
Philipp Krones
1e1bd519a1
Rollup merge of #5410 - dtolnay:trivially, r=flip1995
Downgrade trivially_copy_pass_by_ref to pedantic

The rationale for this lint is documented as:

> In many calling conventions instances of structs will be passed through registers if they fit into two or less general purpose registers.

I think the purported performance benefits of clippy's recommendation are overstated. This isn't worth asking people to sprinkle code with more `*`​`*`​`&`​`*`​`&` to chase the alleged performance.

This should be a pedantic lint that is disabled by default and opted in if some specific performance sensitive codebase determines that it is worthwhile.

As a reminder, a typical place that a reference to a primitive would come up is if the function is used as a filter. Triggering a performance-oriented lint on this type of code is the definition of pedantic.

```rust
fn filter(_n: &i32) -> bool {
    true
}

fn main() {
    let v = vec![1, 2, 3];
    v.iter().copied().filter(filter).for_each(drop);
}
```

```console
warning: this argument (4 byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte)
 --> src/main.rs:1:15
  |
1 | fn filter(_n: &i32) -> bool {
  |               ^^^^ help: consider passing by value instead: `i32`
```

changelog: Remove trivially_copy_pass_by_ref from default set of enabled lints
2020-04-08 15:50:17 +02:00
Philipp Krones
935b45db61
Rollup merge of #5409 - dtolnay:letunit, r=flip1995
Downgrade let_unit_value to pedantic

Given that the false positive in #1502 is marked E-hard and I don't have much hope of it getting fixed, I think it would be wise to disable this lint by default. I have had to suppress this lint in every substantial codebase (\>100k line) I have worked in. Any time this lint is being triggered, it's always the false positive case.

The motivation for this lint is documented as:

> A unit value cannot usefully be used anywhere. So binding one is kind of pointless.

with this example:

> ```rust
> let x = {
>     1;
> };
> ```

Sure, but the author would find this out via an unused_variable warning or from `x` not being the type that they need further down. If there ends up being a type error on `x`, clippy's advice isn't going to help get the code compiling because it can only run if the code already compiles.

changelog: Remove let_unit_value from default set of enabled lints
2020-04-08 15:50:16 +02:00
Philipp Krones
46337cb6a8
Rollup merge of #5406 - flip1995:update_lints_fix, r=flip1995
Fix update_lints

This fixes a bug in update_lints, where `internal` lints were not registered properly. This also cleans up some code. For example: The code generation functions no longer filter the lints the are given. This is now the task of the caller. This way, it is more obvious in the `replace_in_file` calls which lints will be included in which part of a file.

This also turns the lint modules private. There is no need for them to be public, since shared code should be in the utils module anyway.

And last but not least, this fixes the `register_lints` code generation, so also internal lints get registered.

changelog: none
2020-04-08 15:50:15 +02:00
bors
0b4098335d Auto merge of #5429 - faern:use-assoc-int-float-consts, r=flip1995
Use assoc int and float consts instead of module level ones

changelog: Recommend primitive type associated constants instead of module level constants

In Rust 1.43 integer and float primitive types will have a number of new associated constants. For example `MAX`, `MIN` and a number of constants related to the machine representation of floats. https://github.com/rust-lang/rust/pull/68952

These new constants are preferred over the module level constants in `{core,std}::{f*, u*, i*}`. I have in the last few days made sure that the documentation in the main rust repository uses the new constants in every place I could find (https://github.com/rust-lang/rust/pull/69860, https://github.com/rust-lang/rust/pull/70782). So the next step is naturally to make the linter recommend the new constants as well.

This PR only changes two lints. There are more. But I did not want the PR to be too big. And since I have not contributed to clippy before it felt saner to start with a small PR so I see if there are any quirks. More will come later.
2020-04-08 13:14:50 +00:00
Linus Färnstrand
1647f53fb3 Use int assoc consts in MANUAL_SATURATING_ARITHMETIC 2020-04-08 00:43:27 +02:00
Linus Färnstrand
4726daad52 Use int assoc consts in checked_conversions lint 2020-04-08 00:43:27 +02:00
Linus Färnstrand
b192f2cd15 Use primitive type assoc consts in more tests 2020-04-08 00:43:27 +02:00
Linus Färnstrand
c2f67e1e19 Use integer assoc consts in more lint example code 2020-04-08 00:43:27 +02:00
Linus Färnstrand
518568ae0a Don't import primitive type modules 2020-04-08 00:43:27 +02:00
Linus Färnstrand
51bb1d28c5 Use assoc const NAN for zero_div_zero lint 2020-04-08 00:43:27 +02:00
Linus Färnstrand
645b62e436 Fix float cmp to use assoc fxx::EPSILON 2020-04-08 00:43:27 +02:00