Commit graph

6325 commits

Author SHA1 Message Date
Steven Engler
58491d386a Update message for 'not_unsafe_ptr_arg_deref' lint 2021-05-30 20:19:57 -04:00
bors
d1308aecaf Auto merge of #7292 - Jarcho:suspicious_splitn, r=flip1995
Add lint `suspicious_splitn`

fixes: #7245
changelog: Add lint `suspicious_splitn`
2021-05-30 20:32:22 +00:00
Jason Newcomb
5fa08eaf53
Evaluate constant expressions in suspicious_splitn 2021-05-30 13:25:24 -04:00
Jason Newcomb
898b6a0e07
Add lint suspicious_splitn 2021-05-30 09:49:55 -04:00
Jason Newcomb
4ba6afd192
Fix ICE in too_many_lines due to wrong assumptions on braces. 2021-05-27 22:44:08 -04:00
Cameron Steffen
21c829e0c8 Simplify collect expr_ty 2021-05-27 20:54:56 -05:00
Cameron Steffen
6c1ba7c1bc Fix needless_collect with binding shadowing 2021-05-27 20:39:59 -05:00
Cameron Steffen
29b4b4c10d Do not lint use_self on type parameters 2021-05-27 20:18:07 -05:00
Cameron Steffen
d3c20c835f Some cleanup for use_self 2021-05-27 16:25:17 -05:00
Cameron Steffen
d39a11cbe1 Remove clippy_utils::consts re-export 2021-05-27 08:52:10 -05:00
bors
2fa9362448 Auto merge of #7281 - camsteffen:has-doc-fp, r=flip1995
Fix missing_docs_in_private_items false negative

changelog: Fix [`missing_docs_in_private_items`] false negative when the item has any `#[name = "value"]` attribute

Closes #7247 (decided not to use the rustc method since it calls `Session::check_name`, which is for rustc only)
2021-05-27 08:37:08 +00:00
bors
8066f836ec Auto merge of #7282 - camsteffen:lint-stmt-expr, r=flip1995
Fix allow on some statement lints

changelog: Fix `#[allow(..)]` over statements for [`needless_collect`], [`short_circuit_statement`] and [`unnecessary_operation`]

Fixes #7171
Fixes #7202
2021-05-27 08:23:21 +00:00
bors
9c4651f2ee Auto merge of #7187 - camsteffen:avoid-break-exported, r=flip1995,phansch
Add avoid_breaking_exported_api config option

changelog: Add `avoid_breaking_exported_api` config option for [`enum_variant_names`], [`large_types_passed_by_value`], [`trivially_copy_pass_by_ref`], [`unnecessary_wraps`], [`upper_case_acronyms`] and [`wrong_self_convention`].

changelog: Deprecates [`pub_enum_variant_names`] and [`wrong_pub_self_convention`] as the non-pub variants are now configurable.

changelog: Fix various false negatives for `pub` items that are not exported from the crate.

A couple changes to late passes in order to use `cx.access_levels.is_exported` rather than `item.vis.kind.is_pub`.

I'm not sure how to better document the config option or lints that are (not) affected (see comments in #6806). Suggestions are welcome. cc `@rust-lang/clippy`

I added `/clippy.toml` to use the config internally and `/tests/clippy.toml` to maintain a default config in ui tests.

Closes #6806
Closes #4504
2021-05-27 04:49:56 +00:00
Cameron Steffen
f3e77a454a Fix allow on some statement lints 2021-05-26 22:07:53 -05:00
Cameron Steffen
6eea598645 Fix config file lookup 2021-05-26 21:53:43 -05:00
bors
f205dd176a Auto merge of #7280 - camsteffen:macro-use, r=Manishearth
Add macro_use clippy_utils

changelog: none
2021-05-26 22:15:07 +00:00
Cameron Steffen
55ccc7a8c6 Use break api config for upper_case_acronyms 2021-05-26 16:53:13 -05:00
Cameron Steffen
1ce581d706 Use break api config for unnecessary_wraps 2021-05-26 16:53:13 -05:00
Cameron Steffen
3d77a2b861 Use break api config for enum_variant_names 2021-05-26 16:53:13 -05:00
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
bors
9af07e65aa Auto merge of #7138 - mgacek8:issue6808_iter_cloned_collect_FN_with_large_array, r=Manishearth
Fix FN in `iter_cloned_collect` with a large array

fixes #6808
changelog: Fix FN in `iter_cloned_collect` with a large array

