Commit graph

6033 commits

Author SHA1 Message Date
Jason Newcomb
60dd2b65dc
Fix redundant_closure for vec![] macro in a closure with arguments 2021-05-21 15:48:29 -04:00
Jason Newcomb
6d4dc35882
Improve needless_borrow lint
Suggest changing usages of ref bindings to match the new type
Split out some cases into new lint `ref_binding_to_reference`
2021-05-20 09:03:47 -04:00
Jason Newcomb
6e03a306ac
Remove fix for rustc bug from needless_borrow
The spans given for derived traits used to not indicate they were from a macro expansion.
2021-05-20 09:03:31 -04:00
flip1995
7304829115
Early return from LintPass registration when collecting metadata
This speeds up the metadata collection by 2-2.5x on my machine. During
metadata collection other lint passes don't have to be registered, only
the lints themselves.
2021-05-20 13:57:52 +02:00
flip1995
451ff5668b
Merge remote-tracking branch 'upstream/master' into rustup 2021-05-20 12:05:02 +02:00
Fridtjof Stoldt
9dc366bc4d
Fixed a type
Co-authored-by: Philipp Krones <hello@philkrones.com>
2021-05-19 17:23:33 +02:00
xFrednet
8036d7f784 Adding the default lint level to the metadata collection
And stripping the clippy:: prefix from the group
2021-05-19 16:42:21 +02:00
bors
4f3b49fffa Auto merge of #84767 - scottmcm:try_trait_actual, r=lcnr
Implement the new desugaring from `try_trait_v2`

~~Currently blocked on https://github.com/rust-lang/rust/issues/84782, which has a PR in https://github.com/rust-lang/rust/pull/84811~~ Rebased atop that fix.

`try_trait_v2` tracking issue: https://github.com/rust-lang/rust/issues/84277

Unfortunately this is already touching a ton of things, so if you have suggestions for good ways to split it up, I'd be happy to hear them.  (The combination between the use in the library, the compiler changes, the corresponding diagnostic differences, even MIR tests mean that I don't really have a great plan for it other than trying to have decently-readable commits.

r? `@ghost`

