Commit graph

6156 commits

Author SHA1 Message Date
Cameron Steffen
ee79077d80 Use break api config for pass by value or ref 2021-05-26 16:53:13 -05:00
Cameron Steffen
d7f47f280e Use break api config for wrong_pub_self_convention 2021-05-26 16:53:13 -05:00
Cameron Steffen
2e2021bbda Add avoid_breaking_exported_api config option 2021-05-26 16:35:22 -05:00
Cameron Steffen
c21b965d43 Fix missing_docs_in_private_items FP 2021-05-26 16:25:38 -05:00
Cameron Steffen
5cc6635fcf Add macro_use clippy_utils 2021-05-26 16:11:18 -05:00
mbartlett21
bcebea65c1 Run cargo fmt 2021-05-25 06:05:52 +00:00
mbartlett21
9cad27fce8 Add semicolon in needless_for_each.rs 2021-05-25 02:06:45 +00:00
mbartlett21
6d73777224 Fix same_item_push.rs 2021-05-25 02:03:31 +00:00
mbartlett21
527fb42a32 Add all the semicolons to clippy_lints 2021-05-25 01:46:33 +00:00
mbartlett21
cadad20da1 Add semicolons up to needless_for_each.rs 2021-05-25 00:54:50 +00:00
mbartlett21
1ac7e19b4c Move semicolon_if_nothing_returned to pedantic 2021-05-24 22:09:07 +00:00
Pietro Albini
91aa821745 remove cfg(bootstrap) 2021-05-24 11:07:48 -04:00
Cameron Steffen
24743b3968 Use UnhashMap 2021-05-24 09:48:05 -05:00
Michael Wright
2f78d57d8b Downgrade suspicious_op..._groupings to Nursery
This addresses #6722.
2021-05-24 06:44:38 +02:00
bors
41bb092185 Auto merge of #7255 - whatisaphone:feat/similar-names-wparam-lparam, r=giraffate
Allow wparam and lparam in similar_names