I spotted that [is_iterable_array](a362a4d1d0/clippy_lints/src/loops/explicit_iter_loop.rs (L67-L75)) function that `explicit_iter_loop` lint is using only works for array sizes <= 32.
There is this comment:
> IntoIterator is currently only implemented for array sizes <= 32 in rustc

I'm a bit confused, because I read that [IntoIterator for arrays](https://doc.rust-lang.org/src/core/array/mod.rs.html#194-201) with const generic `N` is stable since = "1.0.0". Although Const Generics MVP were stabilized in Rust 1.51.

Should I set MSRV for the current change? I will try to test with older compilers soon.
2021-04-27 13:44:51 +00:00
bors
0a330e6824 Auto merge of #7136 - mgacek8:issue6965_manual_unwrap_or_invalid_sugg_macro_expansion, r=llogiq
manual_unwrap_or: fix invalid code suggestion, due to macro expansion

fixes #6965

changelog: fix invalid code suggestion in `manual_unwrap_or` lint, due to macro expansion
2021-04-26 21:39:40 +00:00
Cameron Steffen
340b570ea0 Refactor MSRV aliases 2021-04-26 16:07:48 -05:00
Cameron Steffen
33ed8b5b24 Remove needless_question_mark MSRV 2021-04-26 16:02:11 -05:00
Mateusz Gacek
d7627dcfc8 Fix FN in iter_cloned_collect with a large array 2021-04-26 13:03:51 -07:00
Mateusz Gacek
84003aa7a1 fix invalid code suggestion in manual_unwrap_or, due to macro expansion 2021-04-26 12:19:23 -07:00
bors
a362a4d1d0 Auto merge of #7134 - camsteffen:copied-msrv, r=Manishearth
Finish MSRV for cloned_instead_of_copied

changelog: none

r? `@Manishearth`
2021-04-26 16:12:04 +00:00
Cameron Steffen
dcf4e07458 Finish MSRV for cloned_instead_of_copied 2021-04-26 11:09:24 -05:00
bors
1bb3b12dfb Auto merge of #7132 - rust-lang:single_element_loop_iter, r=Manishearth
extend `single_element_loop` to match `.iter()`

This extends `single_element_loop` to also match `[..].iter()` in the loop argument. Related to #7125, but not completely fixing it due to the lint only firing if the array expression contains a local variable.

---

changelog: none
2021-04-26 14:28:31 +00:00
Andre Bogus
efc4c6c957 extend single_element_loop to match .iter() 2021-04-26 15:58:58 +02:00
Ralf Jung
f801d026f5 fix clippy 2021-04-25 17:05:48 +02:00
Cameron Steffen
3f5be5e235 Fix cloned_instead_of_copied MSRV 2021-04-25 09:54:04 -05:00
bors
74f55996fe Auto merge of #7120 - cherryblossom000:7106, r=Manishearth
`single_component_path_imports`: ignore `pub(crate) use some_macro;`

Fixes #7106

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

changelog: Ignore exporting a macro within a crate using `pub(crate) use some_macro;` for [`single_component_path_imports`]
2021-04-22 14:36:21 +00:00
bors
0ab7acc890 Auto merge of #7100 - ABouttefeux:unused_io_amount, r=camsteffen
Unused io amount detects `.read().ok()?`