~~(This probably shouldn't go in during the last week before the fork anyway.)~~ Fork happened.
2021-05-18 20:50:01 +00:00
bors
aa1959b90c Auto merge of #7089 - Jarcho:multiple_impls_generic, r=Jarcho
Don't lint `multiple_inherent_impl` with generic arguments

fixes: #5772
changelog: Treat different generic arguments as different types in `multiple_inherent_impl`
2021-05-18 16:35:48 +00:00
Jason Newcomb
760f70312e
Improve multiple_inherent_impl lint
Treat different generic arguments as different types.
Allow the lint to be ignored on the type definition, or any impl blocks.
2021-05-18 11:45:51 -04:00
Jason Newcomb
a149ba26fa
Fix ICE in implicit_return
async functions always return a value
2021-05-18 10:51:59 -04:00
flip1995
ff452d5ba6
Deny warning in every main sub-crate
This enables the same warnings that are enabled in `clippy_lints` also
in `clippy_utils` and `clippy_dev`. Then it makes sure, that the
`deny-warnings` feature is passed down to `clippy_lints` and
`clippy_utils` when compiling Clippy.
2021-05-18 11:05:48 +02:00
Philipp Krones
99fb776ace
Rollup merge of #7235 - camsteffen:manual-unwrap-or-deref, r=flip1995
Fix another manual_unwrap_or deref FP

changelog: none (since this just piggybacks on #7233)

Fixes #6960
2021-05-18 10:21:55 +02:00
bors
9028173b24 Auto merge of #7201 - mucinoab:master, r=giraffate
Remove powi, "square can be computed more efficiently"

powi(2) produces exactly the same native code as x * x
powi was part of the [`suboptimal_flops`] lint

fixes #7058
changelog: Remove powi [`suboptimal_flops`], "square can be computed more efficiently"
2021-05-18 05:28:42 +00:00
Bruno A. Muciño
be540e6596 Remove powi, "square can be computed more efficiently"
powi(2) produces exactly the same native code as x * x
2021-05-17 21:59:08 -05:00
bors
6fcdb8a297 Auto merge of #7234 - camsteffen:if-let-else-braces, r=flip1995
Remove dead code after #7216

changelog: none
2021-05-17 21:42:21 +00:00
Cameron Steffen
8356c485a9 Fix manual_unwrap_or FP deref reference 2021-05-17 14:20:26 -05:00
Cameron Steffen
ca0f0002a4 Remove dead code after not linting else if let 2021-05-17 14:09:54 -05:00
bors
a3223af9fe Auto merge of #7133 - arya-k:master, r=llogiq
Add `needless_bitwise_bool` lint

fixes #6827
fixes #1594

changelog: Add ``[`needless_bitwise_bool`]`` lint

Creates a new `bitwise_bool` lint to convert `x & y` to `x && y` when both `x` and `y` are booleans. I also had to adjust thh `needless_bool` lint slightly, and fix a couple failing dogfood tests. I made it a correctness lint as per flip1995's comment [here](https://github.com/rust-lang/rust-clippy/pull/3385#issuecomment-434715723), from a previous WIP attempt at this lint.
2021-05-17 18:57:14 +00:00
Cameron Steffen
b2270e1f45 Simplify manual_unwrap_or 2021-05-17 13:54:25 -05:00
bors
1aad7541db Auto merge of #7223 - ThibsG:FpUselessConversion7205, r=camsteffen
Fix FPs about generic args

Fix 2 false positives in [`use_self`] and [`useless_conversion`] lints, by taking into account generic args and comparing them.

Fixes: #7205
Fixes: #7206

changelog: Fix FPs about generic args in [`use_self`] and [`useless_conversion`] lints
2021-05-17 17:40:48 +00:00
bors
cec8d95729 Auto merge of #7233 - giraffate:fix_manual_unwrap_or_fp_with_deref_coercion, r=flip1995
Fix a `manual_unwrap_or` FP with deref coercion

Fix https://github.com/rust-lang/rust-clippy/issues/7228.

changelog: Fix a [`manual_unwrap_or`] FP with deref coercion
2021-05-17 17:13:57 +00:00
ThibsG
2fb35ce4f0 Add generic args for comparison in use_self and useless_conversion lints 2021-05-17 17:27:16 +02:00
Arya Kumar
0dcde71224 Fix missing variable init in lint example 2021-05-17 15:00:15 +00:00
Takayuki Nakata
ebf065e517 Fix a manual_unwrap_or FP with deref coercion 2021-05-17 22:18:50 +09:00
bors
acdf43f257 Auto merge of #7225 - InquisitivePenguin:unnessecary-async, r=llogiq
New lint: `unused_async`

changelog: Adds a lint, `unused_async`, which checks for async functions with no await statements

`unused_async` is a lint that reduces code smell and overhead by encouraging async functions to be refactored into synchronous functions.

Fixes #7176

### Examples

```rust
async fn get_random_number() -> i64 {
    4 // Chosen by fair dice roll. Guaranteed to be random.
}
```

Could be written as:

```rust
fn get_random_number() -> i64 {
    4 // Chosen by fair dice roll. Guaranteed to be random.
}
```

Something like this, however, should **not** be caught by clippy:
```rust
#[async_trait]
trait AsyncTrait {
    async fn foo();
}

struct Bar;

#[async_trait]
impl AsyncTrait for Bar {
    async fn foo() {
        println!("bar");
    }
}
```
2021-05-17 06:00:55 +00:00
bors
44e0747664 Auto merge of #7216 - ThibsG:OptionIfLetElse7006, r=llogiq
Stop linting `else if let` pattern in [`option_if_let_else`] lint

For readability concerns, it is counterproductive to lint `else if let` pattern.
Unfortunately the suggested code is much less readable.

Fixes: #7006

changelog: stop linting `else if let` pattern in [`option_if_let_else`] lint
2021-05-17 05:45:24 +00:00
bors
c086676657 Auto merge of #85178 - cjgillot:local-crate, r=oli-obk
Remove CrateNum parameter for queries that only work on local crate

The pervasive `CrateNum` parameter is a remnant of the multi-crate rustc idea.

Using `()` as query key in those cases avoids having to worry about the validity of the query key.
2021-05-17 01:42:03 +00:00
bors
48dad265ab Auto merge of #7214 - xFrednet:7197-collecting-configuration, r=flip1995,camsteffen
Metadata collection monster searching for Clippy's configuration options

This PR teaches our lovely metadata collection monster which configurations are available inside Clippy. It then adds a new *Configuration* section to the lint documentation.

---

The implementation uses the `define_Conf!` macro to create a vector of metadata during compilation. This enables easy collection and parsing without the need of searching for the struct during a lint-pass (and it's quite elegant IMO). The information is then parsed into an intermediate struct called `ClippyConfiguration` which will be saved inside the `MetadataCollector` struct itself. It is currently only used to generate the *Configuration* section in the lint documentation, but I'm thinking about adding an overview of available configurations to the website. Saving them in this intermediate state without formatting them right away enables this in the future.

The new parsing will also allow us to have a documentation that spans over multiple lines in the future. For example, this will be valid when the old script has been removed:
```rust
/// Lint: BLACKLISTED_NAME.
/// The list of blacklisted names to lint about. NB: `bar` is not here since it has legitimate uses
(blacklisted_names: Vec<String> = ["foo", "baz", "quux"].iter().map(ToString::to_string).collect())
```

The deprecation reason is also currently being collected but not used any further and that's basically it.

---

See: #7172 for the full metadata collection to-do list or to suggest a new feature in connection to it 🙃

---

changelog: none

r? `@flip1995`
cc `@camsteffen` It would be great if you could also review this PR as you have recently worked on Clippy's `define_Conf!` macro.
2021-05-16 21:02:02 +00:00
xFrednet
f810c11d3c Applying PR suggestions and cleaning up 2021-05-15 19:09:16 +02:00
Jackson Lewis
75ef9dc708
update_lints 2021-05-14 17:12:25 -07:00
Jackson Lewis
1d8f3b51e6
Unnecessary -> Unused 2021-05-14 17:07:30 -07:00
Jackson Lewis
c6e0e843d2
Implement unnecessary-async and UI test 2021-05-14 16:45:18 -07:00
bors
10db5a6064 Auto merge of #7188 - mgacek8:issue7164_needless_collect_FP, r=xFrednet,flip1995
`needless_collect` enhancements

fixes #7164
changelog: `needless_collect`: For `BTreeMap` and `HashMap` lint only `is_empty`, as `len` might produce different results than iter's `count`
changelog: `needless_collect`: Lint `LinkedList` and `BinaryHeap` in direct usage case as well
2021-05-13 16:35:42 +00:00
bors
08ce8bb703 Auto merge of #7215 - ThibsG:WrongSelfFix7179, r=Manishearth
Trigger [`wrong_self_convention`] only if it has implicit self

Lint [`wrong_self_convention`] only if the impl or trait has `self` _per sé_.

Fixes: #7179

changelog: trigger [`wrong_self_convention`] only if it has implicit self
2021-05-13 16:00:58 +00:00
Mateusz Gacek
b249290448 needless_collect: use snippet_with_applicability
+ small code refactor - using early returns.
2021-05-13 17:09:59 +02:00
bors
1fd9975249 Auto merge of #7095 - Y-Nak:match_single_binding, r=giraffate
match_single_binding: Fix invalid suggestion when match scrutinee has side effects

fixes #7094

changelog: `match_single_binding`: Fix invalid suggestion when match scrutinee has side effects

---
`Expr::can_have_side_effects` is used to determine the scrutinee has side effects, while this method is a little bit conservative for our use case. But I'd like to use it to avoid reimplementation of the method and too much heuristics. If you think this is problematic, then I'll implement a custom visitor to address it.
2021-05-13 13:55:47 +00:00
ThibsG
368e621265 Stop linting else if let pattern in option_if_let_else lint 2021-05-13 11:50:25 +02:00
ThibsG
cd241b33cb Trigger wrong_self_convention only if it has implicit self 2021-05-13 10:24:29 +02:00
Jason Newcomb
4713e25ab0
Cleanup of while_let_on_iterator 2021-05-12 21:51:19 -04:00
Jason Newcomb
daca50a515
Improvements to while_let_on_iterator
* Suggest `&mut iter` when the iterator is used after the loop.
* Suggest `&mut iter` when the iterator is a field in a struct.
* Don't lint when the iterator is a field in a struct, and the struct is
used in the loop.
* Lint when the loop is nested in another loop, but suggest `&mut iter`
unless the iterator is from a local declared inside the loop.
2021-05-12 21:49:22 -04:00
Yoshitomo Nakanishi
8214bf0445 match_single_binding: Fix invalid suggestion when match scrutinee has side effects 2021-05-13 10:36:09 +09:00
xFrednet
b740a04dc4 Metadata collection collecting configuration deprecation reason 2021-05-12 18:47:32 +02:00
xFrednet
b03642e51f Metadata collection clarifying default configuration values 2021-05-12 17:31:00 +02:00
xFrednet
88ae2d1155 Metadata formatting the configuration section 2021-05-12 17:31:00 +02:00
xFrednet
210ec728e5 Metadata collection monster searching for configurations 2021-05-12 17:31:00 +02:00
Camille GILLOT
44c1ef8797 Use () for inherent_impls. 2021-05-12 13:58:44 +02:00
Camille GILLOT
c5a3f1c306 Use () for HIR queries. 2021-05-12 13:58:42 +02:00
bors
f019d28c72 Auto merge of #83813 - cbeuw:remap-std, r=michaelwoerister
Fix `--remap-path-prefix` not correctly remapping `rust-src` component paths and unify handling of path mapping with virtualized paths

This PR fixes #73167 ("Binaries end up containing path to the rust-src component despite `--remap-path-prefix`") by preventing real local filesystem paths from reaching compilation output if the path is supposed to be remapped.

`RealFileName::Named` introduced in #72767 is now renamed as `LocalPath`, because this variant wraps a (most likely) valid local filesystem path.

`RealFileName::Devirtualized` is renamed as `Remapped` to be used for remapped path from a real path via `--remap-path-prefix` argument, as well as real path inferred from a virtualized (during compiler bootstrapping) `/rustc/...` path. The `local_path` field is now an `Option<PathBuf>`, as it will be set to `None` before serialisation, so it never reaches any build output. Attempting to serialise a non-`None` `local_path` will cause an assertion faliure.

When a path is remapped, a `RealFileName::Remapped` variant is created. The original path is preserved in `local_path` field and the remapped path is saved in `virtual_name` field. Previously, the `local_path` is directly modified which goes against its purpose of "suitable for reading from the file system on the local host".

`rustc_span::SourceFile`'s fields `unmapped_path` (introduced by #44940) and `name_was_remapped` (introduced by #41508 when `--remap-path-prefix` feature originally added) are removed, as these two pieces of information can be inferred from the `name` field: if it's anything other than a `FileName::Real(_)`, or if it is a `FileName::Real(RealFileName::LocalPath(_))`, then clearly `name_was_remapped` would've been false and `unmapped_path` would've been `None`. If it is a `FileName::Real(RealFileName::Remapped{local_path, virtual_name})`, then `name_was_remapped` would've been true and `unmapped_path` would've been `Some(local_path)`.

cc `@eddyb` who implemented `/rustc/...` path devirtualisation
2021-05-12 11:05:56 +00:00
bors
aa15a5442a Auto merge of #7197 - xFrednet:4310-depreciated-lints-collection, r=flip1995
Metadata collection monster eating deprecated lints

This adds the collection of deprecated lints to the metadata collection monster. The JSON output has the same structure with the *new* lint group "DEPRECATED". Here is one of fourteen examples it was able to dig up in Clippy's code:

```JSON
  {
    "id": "assign_op_pattern",
    "id_span": {
      "path": "src/assign_ops.rs",
      "line": 34
    },
    "group": "clippy::style",
    "docs": " **What it does:** Checks for `a = a op b` or `a = b commutative_op a` patterns.\n\n **Why is this bad?** These can be written as the shorter `a op= b`.\n\n **Known problems:** While forbidden by the spec, `OpAssign` traits may have\n implementations that differ from the regular `Op` impl.\n\n **Example:**\n ```rust\n let mut a = 5;\n let b = 0;\n // ...\n // Bad\n a = a + b;\n\n // Good\n a += b;\n ```\n",
    "applicability": {
      "is_multi_part_suggestion": false,
      "applicability": "MachineApplicable"
    }
  }
```

And you! Yes you! Sir or Madam can get all of this **for free** in Clippy if this PR gets merged. (Sorry for the silliness ^^)

---

See: #7172 for the full metadata collection to-do list or to suggest a new feature in connection to it 🙃

---

changelog: none

r? `@flip1995`
2021-05-12 08:01:10 +00:00