`wparam` and `lparam` are often used as generic parameter names in win32 (for example [WindowProc](https://docs.microsoft.com/en-us/previous-versions/windows/desktop/legacy/ms633573(v=vs.85))). This PR adds them to the similar_names exception list.

changelog: [`similar_names`] don't treat wparam and lparam as similar
2021-05-24 00:20:17 +00:00
bors
297e7433bf Auto merge of #7264 - yotamofek:from_iter_instead_collect_as_trait, r=llogiq
Fix invalid syntax in `from_iter_instead_of_collect` suggestion

First attempt at contributing, hopefully this is a good start and can be improved. :)

fixes #7259

changelog: [`from_iter_instead_of_collect`] fix invalid suggestion involving "as Trait"
2021-05-22 23:08:51 +00:00
bors
87871864b3 Auto merge of #7263 - Jarcho:redundant_closure_macro, r=llogiq
Fix `redundant_closure` for `vec![]` macro in a closure with arguments

fixes: #7224
changelog: Fix `redundant_closure` for `vec![]` macro in a closure with arguments
2021-05-22 21:41:08 +00:00
Yotam Ofek
ae0d4da764 Fix invalid syntax in from_iter_instead_of_collect suggestion with "as Trait" 2021-05-22 21:47:11 +03:00
Jason Newcomb
60dd2b65dc
Fix redundant_closure for vec![] macro in a closure with arguments 2021-05-21 15:48:29 -04:00
Jason Newcomb
7db0e4f791
Suggest &mut iter inside a closure for while_let_on_iterator 2021-05-21 12:27:40 -04:00
Jason Newcomb
f355aebf10
Move needless_borrow to style 2021-05-21 11:24:52 -04:00
John Simon
2eafec182d Allow wparam and lparam in similar_names 2021-05-20 10:20:14 -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
97705b7ea6 Merge commit '9e3cd88718cd1912a515d26dbd9c4019fd5a9577' into clippyup 2021-05-20 13:07:57 +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
Aaron Hill
ab73020d40 Implement span quoting for proc-macros
This PR implements span quoting, allowing proc-macros to produce spans
pointing *into their own crate*. This is used by the unstable
`proc_macro::quote!` macro, allowing us to get error messages like this:

```
error[E0412]: cannot find type `MissingType` in this scope
  --> $DIR/auxiliary/span-from-proc-macro.rs:37:20
   |
LL | pub fn error_from_attribute(_args: TokenStream, _input: TokenStream) -> TokenStream {
   | ----------------------------------------------------------------------------------- in this expansion of procedural macro `#[error_from_attribute]`
...
LL |             field: MissingType
   |                    ^^^^^^^^^^^ not found in this scope
   |
  ::: $DIR/span-from-proc-macro.rs:8:1
   |
LL | #[error_from_attribute]
   | ----------------------- in this macro invocation
```

Here, `MissingType` occurs inside the implementation of the proc-macro
`#[error_from_attribute]`. Previosuly, this would always result in a
span pointing at `#[error_from_attribute]`

This will make many proc-macro-related error message much more useful -
when a proc-macro generates code containing an error, users will get an
error message pointing directly at that code (within the macro
definition), instead of always getting a span pointing at the macro
invocation site.

This is implemented as follows:
* When a proc-macro crate is being *compiled*, it causes the `quote!`
  macro to get run. This saves all of the sapns in the input to `quote!`
  into the metadata of *the proc-macro-crate* (which we are currently
  compiling). The `quote!` macro then expands to a call to
  `proc_macro::Span::recover_proc_macro_span(id)`, where `id` is an
opaque identifier for the span in the crate metadata.
* When the same proc-macro crate is *run* (e.g. it is loaded from disk
  and invoked by some consumer crate), the call to
`proc_macro::Span::recover_proc_macro_span` causes us to load the span
from the proc-macro crate's metadata. The proc-macro then produces a
`TokenStream` containing a `Span` pointing into the proc-macro crate
itself.

The recursive nature of 'quote!' can be difficult to understand at
first. The file `src/test/ui/proc-macro/quote-debug.stdout` shows
the output of the `quote!` macro, which should make this eaier to
understand.

This PR also supports custom quoting spans in custom quote macros (e.g.
the `quote` crate). All span quoting goes through the
`proc_macro::quote_span` method, which can be called by a custom quote
macro to perform span quoting. An example of this usage is provided in
`src/test/ui/proc-macro/auxiliary/custom-quote.rs`

Custom quoting currently has a few limitations:

In order to quote a span, we need to generate a call to
`proc_macro::Span::recover_proc_macro_span`. However, proc-macros
support renaming the `proc_macro` crate, so we can't simply hardcode
this path. Previously, the `quote_span` method used the path
`crate::Span` - however, this only works when it is called by the
builtin `quote!` macro in the same crate. To support being called from
arbitrary crates, we need access to the name of the `proc_macro` crate
to generate a path. This PR adds an additional argument to `quote_span`
to specify the name of the `proc_macro` crate. Howver, this feels kind
of hacky, and we may want to change this before stabilizing anything
quote-related.

Additionally, using `quote_span` currently requires enabling the
`proc_macro_internals` feature. The builtin `quote!` macro
has an `#[allow_internal_unstable]` attribute, but this won't work for
custom quote implementations. This will likely require some additional
tricks to apply `allow_internal_unstable` to the span of
`proc_macro::Span::recover_proc_macro_span`.
2021-05-12 00:51:31 -04:00
Arya Kumar
5ba236f303 added needless_bitwise_bool lint 2021-05-11 19:34:14 +00:00
Fridtjof Stoldt
a988a90e11 Update clippy_lints/src/deprecated_lints.rs
Co-authored-by: Philipp Krones <hello@philkrones.com>
2021-05-11 18:33:51 +02:00
xFrednet
d849e9586e Metadata collection monster eating deprecated lints 2021-05-09 21:58:31 +02:00
William Chargin
1b2ca3067e Move inconsistent_struct_constructor to pedantic
The whole point of named fields is that we don't have to worry about
order. The names, not the position, communicate the information, so
worrying about consistency for consistency's sake is pedantic to a *T*.

Fixes #7192.

wchargin-branch: inconsistent-struct-constructor-pedantic
wchargin-source: 4fe078a21c77ceb625e58fa3b90b613fc4fa6a76
2021-05-07 20:24:07 -07:00
bors
65951c969f Auto merge of #7165 - camsteffen:question-mark, r=Manishearth
Fix needless_quesiton_mark false positive

changelog: Fix [`needless_question_mark`] false positive where the inner value is implicity dereferenced by the question mark.

Fixes #7107
2021-05-08 00:04:14 +00:00
Mateusz Gacek
171789eb45 needless_collect: Lint LinkedList and BinaryHeap in direct usage.
Those two types are supported already when used indirectly.
This commit adds support for direct usage as well.
2021-05-07 09:00:51 -07:00
Mateusz Gacek
59ccc1efb3 needless_collect: replace paths with diag items
Related to: #5393
2021-05-07 08:40:48 -07:00
Mateusz Gacek
a21607d9b5 needless_collect: For BTreeMap and HashMap lint only is_empty
- `len` might produce different results than `count`
- they don't have `contain` but `contains_key` method
2021-05-07 08:39:00 -07:00
bors
af8cf9444c Auto merge of #7183 - th1000s:write_nl_hint, r=flip1995
Handle write!(buf, "\n") case better

Make `write!(buf, "\n")` suggest `writeln!(buf)` by removing
the trailing comma from `writeln!(buf, )`.

changelog: [`write_with_newline`] suggestion on only "\n" improved
2021-05-07 12:13:35 +00:00
Thomas Otto
5f3aae61af Handle write!(buf, "\n") case better
Make `write!(buf, "\n")` suggest `writeln!(buf)` by removing
the trailing comma from `writeln!(buf, )`.

changelog: [`write_with_newline`] suggestion on only "\n" improved
2021-05-07 00:53:13 +02:00
Scott McMurray
300f628111 Fix clippy 2021-05-06 11:37:45 -07:00
Mateusz Gacek
ab3094b3db wrong_self_convention: For to_* variant don't lint in trait impl taking self when non-Copy type
It relaxes rules for `to_*` variant, so it doesn't lint in trait definitions
and implementations anymore.
Although, non-`Copy` type implementing trait's `to_*` method taking
`self` feels not good (consumes ownership, so should be rather named `into_`), it would be better if this case was a pedantic lint (allow-by-default) instead.
2021-05-06 10:49:31 -07:00
flip1995
d605882023 Merge commit 'b71f3405606d49b9735606b479c3415a0ca9810f' into clippyup 2021-05-06 12:20:44 +02:00
flip1995
d481b38634
Bump Clippy version -> 0.1.54 2021-05-06 11:32:34 +02:00
flip1995
767cc7cd89
Merge remote-tracking branch 'upstream/master' into rustup 2021-05-06 11:32:03 +02:00
bors
796a6f00e1 Auto merge of #7177 - giraffate:add_a_missing_lint_to_msrv_config_doc, r=flip1995
Add a missing lint to MSRV config doc

A follow-up of https://github.com/rust-lang/rust-clippy/pull/6859.

changelog: Add a missing lint to MSRV config doc
2021-05-06 08:43:36 +00:00
bors
7191675ab1 Auto merge of #7166 - TaKO8Ki:refactor_misc_early_module, r=llogiq
Refactor: arrange lints in misc_early module

This PR arranges misc_early lints so that they can be accessed more easily.
Basically, I refactored them following the instruction described in #6680.

cc: `@Y-Nak,` `@flip1995,` `@magurotuna`

changelog: Move lints in misc_early module into their own modules.
2021-05-06 07:46:52 +00:00
Takayuki Nakata
b8046fab23 Add a missing lint to MSRV config doc 2021-05-06 14:04:50 +09:00
bors
9dd87051c7 Auto merge of #7175 - camsteffen:filter-map-none, r=Manishearth
Fix unnecessary_filter_map false positive

changelog: Fix an [`unnecessary_filter_map`] false positive

Fixes #6804
2021-05-05 22:57:05 +00:00
Cameron Steffen
d66d37303c Fix unnecessary_filter_map false positive 2021-05-05 16:44:00 -05:00
bors
93fe3562d0 Auto merge of #7174 - camsteffen:eval-order-async, r=flip1995
Fix eval_order_dependence async false positive

changelog: Fix [`eval_order_dependence`] false positive in async code

Fixes #6925
2021-05-05 21:18:05 +00:00
Cameron Steffen
7a7b8bd3e8 Fix eval_order_dependence async false positive 2021-05-05 15:08:44 -05:00
Cameron Steffen
2b38399920 Improve eval_order_dependence output 2021-05-05 15:03:14 -05:00
bors
182a1853c3 Auto merge of #7170 - flip1995:revert_drop_order, r=llogiq
Fix stack overflow issue in `redundant_pattern_matching`

Fixes #7169

~~cc `@Jarcho` Since tomorrow is release day and we need to get this also fixed in beta, I'll just revert the PR instead of looking into the root issue. Your changes are good, so if you have an idea what could cause this stack overflow and know how to fix it, please open a PR that reverts this revert with a fix.~~

r? `@llogiq`

changelog: none (fixes stack overflow, but this was introduced in this release cycle)
2021-05-05 17:33:46 +00:00
xFrednet
e0eb29c936 Applying PR suggestions (mostly typos)
Co-authored-by: flip1995 <hello@philkrones.com>
Co-authored-by: phansch <dev@phansch.net>
2021-05-05 18:58:57 +02:00
xFrednet
62cafe2c02 Applying PR suggestions 2021-05-05 18:38:26 +02:00
xFrednet
c1fa1102d4 ENABLE_METADATA_COLLECTION env-value to disable default metadata collection 2021-05-05 18:38:26 +02:00
xFrednet
4fc960301b Metadata collection: Rounding up the implementation 2021-05-05 18:38:26 +02:00
xFrednet
35844d0a48 Metadata collection: Resolve lint from locals 2021-05-05 18:35:33 +02:00
xFrednet
2ce5e368d8 Metadata collection: Refining the implementation 2021-05-05 18:35:33 +02:00
xFrednet
6658db1044 Metadata collection: processing emission closures (417/455) 2021-05-05 18:35:33 +02:00
xFrednet
5830fa7c60 Metadata Collection: Collecting direct emission applicabilities (324/455) 2021-05-05 18:35:33 +02:00
xFrednet
ee8a99a114 Metadata collection: Collecting Applicability assign values 2021-05-05 18:35:33 +02:00
xFrednet
a39912cfbb Metadata collection: Some refactoring for readability 2021-05-05 18:35:33 +02:00
xFrednet
ee130d066d Metadata collection: Tracking Applicability mut borrows 2021-05-05 18:35:33 +02:00
xFrednet
8dca1b8f61 Metadata collection: Collecting Applicability assign values 2021-05-05 18:35:33 +02:00
xFrednet
68d702f88d Metadata collection lint: Start Applicability value tracking 2021-05-05 18:35:33 +02:00
xFrednet
060e0e9f93 Metadata collection lint: Basic applicability collection 2021-05-05 18:35:33 +02:00
xFrednet
637751ff62 Metadata collection lint: Basic lint collection
WIP-2021-02-01

WIP-2021-02-01

WIP-2021-02-13
2021-05-05 18:34:24 +02:00
bors
0baf6bf226 Auto merge of #7163 - mgacek8:issue7110_needless_collect_with_type_annotations, r=flip1995
needless_collect: Lint cases with type annotations for indirect usage and recognize `BinaryHeap`

fixes #7110
changelog: needless_collect: Lint cases with type annotations for indirect usage and recognize `BinaryHeap`.
2021-05-05 15:43:02 +00:00
Andy Wang
53ffe39b42 Use local and remapped paths where appropriate 2021-05-05 15:31:28 +01:00
Cameron Steffen
344f04bea6
Fix stack overflow in redundant_pattern_matching 2021-05-05 16:12:39 +02:00
Mateusz Gacek
f79a2a3990 needless_collect: use node_type_opt instead of node_type
It may prevent future ICEs.
2021-05-05 04:52:03 -07:00
Cameron Steffen
83329ec705 Fix unused_unit macro false positive 2021-05-04 17:20:33 -05:00
Takayuki
3fbb060379 replace lit_snip type with &str 2021-05-05 06:53:04 +09:00
Takayuki
2dfb246d8e refactor unseparated_literal_suffix 2021-05-05 06:39:38 +09:00
Cameron Steffen
919ed2ba03 Fix needless_quesiton_mark false positive 2021-05-04 16:28:13 -05:00
Takayuki
b1567f4466 move zero_prefixed_literal to its own module 2021-05-05 06:18:58 +09:00
Mateusz Gacek
1835d8a238 needless_collect: Add BinaryHeap for indirect usage lint 2021-05-04 12:38:30 -07:00
Mateusz Gacek
b1faaaeb0c needless_collect: Lint cases with type annotations 2021-05-04 12:38:30 -07:00
Takayuki
0773d8afdb move mixed_case_hex_literals to its own module 2021-05-05 02:21:26 +09:00
Takayuki
f012e0e3de move unseparated_literal_suffix to its own module 2021-05-05 02:10:24 +09:00
Takayuki
829fde5e1f move unneeded_field_pattern to its own module 2021-05-05 01:44:38 +09:00
flip1995
0854f0caee
Don't trigger field_reassign_with_default in macros
Producing a good suggestion for this lint is already hard when no macros
are involved. With macros the lint message and the suggestion are just
confusing. Since both, producing a good suggestion and figuring out if
this pattern can be re-written inside a macro is nearly impossible, just
bail out.
2021-05-04 16:48:43 +02:00
Takayuki
c0a106e252 move unneeded_wildcard_pattern to its own module 2021-05-04 19:50:48 +09:00
Takayuki
52cfde0586 move redundant_pattern to its own module 2021-05-04 17:28:32 +09:00
Takayuki
55af0cee15 move double_neg to its own module 2021-05-04 17:20:22 +09:00
Takayuki
64eb18e675 move builtin_type_shadow to its own module 2021-05-04 17:04:10 +09:00
Takayuki
91a8611b44 move misc_early to misc_early/mod.rs 2021-05-04 16:38:34 +09:00
bors
5e3160ca0b Auto merge of #7156 - hellow554:single_char_strip, r=flip1995
[single_char_pattern] add strip_prefix and strip_suffix

Title says it all. Adjusted ui tests.

I added the second commit in case you don't like that I moved that table into `single_char_pattern.rs` directly. I don't see any reason why it shouldn't be in that file. It isn't used anywhere else.

*Please write a short comment explaining your change (or "none" for internal only changes)*

changelog: add strip_prefix and strip_suffix to single_char_pattern lint
2021-05-03 14:44:44 +00:00
Marcel Hellwig
19e7448c7f move PATTERN_METHODS table directly into file
also removed rustfmt::skip
2021-05-03 16:25:05 +02:00
Marcel Hellwig
c080899848 add strip_{prefix,suffix} to PATTERN_METHODS
this will warn, if a single_char_pattern is used in one of the above
methods
2021-05-03 16:18:41 +02:00
Cameron Steffen
499813026f Fix config parsing 2021-05-02 17:50:22 -05:00
Cameron Steffen
857d9f15da Fix error punctuation 2021-05-02 16:56:46 -05:00
Cameron Steffen
1e22e564e4 Refactor config deserialization 2021-05-01 17:38:05 -05:00
Cameron Steffen
b9c8e683d6 Disable default_trait_access in macros 2021-05-01 16:16:32 -05:00
bors
a300b0e66c Auto merge of #7144 - rust-lang:while_immutable_mut_cond, r=flip1995
while_immutable_cond: check condition for mutation

This fixes #6689 by also checking the bindings mutated in the condition, whereas it was previously only checked in the loop body.

---

changelog: Fix FP in [`while_immutable_cond`] where mutation in the loop variable wasn't picked up.
2021-04-30 15:08:27 +00:00
bors
5e49c4bd67 Auto merge of #6951 - Jarcho:implicit_return_fp, r=flip1995
`implicit_return` improvements

fixes: #6940

changelog: Fix `implicit_return` suggestion for async functions
changelog: Improve `implicit_return` suggestions when returning the result of a macro
changelog: Check for `break` expressions inside a loop which are then implicitly returned
changelog: Allow all diverging functions in `implicit_return`, not just panic functions
2021-04-30 14:55:56 +00:00
bors
14f1551075 Auto merge of #7118 - TaKO8Ki:fix-false-positive-in-comparison-chain, r=giraffate
Fix a false-positive inside const fn in `comparison_chain`

closes https://github.com/rust-lang/rust-clippy/issues/7082

changelog: fix a false-positive inside const fn in [`comparison_chain`]
2021-04-30 06:30:38 +00:00
Takayuki
0dff377a62 use in_constant 2021-04-30 14:40:35 +09:00
bors
a55912c48e Auto merge of #7141 - camsteffen:conf-file, r=flip1995
Remove leftover plugin conf_file code

changelog: none

Removes dead code that used to support the following syntax:

```rust
#![plugin(clippy(conf_file="path/to/clippy's/configuration"))]
```

RLS (and others?) will need to remove the `&[]` from `clippy_lints::read_conf(&[], sess)`.

r? `@flip1995`
2021-04-29 14:57:24 +00:00
Andre Bogus
63425de77d while_immutable_cond: check condition for mutation 2021-04-29 10:10:58 +02:00
Jack Huey
cd88031ce5 Rollup merge of #84484 - jyn514:check-tools, r=Mark-Simulacrum
Don't rebuild rustdoc and clippy after checking bootstrap

This works by unconditionally passing -Z unstable-options to the
compiler. This has no affect in practice since bootstrap doesn't use
`deny(rustc::internal)`.

Fixes https://github.com/rust-lang/rust/issues/82461.

r? ```@Mark-Simulacrum```
2021-04-28 22:59:22 -04:00
Cameron Steffen
32351d6b9f Remove leftover plugin conf_file code 2021-04-28 16:04:59 -05:00
Matthias Krüger
572c405da0 fix ice when checking rustc libstd
thread 'rustc' panicked at 'index out of bounds: the len is 0 but the index is 0', src/tools/clippy/clippy_lints/src/matches.rs:1595:53
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

I don't have a minimised testcase because I don't have time to reduce libstd down to a few lines right now.
2021-04-27 23:16:19 +02:00
Joshua Nelson
f4bd12cfde Switch rustc::internal from deny to warn
These should still obey deny-warnings.
2021-04-27 13:00:36 -04:00
flip1995
ae72f1adb9 Merge commit '7c7683c8efe447b251d6c5ca6cce51233060f6e8' into clippyup 2021-04-27 16:55:11 +02:00