fixes #7096
changelog: unused_io_amount now detect expertion like `.read().ok()?`,  `.read().or_else(|err| ...)?` and similar expressions.
2021-04-22 13:57:06 +00:00
Aliénore Bouttefeux
5625d58f9f add detection unused_io_amount of "or", "or_else" and "ok" 2021-04-22 15:52:42 +02:00
Jason Newcomb
3d793f3111
Minor cleanup of implicit_return 2021-04-22 09:36:49 -04:00
Jason Newcomb
74cf5f2fc6
Fix implicit_return suggestion for async functions 2021-04-22 09:36:32 -04:00
Jason Newcomb
22f8c13cf5
Improve implicit_return
Better suggestions when returning macro calls.
Suggest changeing all the break expressions in a loop, not just the final statement.
Don't lint divergent functions.
Don't suggest returning the result of any divergent fuction.
2021-04-22 09:13:06 -04:00
cherryblossom
b48699e4cf
single_component_path_imports: ignore pub(crate) use some_macro; (fixes #7106) 2021-04-22 19:34:36 +10:00
flip1995
02bf692169 Merge commit '98e2b9f25b6db4b2680a3d388456d9f95cb28344' into clippyup 2021-04-22 11:31:13 +02:00
bors
1f7aef336e Auto merge of #7102 - taralx:taralx-patch-1, r=flip1995
Switch transmute_ptr_to_ptr to "pedantic" class.

Per discussion in https://github.com/rust-lang/rust-clippy/issues/6372, this lint has significant false positives.

changelog: transmute_ptr_to_ptr defaults to "allow".
2021-04-22 08:26:14 +00:00
Takayuki
65778fa5e8 fix a false-positive inside const fn in comparison_chain 2021-04-22 16:58:12 +09:00
bors
79b9eb5371 Auto merge of #7072 - ebobrow:imports-ending-with-self, r=camsteffen
add unnecessary_self_imports lint

fixes #6552

changelog: add `unnecessary_self_imports` lint
2021-04-21 14:47:49 +00:00
Elliot Bobrow
224881b94d add unnecessary_self_imports lint 2021-04-21 07:17:42 -07:00
bors
bbc22e2ef3 Auto merge of #7083 - GuillaumeGomez:bool-assert-eq, r=camsteffen
Add lint to check for boolean comparison in assert macro calls

This PR adds a lint to check if an assert macro is using a boolean as "comparison value". For example:

```rust
assert_eq!("a".is_empty(), false);
```

Could be rewritten as:

```rust
assert!(!"a".is_empty());
```

PS: The dev guidelines are amazing. Thanks a lot for writing them!

changelog: Add `bool_assert_comparison` lint
2021-04-21 13:58:53 +00:00
bors
ec38ea1ac1 Auto merge of #7097 - yawara:fix/7069, r=llogiq
Fixed inconsistent_struct_constructor triggers in macro-generated code

fixes #7069

changelog: `inconsistent_struct_constructor`: Fix FP in macro expansion.
2021-04-20 08:26:21 +00:00
Yawara ISHIDA
6eae905808 Add a test for FP in macro expansion 2021-04-20 13:34:30 +09:00
bors
b7c12f3aab Auto merge of #7092 - basavesh:fix#7066, r=giraffate
useless use of format! should return function directly

fixes #7066

changelog: [`useless_format`] wraps the content in the braces when it's needed.

r? `@giraffate`
2021-04-19 23:06:21 +00:00
Guillaume Gomez
e2e104b993 Add lint to check for boolean comparison in assert macro calls 2021-04-19 22:15:51 +02:00
Basavesh Shivakumar
c6b381c59b useless use of format! should return function directly 2021-04-19 17:20:21 +02:00
bors
fe5cefceba Auto merge of #7101 - camsteffen:flat-map-option, r=giraffate
Add flat_map_option lint

changelog: Add flat_map_option lint

Closes #2241
2021-04-19 13:34:23 +00:00
Andre Bogus
243dc46250 un-double return on try_err 2021-04-18 23:49:54 +02:00
JP Sugarbroad
8b5faf4ab0 Switch transmute_ptr_to_ptr to "pedantic" class.
Per discussion in https://github.com/rust-lang/rust-clippy/issues/6372, this lint has significant false positives.
2021-04-16 14:29:23 -07:00
bors
e441b33ba0 Auto merge of #7099 - ABouttefeux:master, r=llogiq
add type in help message of from_over_into

fixes #7088
changelog: add type in help message of from_over_into
2021-04-16 21:22:24 +00:00
Cameron Steffen
5af078ac1b Add flat_map_option lint 2021-04-16 15:23:49 -05:00
bors
831c15737c Auto merge of #7087 - Jarcho:allman_style_else, r=camsteffen
Allow allman style braces in `suspicious_else_formatting`

fixes: #3864

Indentation checks could be added as well, but the lint already doesn't check for it.

changelog: Allow allman style braces in `suspicious_else_formatting`
2021-04-16 20:16:52 +00:00
Jason Newcomb
559deddb3b
Allow allman style braces in suspicious_else_formatting 2021-04-16 15:24:46 -04:00
bors
eaf0f3df15 Auto merge of #7075 - xFrednet:7054-fp-branches-sharing-code, r=camsteffen,flip1995
Fixing FPs for the `branches_sharing_code` lint

Fixes #7053
Fixes #7054
And an additional CSS adjustment to support dark mode for every inline code. It currently only works in paragraphs, which was an oversight on my part 😅. [Current Example](https://rust-lang.github.io/rust-clippy/master/index.html#blacklisted_name)

This also includes ~50 lines of doc comments and is therefor not as big as the changes would indicate. 🐧

---

changelog: none

All of these bugs were introduced in this dev version and are therefor not worth a change log entry.

r? `@phansch`
cc: `@camsteffen` since you have a pretty good overview of the `SpanlessEq` implementation 🙃
2021-04-16 18:33:45 +00:00
Aliénore Bouttefeux
2d050f4b2f add type in help of from over Into 2021-04-16 19:38:01 +02:00
bors
28dbcd85c8 Auto merge of #7098 - camsteffen:cloned-copied, r=Manishearth
Add `cloned_instead_of_copied` lint

Don't go cloning all willy-nilly.

Featuring a new `get_iterator_item_ty` util!

changelog: Add cloned_instead_of_copied lint

Closes #3870
2021-04-16 17:32:13 +00:00
bors
7f2068cc2b Auto merge of #6568 - Jarcho:redundant_pattern_matching, r=flip1995
Fix: redundant_pattern_matching drop order

Fixes #5746

A note about the change in drop order is added when the scrutinee (or any temporary in the expression) isn't known to be safe to drop in any order (i.e. doesn't implement the `Drop` trait, or contain such a type). There is a whitelist for some `std` types, but it's incomplete. Currently just `Vec<_>`, `Box<_>`, `Rc<_>` and `Arc<_>`, but only if the contained type is also safe to drop in any order.

Another lint for when the drop order changes could be added as allowed by default, but the drop order requirement is pretty subtle in this case. I think the note added to the lint should be enough to make someone think before applying the change.

changelog: Added a note to `redundant_pattern_matching` when the change in drop order might matter
2021-04-16 16:45:59 +00:00
Cameron Steffen
b049c88fbe Eat dogfood 2021-04-16 11:39:31 -05:00
Cameron Steffen
0462666c70 Add cloned_instead_of_copied lint 2021-04-16 11:39:31 -05:00
Yawara ISHIDA
61230f4cb8 Fixed incosistent_struct_constructor triggers in macro-generated code 2021-04-16 22:50:04 +09:00
bors
1e0a3ff55c Auto merge of #6937 - Jarcho:map_entry_suggestion, r=giraffate
Improve `map_entry` suggestion

fixes: #5176
fixes: #4674
fixes: #4664
fixes: #1450

Still need to handle the value returned by `insert` correctly.

changelog: Improve `map_entry` suggestion. Will now suggest `or_insert`, `insert_with` or `match _.entry(_)` as appopriate.
changelog: Fix `map_entry` false positives where the entry api can't be used. e.g. when the map is used for multiple things.
2021-04-16 13:23:23 +00:00
bors
ddc2598230 Auto merge of #7093 - Jarcho:single_match_fp, r=llogiq
Fix `single_match`

fixes: #7038
changelog: Don't suggest an equality check for types which don't implement `PartialEq` in `single_match`
2021-04-16 06:44:26 +00:00
bors
faa97568a0 Auto merge of #7085 - Jarcho:manual_map_autoderef, r=giraffate
Don't allow adjustments for `manual_map`

fixes: #7077

The other option here would be to add the return type to the closure. It would be fine for simple types, but longer types can be rather unwieldy. Could also implement the adjustment manually.

changelog: Don't lint `manual_map` when type adjustments are added. e.g. autoderef
2021-04-16 03:05:52 +00:00
Jason Newcomb
9a55c0c176
Fix single_match
Check for `PartialEq` in addition to `StructuralPartialEq` before suggesting `==`
2021-04-15 22:09:20 -04:00
Jason Newcomb
c02baba1dc
redundant_pattern_matching fix inverted boolean when missing Drop trait # Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # # Date: Fri Apr 2 19:04:45 2021 -0400 # # On branch redundant_pattern_matching # Your branch is ahead of 'origin/redundant_pattern_matching' by 1 commit. # (use "git push" to publish your local commits) # # Changes to be committed: # modified: clippy_lints/src/matches.rs # # Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # # Date: Fri Apr 2 19:04:45 2021 -0400 # # interactive rebase in progress; onto ebc64690d # Last commands done (6 commands done): # pick 25d211ad8 Code cleanup and additional std types checked # r 0c71ce56f redundant_pattern_matching fix inverted boolean when missing Drop trait # No commands remaining. # You are currently editing a commit while rebasing branch 'redundant_pattern_matching' on 'ebc64690d'. # # Changes to be committed: # modified: clippy_lints/src/matches.rs # 2021-04-15 20:37:20 -04:00
Jason Newcomb
b6581636bd
Improve redundant_pattern_matching
Add a note when the drop order change may result in different behaviour.
2021-04-15 20:37:15 -04:00
bors
586a99348c Auto merge of #7049 - Jarcho:remove_match_path, r=camsteffen
Remove `match_path` and `match_qpath`

The only remaining usage is the `author` lint, so the functions are left in for now. The test result for `repl_uninit` changed, the lint was broken before.

The `collapsible_span_lint_calls` and `match_type_on_diag_item` tests have been changed. Both lints were broken when utils was extracted into it's own crate. `match_type_on_diag_item` isn't quite fixed, but it's at least less broken.

changelog: None
2021-04-15 23:54:41 +00:00
Jason Newcomb
f6c5d8d599
Remove all usages of match_path, match_qpath and match_path_ast except the author lint.
Add note to fix `MATCH_TYPE_ON_DIAG_ITEM`
Add false negative test for `uninit_assumed_init`
2021-04-15 19:27:25 -04:00
Cameron Steffen
014bf4390c Add note for pre-expansion passes 2021-04-15 12:57:31 -05:00
Jason Newcomb
779d98f6cc
Don't allow adjustments for manual_map 2021-04-15 10:37:42 -04:00
Jason Newcomb
bcf3488007
Minor cleanup of map_entry and a few additional tests. 2021-04-15 08:25:24 -04:00
Jason Newcomb
3323ff7145
map_entry improvements
Suggest using `or_insert_with` when possible
2021-04-15 08:22:40 -04:00
Jason Newcomb
b63a5b56d6
map_entry improvements
Lint `if _.[!]contains_key(&_) { .. } else { .. }` so long as one of the branches contains an insertion.
2021-04-15 08:19:59 -04:00
Jason Newcomb
ce5e927713
Improve map_entry lint
Fix false positives where the map is used before inserting into the map.
Fix false positives where two insertions happen.
Suggest using `if let Entry::Vacant(e) = _.entry(_)` when `or_insert` might be a semantic change
2021-04-15 08:19:40 -04:00
xFrednet
0b4af7257d PR suggestions and removing utils::parent_node_is_if_expr 2021-04-14 20:11:08 +02:00
xFrednet
2992b19c82 Added inferred local type comparion to SpanlessEq 2021-04-14 20:06:26 +02:00
xFrednet
cbde4f2c67 parent_node_is_if_expr now also recognizes if let as parent if 2021-04-14 20:06:26 +02:00
bors
24921df7bd Auto merge of #7039 - phansch:melt-ice, r=flip1995
tabs_in_doc_comments: Fix ICE due to char indexing

This is a quick-fix for an ICE in `tabs_in_doc_comments`. The problem
was that we we're indexing into possibly multi-byte characters, such as '位'.

More specifically `get_chunks_of_tabs` was returning indices into
multi-byte characters. Those were passed on to a `Span` creation that
then caused the ICE.

This fix makes sure that we don't return indices that point inside a
multi-byte character. *However*, we are still iterating over unicode
codepoints, not grapheme clusters. So a seemingly single character like y̆ ,
which actually consists of two codepoints, will probably still cause
incorrect spans in the output. But I don't think we handle those cases
anywhere in Clippy currently?

Fixes #5835

changelog: Fix ICE in `tabs_in_doc_comments`
2021-04-14 04:53:24 +00:00
bors
19740d9334 Auto merge of #7076 - rail-rain:missing_const_for_fn, r=phansch
Fix a FP in `missing_const_for_fn`

where a function that calls a standard library function whose constness
is unstable is considered as being able to be a const function. Fixes #5995.

The core change is the move from `rustc_mir::const_eval::is_min_const_fn` to `rustc_mir::const_eval::is_const_fn`. I'm not clear about the difference in their purpose between them so I'm not sure if it's acceptable to call `qualify_min_const_fn::is_min_const_fn` this way now.

---

changelog: `missing_const_for_fn`: No longer lints when an unstably const function is called
2021-04-14 04:39:25 +00:00
Philipp Hansch
cbdebd97ec Explain why we use char_indices() instead of chars() 2021-04-14 06:30:51 +02:00
rail
26a1989041 Fix a FP in missing_const_for_fn
where a function that calls a standard library function whose constness
is unstable is considered as being able to be a const function
2021-04-14 09:23:44 +12:00
Cameron Steffen
76bd5d232c Refactor diagnostic item methods 2021-04-13 14:10:40 -05:00
bors
e9728b80ce Auto merge of #7068 - boxdot:remove-std-ptr-null, r=camsteffen
Remove paths::STD_PTR_NULL

Related to #5393

changelog: none
2021-04-12 18:37:31 +00:00
bors
2a96bc434b Auto merge of #7067 - TaKO8Ki:fix-false-negative-on-needless-return, r=llogiq
Fix a false negative on `needless return`

closes #7042

changelog: fix a false negative on `needless return`
2021-04-12 18:00:38 +00:00
boxdot
d6beb18411
Remove paths::STD_PTR_NULL 2021-04-12 18:35:47 +02:00
bors
411c0df1d0 Auto merge of #7064 - ThibsG:WrongSelfFix, r=giraffate
Fix FP in `wrong_self_convention` lint

Previously, this lint didn't check into impl block when it was implementing a trait.
Recent improvements (#6924) have moved this check and some impl blocks are now checked but they shouldn't, such as in #7032.

Fixes #7032

changelog: Fix FP when not taking `self` in impl block for `wrong_self_convention` lint
2021-04-12 14:16:17 +00:00
Takayuki
53260df2fa fix a false negative on needless_return 2021-04-12 21:36:49 +09:00
bors
c3ef585328 Auto merge of #6982 - Jarcho:explicit_into_iter_loop_fp, r=flip1995
Fix `explicit_into_iter_loop`

fixes: #6900

changelog: Only lint when `into_iter` is an implementation of `IntoIterator`
2021-04-12 09:45:32 +00:00
bors
aecccbc579 Auto merge of #7047 - camsteffen:lang-ctor, r=flip1995
Introduce `is_lang_ctor`

changelog: none

Replaces `is_some_ctor` and `is_ok_ctor`. Removes many path usages.
2021-04-12 08:52:10 +00:00
bors
f0ceb28ba1 Auto merge of #7065 - rail-rain:warn_copy_pass_by_ref, r=Manishearth
Add a note on the issue #5953

Hello,

I thought it would be better to have a note and warning about this issue considering it introduced an UB in the past even with the "Search on Github" feature.

---

changelog: Add a note on the issue #5953 to the known problems section.
2021-04-12 04:38:42 +00:00
rail
fb54b703c7 Add a note on the issue #5953 2021-04-12 15:32:54 +12:00
bors
a6b514c603 Auto merge of #7059 - camsteffen:filter-map, r=flip1995
Deprecate `filter_map`

Since #6591, `filter_map` does not even lint `filter().map()`. The cases that are still linted make no sense IMO. So this just removes/deprecates it.

changelog: Deprecate `filter_map` lint

Closes #3424
Fixes #7050
2021-04-11 18:24:23 +00:00
bors
67fad0139f Auto merge of #6905 - ThibsG:fpSingleComponentPathImports5210, r=giraffate
Fix FP in `single_component_path_imports` lint

Fix FP in  `single_component_path_imports` lint when the import is reused with `self`, like in `use self::module`.

Fixes #5210

changelog: none
2021-04-11 14:18:38 +00:00
ThibsG
3ce6f0d022 Fix FP in wrong_self_convention lint 2021-04-11 13:29:08 +02:00
Cameron Steffen
a45faf66f3 Deprecate filter_map 2021-04-10 16:59:59 -05:00
daxpedda
cb14e7ebf4
Fix false-positive debug_assert in panic 2021-04-10 23:37:18 +02:00
daxpedda
271c163ba3
Fix false-positive debug_assert 2021-04-10 20:54:40 +02:00
daxpedda
43e6c656ba
Remove debug_assert from panic_in_result_fn 2021-04-10 17:38:04 +02:00
Philipp Hansch
47a4865406 Fix dogfood 2021-04-10 15:30:51 +02:00
Philipp Hansch
dde46c9340 Replace complex conditional with pattern matching 2021-04-10 14:42:33 +02:00
ThibsG
297e84f3f4 Handle imports which are nested directly 2021-04-10 10:26:53 +02:00
Joshua Nelson
012f9d47b2 Use register_renamed instead of register_removed for uplifted lints
This still applies the lint, and also adds a structured suggestion to
rename it.
2021-04-09 10:56:11 -04:00
bors
75efc144e7 Auto merge of #7023 - boxdot:invalid-null-usage-v2, r=camsteffen
Invalid null usage v2

This is continuation of #6192 after inactivity.

I plan to move paths into the compiler as diagnostic items after this is merged.

fixes #1703
changelog: none
2021-04-08 21:00:48 +00:00
boxdot
4f7fc11ef1
Add invalid null pointer usage lint. 2021-04-08 22:49:48 +02:00
bors
c40fa00113 Auto merge of #7022 - Jarcho:macro_use_import_ice, r=flip1995
Fix `macro_use_import` ICE

fixes: #7015
changelog: Fix `macro_use_import` ICE
2021-04-08 16:04:55 +00:00
flip1995
f6d1f368db Merge commit 'b40ea209e7f14c8193ddfc98143967b6a2f4f5c9' into clippyup 2021-04-08 17:50:13 +02:00
flip1995
ffa2b7da29
Merge remote-tracking branch 'upstream/master' into rustup 2021-04-08 17:36:41 +02:00
Cameron Steffen
7468542328 Introduce is_lang_ctor 2021-04-06 15:05:00 -05:00
Cameron Steffen
47f0c15f67 Symbol optimizations 2021-04-06 13:00:36 -05:00
Jason Newcomb
6b5778eb17
Fix explicit_into_iter_loop
Only lint when `into_iter` is an implementation of `IntoIterator`
Minor cleanups
2021-04-06 12:12:32 -04:00
Jason Newcomb
12fce55766
Fix all occurences of needless_borrow internally 2021-04-06 10:43:47 -04:00
bors
d2ba777159 Auto merge of #7036 - horacimacias:master, r=giraffate
consider mutability on useless_vec suggestions

fixes #7035

changelog: Now the suggested by `useless_vec` considers mutability to suggest either `&[]`, as before, or `&mut []` if the used reference is mutable.
2021-04-06 13:38:08 +00:00
Amanieu d'Antras
879bfeca54 Use AnonConst for asm! constants 2021-04-06 12:35:41 +01:00
Horaci Macias
8a50923da4 consider mutability on useless_vec suggestions
https://github.com/rust-lang/rust-clippy/issues/7035
2021-04-06 11:09:52 +02:00
Philipp Hansch
1573d10325
tabs_in_doc_comments: Fix ICE due to char indexing
This is a quick-fix for an ICE in `tabs_in_doc_comments`. The problem
was that we we're indexing into possibly multi-byte characters, such as '位'.

More specifically `get_chunks_of_tabs` was returning indices into
multi-byte characters. Those were passed on to a `Span` creation that
then caused the ICE.

This fix makes sure that we don't return indices that point inside a
multi-byte character. *However*, we are still iterating over unicode
codepoints, not grapheme clusters. So a seemingly single character like y̆ ,
which actually consists of two codepoints, will probably still cause
incorrect spans in the output.
2021-04-06 07:20:55 +02:00
bors
57406c93df Auto merge of #7018 - Y-Nak:same_item_push, r=Manishearth
Don't trigger `same_item_push` if the vec is used in the loop body

fixes #6987
changelog: `same_item_push`: Don't trigger if the `vec` is used in the loop body
2021-04-05 22:57:33 +00:00
bors
25c1ed38aa Auto merge of #7029 - ABouttefeux:master, r=Manishearth
fix `missing_panics_doc` not detecting `assert_eq!` and `assert_ne!`

fixes #6997
changelog: `missing_panics_doc` detects `assert_eq!` and `assert_ne!`

---
searching for `assert_eq!` and `assert_ne!` in `FindPanicUnwrap`
2021-04-05 19:14:55 +00:00
bors
d91da405df Auto merge of #6463 - xFrednet:5234-shared-code-in-if-blocks, r=phansch
New Lint: `branches_sharing_code`

This lint checks if all `if`-blocks contain some statements that are the same and can be moved out of the blocks to prevent code duplication. Here is an example:

```rust
let _ = if ... {
    println!("Start"); // <-- Lint for code duplication
    let _a = 99;
    println!("End"); // <-- Lint for code duplication
    false
} else {
    println!("Start");
    let _b = 17;
    println!("End");
    false
};
```

This could be written as:

```rust
println!("Start");

let _ = if ... {
    let _a = 99;
    false
} else {
    let _b = 17;
    false
};

println!("End");
```

---

This lint will get masked by the `IF_SAME_THEN_ELSE` lint. I think it makes more sense to only emit one lint per if block. This means that the folloing example:

```rust
if ... {
    let _a = 17;
} else {
    let _a = 17;
}
```

Will only trigger the `IF_SAME_THEN_ELSE` lint and not the `SHARED_CODE_IN_IF_BLOCKS` lint.

---

closes: #5234

changelog: Added a new lint: `branches_sharing_code`

And hello to the one that is writing the changelog for this release :D
2021-04-05 19:00:41 +00:00
bors
1a45e437b8 Auto merge of #7026 - daxpedda:cargo-author, r=camsteffen
Remove author requirement for `cargo_common_metadata`

This PR follows https://github.com/rust-lang/cargo/pull/9282, I'm not fully informed about all of this, it would be great if somebody knowledgeable about this topic agrees.

changelog: Changed `cargo_common_metadata` to stop linting on the optional author field.
2021-04-05 18:02:32 +00:00
xFrednet
a6f54f5dfd Renaming the lint to branches_sharing_code and fixing typos 2021-04-05 13:35:51 +02:00
xFrednet
8c0b4d7f65 Only running shared_code_in_if_blocks only for if statements 2021-04-05 13:35:51 +02:00
xFrednet
617c65baa9 Moving shared_code_in_if_blocks to clippy::complexity and running lintcheck 2021-04-05 13:35:51 +02:00
xFrednet
c74e49eab9 Adapted the lint to use the new SpanlessEq 2021-04-05 13:35:51 +02:00
xFrednet
65ed5a632f Updated code for dogfood 2021-04-05 13:33:45 +02:00
xFrednet
b1d26e544f Improved shared_code_in_if_blocks message and added test stderrs 2021-04-05 13:33:45 +02:00
xFrednet
8efc6acc05 Improved shared_code_in_if_blocks output readability and added tests 2021-04-05 13:33:45 +02:00
xFrednet
469ff96db3 The shared_code_in_if_blocks lint only operats on entire if expr not else ifs 2021-04-05 13:33:45 +02:00
xFrednet
d1df73228a A new lint for shared code in if blocks
* Added expression check for shared_code_in_if_blocks
* Finishing touches for the shared_code_in_if_blocks lint
* Applying PR suggestions
* Update lints yay
* Moved test into subfolder
2021-04-05 13:33:45 +02:00
bors
81f99460b1 Auto merge of #7034 - Jarcho:missing_doc_ice, r=phansch
Fix ICE in `missing_panics_doc`

fixes: #7033
changelog: Fix ICE in `missing_panics_doc` while searching in a `const` block
2021-04-05 09:27:18 +00:00
bors
8d221c569e Auto merge of #7027 - camsteffen:defidmap, r=phansch
Use DefIdMap and similar aliases

changelog: none
2021-04-05 09:15:08 +00:00
Jason Newcomb
a00de90ceb
Fix ICE in missing_panics_doc 2021-04-05 00:09:13 -04:00
ThibsG
81dfb9ecfb Check path imports per module 2021-04-04 14:25:05 +02:00
Aliénore Bouttefeux
2f81e4e34f modification not working: fixing 2021-04-04 13:03:05 +02:00
Cameron Steffen
6f31ed6c8d Use DefIdMap and similar aliases 2021-04-03 18:02:49 -05:00
daxpedda
5102c9cc69
Remove author requirement for cargo_common_metadata 2021-04-03 22:52:48 +02:00
Cameron Steffen
7014340d57 Fix ICE 2021-04-03 14:17:58 -05:00
Jason Newcomb
c05760ff90
Fix macro_use_import ICE 2021-04-02 22:27:13 -04:00
bors
86fb0e8266 Auto merge of #7020 - camsteffen:needless-collect, r=Manishearth
Improve needless_collect output

changelog: Improve needless_collect output

Fixes #6908
Partially addresses #6164
2021-04-02 15:27:54 +00:00
Cameron Steffen
33798bb064 Improve needless_collect output 2021-04-02 10:10:54 -05:00
bors
9ce23730e2 Auto merge of #7016 - camsteffen:bind-map-paths, r=Manishearth
Remove paths from bind_instead_of_map

changelog: none
2021-04-02 15:10:24 +00:00
Cameron Steffen
4356a8f8f7 Remove redundant emit() 2021-04-02 09:38:13 -05:00
Cameron Steffen
a064534b9e Refactor needless_collect 2021-04-02 08:41:05 -05:00
bors
1931db20b1 Auto merge of #6988 - mikerite:fix-6984, r=camsteffen
Fix hidden variant suggestion on single variant

Fixes #6984

changelog: Fix hidden variant suggestion on `match_wildcard_for_single_variants`
2021-04-02 12:42:40 +00:00
Yoshitomo Nakanishi
9f6f001988 same_item_push: Don't trigger same_item_push if the vec is used in the loop body 2021-04-02 16:28:16 +09:00
Cameron Steffen
08a8ad3a36 Remove paths from bind_instead_of_map 2021-04-01 15:41:25 -05:00
bors
92c4fc3cd8 Auto merge of #7011 - Jarcho:redundant_clone_fp, r=flip1995
Fix `redundant_clone` fp

fixes: #5973
fixes: #5595
fixes: #6998

changelog: Fix `redundant_clone` fp  where the cloned value is modified while the clone is in use.
2021-04-01 14:06:04 +00:00
bors
38b1fd0fa7 Auto merge of #7002 - mgacek8:issue6983_wrong_self_convention_inside_trait_impls, r=phansch
wrong_self_convention: fix FP inside trait impl for `to_*` method taking `&self`

fixes #6983
changelog: `wrong_self_convention`: fix FP inside trait impl for `to_*` method taking `&self`
2021-04-01 05:48:16 +00:00