Commit graph

4941 commits

Author SHA1 Message Date
lcnr
fd8b150959 feature(const_generics) -> feature(const_param_types) 2021-08-30 11:00:21 +02:00
Ellen
0b526fd7fb rename const_evaluatable_checked to generic_const_exprs
2021-08-30 11:00:21 +02:00
Jason Newcomb
3e5dcba2ee
Small cleanup of option_if_let_else and additional tests. 2021-08-26 11:44:36 -04:00
bors
de80188c64 Auto merge of #7543 - DevinR528:disallowed-mod, r=Manishearth
Add module_style lint to style

changelog: Add new [`module_style`] style lint

This is a configurable (no mod file/mod file) lint that determines if `mod.rs` is used consistently or if `mod.rs` is never used (using the new mod layout).
2021-08-25 15:20:28 +00:00
bors
305177342f Auto merge of #7453 - F3real:assume_function_calls_have_side_effect, r=flip1995
Don't report function calls as unnecessary operation if used in array index

Attempts to fix: #7412

changelog: Don't report function calls used in indexing as unnecessary operation. [`unnecessary_operation`]
2021-08-25 08:31:20 +00:00
Devin Ragotzy
31738b1da3 Add module_style lint to restriction
Add tests for disallowed_mod in ui-cargo test section

Use correct algorithm to determine if mod.rs is missing

Move to two lints and remove config option

Switch lint names so they read "warn on ..."

Emit the same help info for self_named_mod_file warnings

Bail when both lints are Allow

Reword help message for both module_style lints
2021-08-24 15:53:58 -04:00
bors
87c6f32756 Auto merge of #7592 - lengyijun:redundant_allocation, r=camsteffen
redundant_allocation: fix 7487

Fixes #7487

changelog: [`redundant_allocation`] - allow `Box<Box<dyn T>>` which replaces wide pointers with thin pointers
2021-08-24 12:32:01 +00:00
lengyijun
641be558fc redundant_allocation: fix 7487 2021-08-24 13:03:48 +08:00
Mara Bos
4c847c0dbd Rollup merge of #88230 - steffahn:a_an, r=oli-obk
Fix typos “a”→“an”

Fix typos in comments; found using a regex to find some easy instance of incorrect usage of a vs. an.

While automation was used to find these, every change was checked manually.

Changes in submodules get separate PRs:
* https://github.com/rust-lang/stdarch/pull/1201
* https://github.com/rust-lang/cargo/pull/9821
* https://github.com/rust-lang/miri/pull/1874
* https://github.com/rust-lang/rls/pull/1746
* https://github.com/rust-analyzer/rust-analyzer/pull/9984
  _folks @ rust-analyzer are fast at merging…_
  * https://github.com/rust-analyzer/rust-analyzer/pull/9985
  * https://github.com/rust-analyzer/rust-analyzer/pull/9987
  * https://github.com/rust-analyzer/rust-analyzer/pull/9989

_For `clippy`, I don’t know if the changes should better better be moved to a PR to the original repo._

<hr>

This has some overlap with #88226, but neither is a strict superset of the other.

If you want multiple commits, I can split it up; in that case, make sure to suggest a criterion for splitting.
2021-08-23 20:45:49 +02:00
bors
22606e7358 Auto merge of #7539 - Labelray:master, r=camsteffen
Add new lint `negative_feature_names` and `redundant_feature_names`

Add new lint [`negative_feature_names`] to detect feature names with prefixes `no-` or `not-` and new lint [`redundant_feature_names`] to detect feature names with prefixes `use-`, `with-` or suffix `-support`
changelog: Add new lint [`negative_feature_names`] and [`redundant_feature_names`]
2021-08-23 13:56:18 +00:00
Labelray
0a021d5900 Add new lints negative_feature_names and redundant_feature_names 2021-08-23 21:05:44 +08:00
Frank Steffahn
c86071898f Fix typos “a”→“an” 2021-08-22 15:35:11 +02:00
Cameron Steffen
ae02282ad0 Fix clippy let expressions fallout 2021-08-19 14:17:05 -05:00
Jason Newcomb
8b3ca9a315
Fix option_if_let_else
* `break` and `continue` statments local to the would-be closure are allowed
* don't lint in const contexts
* don't lint when yield expressions are used
* don't lint when the captures made by the would-be closure conflict with the other branch
* don't lint when a field of a local is used when the type could be pontentially moved from
* in some cases, don't lint when scrutinee expression conflicts with the captures of the would-be closure
2021-08-16 16:12:00 -04:00
Jason Newcomb
a7f376fbd3
Add lint manual_split_once 2021-08-16 09:34:58 -04:00
dswij
711c5cb6d2 Add false positive test for manual_flatten
Add a scenario where `manual_flatten` is triggered when match expression will still be used after the match in `if let`.
2021-08-16 16:24:44 +08:00
bors
d9c3f0d690 Auto merge of #84039 - jyn514:uplift-atomic-ordering, r=wesleywiser
Uplift the invalid_atomic_ordering lint from clippy to rustc

This is mostly just a rebase of https://github.com/rust-lang/rust/pull/79654; I've copy/pasted the text from that PR below.

r? `@lcnr` since you reviewed the last one, but feel free to reassign.

---

This is an implementation of https://github.com/rust-lang/compiler-team/issues/390.

As mentioned, in general this turns an unconditional runtime panic into a (compile time) lint failure. It has no false positives, and the only false negatives I'm aware of are if `Ordering` isn't specified directly and is comes from an argument/constant/whatever.

As a result of it having no false positives, and the alternative always being strictly wrong, it's on as deny by default. This seems right.

In the [zulip stream](https://rust-lang.zulipchat.com/#narrow/stream/233931-t-compiler.2Fmajor-changes/topic/Uplift.20the.20.60invalid_atomic_ordering.60.20lint.20from.20clippy/near/218483957) `@joshtriplett` suggested that lang team should FCP this before landing it. Perhaps libs team cares too?

---

Some notes on the code for reviewers / others below

## Changes from clippy

The code is changed from [the implementation in clippy](68cf94f6a6/clippy_lints/src/atomic_ordering.rs) in the following ways:

1. Uses `Symbols` and `rustc_diagnostic_item`s instead of string literals.
    - It's possible I should have just invoked Symbol::intern for some of these instead? Seems better to use symbol, but it did require adding several.
2. The functions are moved to static methods inside the lint struct, as a way to namespace them.
    - There's a lot of other code in that file — which I picked as the location for this lint because `@jyn514` told me that seemed reasonable.
3. Supports unstable AtomicU128/AtomicI128.
    - I did this because it was almost easier to support them than not — not supporting them would have (ideally) required finding a way not to give them a `rustc_diagnostic_item`, which would have complicated an already big macro.
    - These don't have tests since I wasn't sure if/how I should make tests conditional on whether or not the target has the atomic... This is to a certain extent an issue of 64bit atomics too, but 128-bit atomics are much less common. Regardless, the existing tests should be *more* than thorough enough here.
4. Minor changes like:
    - grammar tweaks ("loads cannot have `Release` **and** `AcqRel` ordering" => "loads cannot have `Release` **or** `AcqRel` ordering")
    - function renames (`match_ordering_def_path` => `matches_ordering_def_path`),
    - avoiding clippy-specific helper methods that don't exist in rustc_lint and didn't seem worth adding for this case (for example `cx.struct_span_lint` vs clippy's `span_lint_and_help` helper).

## Potential issues

(This is just about the code in this PR, not conceptual issues with the lint or anything)

1. I'm not sure if I should have used a diagnostic item for `Ordering` and its variants (I couldn't figure out how really, so if I should do this some pointers would be appreciated).
    - It seems possible that failing to do this might possibly mean there are more cases this lint would miss, but I don't really know how `match_def_path` works and if it has any pitfalls like that, so maybe not.

2. I *think* I deprecated the lint in clippy (CC `@flip1995` who asked to be notified about clippy changes in the future in [this comment](https://github.com/rust-lang/rust/pull/75671#issuecomment-718731659)) but I'm not sure if I need to do anything else there.
    - I'm kind of hoping CI will catch if I missed anything, since `x.py test src/tools/clippy` fails with a lot of errors with and without my changes (and is probably a nonsense command regardless). Running `cargo test` from src/tools/clippy also fails with unrelated errors that seem like refactorings that didnt update clippy? So, honestly no clue.

3. I wasn't sure if the description/example I gave good. Hopefully it is. The example is less thorough than the one from clippy here: https://rust-lang.github.io/rust-clippy/master/index.html#invalid_atomic_ordering. Let me know if/how I should change it if it needs changing.

4. It pulls in the `if_chain` crate. This crate was already used in clippy, and seems like it's used elsewhere in rustc, but I'm willing to rewrite it to not use this if needed (I'd prefer not to, all things being equal).
2021-08-16 06:36:13 +00:00
Thom Chiovoloni
295225b660 Uplift the invalid_atomic_ordering lint from clippy to rustc
- Deprecate clippy::invalid_atomic_ordering
- Use rustc_diagnostic_item for the orderings in the invalid_atomic_ordering lint
- Reduce code duplication
- Give up on making enum variants diagnostic items and just look for
`Ordering` instead

  I ran into tons of trouble with this because apparently the change to
  store HIR attrs in a side table also gave the DefIds of the
  constructor instead of the variant itself. So I had to change
  `matches_ordering` to also check the grandparent of the defid as well.

- Rename `atomic_ordering_x` symbols to just the name of the variant
- Fix typos in checks - there were a few places that said "may not be
  Release" in the diagnostic but actually checked for SeqCst in the lint.
- Make constant items const
- Use fewer diagnostic items
- Only look at arguments after making sure the method matches

  This prevents an ICE when there aren't enough arguments.

- Ignore trait methods
- Only check Ctors instead of going through `qpath_res`

  The functions take values, so this couldn't ever be anything else.

- Add if_chain to allowed dependencies
- Fix grammar
- Remove unnecessary allow
2021-08-16 03:55:27 +00:00
Caio
b97d4c062b Introduce hir::ExprKind::Let - Take 2 2021-08-15 16:18:26 -03:00
Jason Newcomb
10c0460a47
update stderr messages 2021-08-14 19:52:59 -04:00
Jason Newcomb
9500974bdb
Fix tracking of which locals would need to be captured in a closure.
* Captures by sub closures are now considered
* Copy types are correctly borrowed by reference when their value is used
* Fields are no longer automatically borrowed by value
* Bindings in `match` and `let` patterns are now checked to determine how a local is captured
2021-08-14 19:49:57 -04:00
Jason Newcomb
251dd30d77
Improve manual_map
In some cases check if a borrow made in the scrutinee expression would prevent creating the closure used by `map`
2021-08-14 19:49:54 -04:00
Jason Newcomb
4838c78ba4
Improve manual_map and map_entry
Locals which can be partially moved created within the to-be-created closure shouldn't block the use of a closure
2021-08-14 19:49:45 -04:00
dswij
e9f56f949d Add false positive test for iterator method 2021-08-13 14:56:37 +08:00
bors
456e48f39e Auto merge of #87954 - flip1995:clippyup, r=Manishearth
Update Clippy

r? `@Manishearth`
2021-08-13 05:30:37 +00:00
xFrednet
c02dcd5405 Update type UI tests to use private items 2021-08-12 22:18:45 +02:00
xFrednet
09b7745f34 Updated lint message for rc_mutex 2021-08-12 13:53:23 +02:00
Guillaume Gomez
fd5427b686 Rollup merge of #87885 - m-ou-se:edition-guide-links, r=rylev
Link to edition guide instead of issues for 2021 lints.

This changes the 2021 lints to not link to github issues, but to the edition guide instead.

Fixes  #86996
2021-08-12 13:25:07 +02:00
flip1995
1ad5464200 Merge commit '7bfc26ec8e7a454786668e7e52ffe527fc649735' into clippyup 2021-08-12 11:16:25 +02:00
flip1995
d02016d686
Merge remote-tracking branch 'upstream/master' into rustup 2021-08-12 10:58:44 +02:00
Mara Bos
8e563b5468 Bless clippy tests. 2021-08-12 10:48:16 +02:00
bors
62f4187ed0 Auto merge of #7546 - mgeier:patch-1, r=giraffate
similar_names: allow "iter" and "item"

changelog: [`similar_names`] no longer complains about `iter` and `item` being too similar
2021-08-12 08:16:50 +00:00
bors
e62a6cad1e Auto merge of #7516 - lf-:unwrap-or-default, r=xFrednet
Add `unwrap_or_else_default` lint

---

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

changelog: Add a new [`unwrap_or_else_default`] style lint. This will catch `unwrap_or_else(Default::default)` on Result and Option and suggest `unwrap_or_default()` instead.
2021-08-12 08:02:44 +00:00
F3real
979ce29086 Correctly report inclusive range in no_effect lint 2021-08-12 01:05:41 +02:00
Matthias Geier
f7784ef534
fix line numbers 2021-08-11 20:42:01 +02:00
Matthias Geier
ee63ebe11b
rustfmt 2021-08-11 20:35:48 +02:00
Matthias Geier
573b897441
Add test for similar names "iter" and "item" 2021-08-11 20:32:26 +02:00
bors
b1b38604f2 Auto merge of #7541 - LeSeulArtichaut:for-never-loop, r=camsteffen
`never_loop`: suggest using an `if let` instead of a `for` loop

changelog: suggest using an `if let` statement instead of a `for` loop that [`never_loop`]s

Fixes #7537, r? `@camsteffen.`
2021-08-11 14:49:37 +00:00
LeSeulArtichaut
fc0af8e4d8 never_loop: suggest using an if let instead of a for loop 2021-08-11 16:35:33 +02:00
Esteban Kuber
652b6a771f update clippy 2021-08-11 14:21:33 +00:00
Jade
11ef04728c Add unwrap_or_else_default lint
This will catch `unwrap_or_else(Default::default)` on Result and Option
and suggest `unwrap_or_default()` instead.
2021-08-10 14:40:26 -07:00
bors
76c4a337d1 Auto merge of #7535 - LeSeulArtichaut:7518-self-ty-arg, r=xFrednet
Properly handle `Self` type for `trivially_copy_pass_by_ref`

changelog: properly handle `Self` type for [`trivially_copy_pass_by_ref`].

Fixes #7518
2021-08-10 10:25:26 +00:00
F3real
ede977cf31 Update suggestion in case of index for unnecessary_operation lint 2021-08-10 12:08:09 +02:00
bors
f998e89e43 Auto merge of #7478 - DevinR528:preemtive, r=llogiq
Fix nonstandard_macro_braces FP and docs of disallowed_types

changelog: Fix FP in [`nonstandard_macro_braces`] lint
2021-08-10 00:52:04 +00:00
bors
0084195dee Auto merge of #7506 - HKalbasi:add-xor-swap, r=camsteffen
Add xor case to `manual swap` lint

Continue of #7153
closes #6598

changelog: Add "xor swap" case to [`manual_swap`]
2021-08-09 13:34:42 +00:00
hamidreza kalbasi
6d36d1a835 merge XOR_SWAP with MANUAL_SWAP 2021-08-09 02:15:10 +04:30
bors
6cb30ad581 Auto merge of #7534 - LeSeulArtichaut:7517-closure-too-many-lines, r=flip1995
Don't emit `too_many_lines` for closures

changelog: don't emit the [`too_many_lines`] lint inside closures to avoir duplicated diagnostics.

Fixes #7517.
2021-08-07 13:05:53 +00:00
LeSeulArtichaut
ccb5d73dec Properly handle Self type for trivially_copy_pass_by_ref 2021-08-05 18:11:08 +02:00
valentine-mario
8a4ffb881d fixed bug that had to deal with mut and non mut suggestion 2021-08-05 16:15:44 +01:00
LeSeulArtichaut
4743ec1948 Don't emit too_many_lines for closures 2021-08-05 15:38:57 +02:00
bors
4e760b675c Auto merge of #7522 - dswij:map-flatten-result, r=llogiq
Cover `Result` on `map_flatten` lint

Closes #7496

changelog: `[map_flatten]` handles `Result` type
2021-08-02 07:27:09 +00:00
bors
b6c23297bf Auto merge of #7519 - Jarcho:rustfmt_fix, r=giraffate
Workaround rust-lang/rustfmt#4477 - relative paths in `path` attribute

See rust-lang/rustfmt#4477
changelog: None
2021-08-02 00:56:54 +00:00
Dharma Saputra Wijaya
69d439065e Handle Result on map_flatten lint
Adds a check on `.map(..).flatten()` on `Result` type that follows the
behaviour on `Option` type.
2021-08-01 17:47:54 +08:00
Jason Newcomb
205aa88921
Fix while_let_on_iterator
When the iterator is one field within a local correctly check for usages of the field
2021-07-31 09:32:54 -04:00
Jason Newcomb
fe75faa6ee
Fix while_let_on_iterator
Reborrow mutable references rather then take a reference to them.
2021-07-31 00:11:46 -04:00
Jason Newcomb
fc387b877a
Workaround rust-lang/rustfmt#4477 - relative paths in path attribute 2021-07-30 23:43:04 -04:00
bors
c9e45e47d5 Auto merge of #86754 - estebank:use-multispans-more, r=varkor
Use `multipart_suggestions` more

Built on top of #86532
2021-07-30 23:18:12 +00:00
Yuki Okushi
0af50b4d32 Rollup merge of #87385 - Aaron1011:final-enable-semi, r=petrochenkov
Make `SEMICOLON_IN_EXPRESSIONS_FROM_MACROS` warn by default

This PR makes the `SEMICOLON_IN_EXPRESSIONS_FROM_MACROS` lint warn by default.

To avoid showing a large number of un-actionable warnings to users, we only enable the lint for macros defined in the same crate. This ensures that users will be able to fix the warning by simply removing a semicolon.

In the future, I'd like to enable this lint unconditionally, and eventually make it into a hard error in a future edition. This PR is a step towards that goal.
2021-07-31 04:09:20 +09:00
Esteban Küber
9a6ae783d4 Use multispan suggestions more often
* Use more accurate span for `async move` suggestion
* Use more accurate span for deref suggestion
* Use `multipart_suggestion` more often
2021-07-30 09:26:31 -07:00
Aaron Hill
967a72196c Remove unnecessary trailing semicolons from clippy tests 2021-07-29 09:52:35 -05:00
Hrishi Dharam
dbb10b87f8 add xor-swap lint 2021-07-29 15:25:08 +04:30
flip1995
2b20f49841 Merge commit '0cce3f643bfcbb92d5a1bb71858c9cbaff749d6b' into clippyup 2021-07-29 12:16:06 +02:00
flip1995
54e539121d
Rename two lints to comply with our lint naming convention
self_named_constructor -> self_named_constructors
append_instead_of_extend -> extend_with_drain
2021-07-29 12:10:18 +02:00
flip1995
490beda6be
Merge remote-tracking branch 'upstream/master' into rustup 2021-07-29 11:14:25 +02:00
flip1995
6c5d199d57
Update deploy CI
This updates all the deploy scripts and the deploy workflow.

The deploy workflow now runs the metadata collector to collect the lint
documentation. It also changes the files that are checked out in the
deploy workflow from master and adds an explanation why we have to do
this.
2021-07-28 14:16:31 +02:00
Jacob Pratt
5331fea875 Update tests 2021-07-27 16:26:50 -04:00
bors
ac0fd99194 Auto merge of #7492 - nfejzic:improve_help, r=Manishearth
Explain flags missing in cargo check in --help

This commit closes #7389. As stated in the issue, `cargo clippy --help`
provides explanation for some flags and states that the rest are same
as in `cargo check --help`, even though some clippy specific flags
exist.

This commit extends the `cargo clippy --help` with two additional flags,
  - `cargo clippy --fix`
  - `cargo clippy --no-deps`

If there are more flags which are not present in `cargo check --help`
please bring these to my attention, I will include these aswell.
For now, I noticed only the two flags mentioned above.

changelog: `cargo clippy --help` now explains additional flags missing in `cargo check --help`.
2021-07-27 14:39:08 +00:00
Devin Ragotzy
a1bab3bc63 Add primitive type support to disallowed_type lint
Fix docs of disallowed_type

Add ability to name primitive types without import path

Move primitive resolution to clippy_utils path_to_res fn

Refactor Res matching, fix naming and docs from review

Use tcx.def_path_str when emitting the lint
2021-07-27 10:01:38 -04:00
Nadir Fejzic
f7af8bf2c1 Handle --no-deps flag same as --fix flag.
As proposed in the pull request thread, there is some inconsistency in
handling the `--no-deps` flag which requires `--` before it, and
`--fix` flag which does not.
In this commit the `--no-deps` flag does not need the `--` anymore.
However, it can still be used that way: `cargo clipyy -- --no-deps`.
2021-07-27 11:13:42 +02:00
bors
ceb7a868d3 Auto merge of #7466 - xFrednet:5393-use-more-diagnostic-items, r=flip1995
Use diagnostic items where possible

Clippy still uses a bunch of paths in places that could easily use already defined diagnostic items. This PR updates all references to such paths and also removes a bunch of them that are no longer needed after this cleanup.

Some paths are also used to construct new paths and can therefore not be removed that easily. I've added a doc comment to those instances that recommends the use of the diagnostic item where possible.

And that's it, cleaning crew signing off 🧹 🗑️

---

changelog: none

(only internal improvements)

cc: #5393
2021-07-27 08:19:23 +00:00
Cameron Steffen
3c517b3b24 Improve conflicting rlibs error again 2021-07-26 11:38:53 -05:00
bors
3214de3fe6 Auto merge of #7493 - xFrednet:7220-fix-new-without-default-impl-type, r=camsteffen
Prefer a code snipped over formatting the self type (`new_without_default`)

Fixes: rust-lang/rust-clippy#7220

changelog: [`new_without_default`]: The `Default` impl block type doesn't use the full type path qualification

Have a nice day to everyone reading this 🙃
2021-07-26 12:20:54 +00:00
bors
7d6946df34 Auto merge of #7485 - camsteffen:add-test-externs, r=flip1995
Add to test third party crates list

changelog: none
2021-07-26 12:06:07 +00:00
bors
02d70f3604 Auto merge of #7477 - F3real:needless_continue, r=flip1995
Enhance needless continue to detect loop {continue;}

Fixes #7417

changelog: Report [`needless_continue`] in `loop { continue; }` case
2021-07-26 11:52:55 +00:00
xFrednet
89c8c3f4cd Prefer a code snipped over formatting the self type (new_without_default) 2021-07-26 09:35:38 +02:00
Cameron Steffen
d3492a0894 author: check block.expr: None 2021-07-25 18:10:59 -05:00
Devin Ragotzy
44d37a44bc Lint inside macro when owned by current crate 2021-07-24 07:30:22 -04:00
Devin Ragotzy
f5c3ed4463 Only trigger for one level of macros 2021-07-24 07:30:22 -04:00
Devin Ragotzy
5bc5bfce04 Add tests for FP in nonstandard_macro_braces 2021-07-24 07:30:22 -04:00
Cameron Steffen
afe5962d38 clippy::author improvements 2021-07-23 17:03:12 -05:00
Cameron Steffen
ea97a5a5d7 Add clippy_utils and if_chain to extern crate list 2021-07-23 17:00:00 -05:00
chaz-kiker
1b8fc8f13d update clippy ui test 'future_not_send.stderr' to match
the new diagnostic messages
2021-07-23 12:55:13 -05:00
F3real
c3452f3bd2 Lint on continue expression without semi-colon 2021-07-22 22:23:59 +02:00
F3real
9d6127cdb0 Emit needless_continue warning if loop ends on continue 2021-07-21 23:32:16 +02:00
F3real
24ec35a904 Enhance needless continue to detect loop {continue;} 2021-07-20 19:26:45 +02:00
bors
610381455c Auto merge of #7221 - th1000s:keyword_, r=giraffate
similar_names: No longer suggest inserting or appending an underscore

changelog: [`similar_names`] lint no longer suggests to insert or add an underscore to "fix" too similar names
2021-07-19 14:18:59 +00:00
flip1995
884ef4c287 Merge commit '4c41a222ca5d1325fb4b6709395bd06e766cc042' into clippyup 2021-07-19 11:52:05 +02:00
bors
f467750680 Auto merge of #7470 - DevinR528:fix-ice7447, r=flip1995
Add check if ty has_escaping_bound_vars in zero_sized_map_values lint

Fixes: #7447

changelog: fix ICE in [`zero_sized_map_values`]
2021-07-19 09:22:34 +00:00
bors
f70a07454b Auto merge of #7403 - Anthuang:redundant-method-names, r=Manishearth
New lint: [`self_named_constructor`]

Adds the `self_named_constructor` lint for detecting when an implemented method has the same name as the type it is implemented for.

changelog: [`self_named_constructor`]

closes: #7142
2021-07-19 06:49:51 +00:00
Anthony Huang
e9e10d209e Run bless 2021-07-19 01:21:06 -04:00
bors
46363df926 Auto merge of #7474 - camsteffen:binop, r=Manishearth
Use lang items for BinOp lints

changelog: none
2021-07-18 15:52:49 +00:00
Michael Howell
f882c363e2 fix(clippy): add missing allow(dyn_drop) 2021-07-18 07:57:03 -07:00
Cameron Steffen
98c500cf83 Factor BinOp utils 2021-07-17 20:49:19 -05:00
Jason Newcomb
5bfc2568a2
Fix ICE in is_integer_const when the expression is inside an AnonConst body 2021-07-17 19:01:19 -04:00
flip1995
b98e2ec527
Fix ICE in redundant_pattern_matching 2021-07-16 10:45:28 +02:00
Devin Ragotzy
7312611207 Add check if ty has_escaping_bound_vars in zero_sized_map_values lint 2021-07-15 18:37:02 -04:00
flip1995
1d084b13a5 Merge commit '54a20a02ecd0e1352a871aa0990bcc8b8b03173e' into clippyup 2021-07-15 10:44:10 +02:00
flip1995
69fbd64e2a
Merge remote-tracking branch 'upstream/master' into rustup 2021-07-15 10:32:06 +02:00
lyj
e575610fb3 redundant_allocation: add Arc; some refractoring. 2021-07-15 07:10:55 +08:00
xFrednet
ecf85f4bdc Use diagnostic items for Vec, VecDeque and connected refactorings 2021-07-15 00:02:46 +02:00
bors
2b193e247f Auto merge of #7462 - xFrednet:7369-branches-sharing-code-else-expr-fp, r=camsteffen
FP fix and documentation for `branches_sharing_code` lint

Closes rust-lang/rust-clippy#7369

Related rust-lang/rust-clippy#7452 I'm still thinking about the best way to fix this. I could simply add another visitor to ensure that the moved expressions don't modify values being used in the condition, but I'm not totally happy with this due to the complexity. I therefore only documented it for now

changelog: [`branches_sharing_code`] fixed false positive where block expressions would sometimes be ignored.
2021-07-14 20:29:56 +00:00
xFrednet
61e280863f Fixed branches_sharing_code FP with block expressions in else
And added `branches_sharing_code` PF note to lint doc for `rust-clippy#7452`
2021-07-14 21:37:17 +02:00
bors
4acbff9eb0 Auto merge of #7437 - ebobrow:redundant-closure-move, r=flip1995
suggest `&mut` for redundant FnMut closures

fixes #6903

changelog: suggest `&mut` for redundant FnMut closures
2021-07-14 15:15:28 +00:00
Elliot Bobrow
4c398e07e0 suggest &mut for redundant FnMut closures 2021-07-14 07:56:27 -07:00
lyj
251c3b64da fix 5707 2021-07-14 10:57:47 +08:00
Thomas Otto
e8f57c3ac4 No longer suggest inserting or appending an underscore
changelog: [`similar_names`] lint no longer suggests to insert or add an underscore
to "fix" too similar names
2021-07-13 23:21:24 +02:00
bors
8131445e53 Auto merge of #7446 - Y-Nak:fix-7445, r=xFrednet,flip1995
`default_numeric_fallback`: Fix FP with floating literal

Fix #7445

changelog: `default_numeric_fallback`: Fix FP with floating literal
2021-07-13 14:31:02 +00:00
Yoshitomo Nakanishi
25e4c7d73f default_numeric_fallback: Add rustfix tests 2021-07-13 23:18:31 +09:00
Cameron Steffen
306f9e843d Split a lint message into help 2021-07-13 08:57:16 -05:00
Cameron Steffen
20dbb277cf Fix useless_format false positive 2021-07-13 08:57:16 -05:00
Yoshitomo Nakanishi
04aa3f7e9b default_numeric_fallback: Add more tests for floating literal 2021-07-09 18:24:23 +09:00
Yoshitomo Nakanishi
3bc5abef62 default_numeric_fallback: Fix FP with floating literal 2021-07-08 11:37:12 +09:00
Ryan Levick
30c5c2ff03 Add s to non_fmt_panic 2021-07-06 20:12:56 +02:00
iobtl
eeefbb7617 fix false positive (panic message) with assert macro using message parameter 2021-07-06 15:14:53 +08:00
Anthony Huang
357a8f0344 Add redundant_method_names lint 2021-07-05 14:15:20 -04:00
Mateusz Gacek
59a164e86c Add new lint: strlen_on_c_strings 2021-07-05 11:10:45 +02:00
bors
3cc6778512 Auto merge of #7431 - DevinR528:fix-macro-brace, r=llogiq
Fix emitting in nested (proc_)macros for nonstandard_macro_braces lint

fixes #7422

changelog: fixes false positives in [`nonstandard_macro_braces`]
2021-07-04 16:47:11 +00:00
Devin Ragotzy
1d110f8c2e Fix emitting in nested (proc_)macros for nonstandard_macro_braces lint 2021-07-04 07:06:23 -04:00
Cameron Steffen
cb4670deb3 Fix use_self ICE 2021-07-03 12:40:50 -05:00
bors
c195db7fee Auto merge of #7426 - ebobrow:doc-markdown-fp, r=llogiq
fix doc_markdown false positive

fixes #7421

changelog: don't lint unbalanced tick marks in code blocks
2021-07-03 16:53:21 +00:00
Elliot Bobrow
e9a5694597 fix doc_markdown false positive 2021-07-03 09:34:10 -07:00
bors
84209994ad Auto merge of #7316 - lengyijun:rc_mutex, r=llogiq
Add new lint: `rc_mutex`

changelog: Add new lint `rc_mutex`.

It lints on `Rc<Mutex<T>>`.

`Rc<Mutex<T>>` should be corrected to `Rc<RefCell<T>>`
2021-07-03 10:26:03 +00:00
David Tolnay
0f662e5833
Downgrade nonstandard_macro_braces to nursery 2021-07-02 22:16:04 -07:00
flip1995
ebe52869a3 Merge commit '61eb38aeda6cb54b93b872bf503d70084c4d621c' into clippyup 2021-07-01 18:17:38 +02:00
flip1995
a82a744155
Merge remote-tracking branch 'upstream/master' into rustup 2021-07-01 17:41:24 +02:00
bors
753bce30f0 Auto merge of #7407 - m-ou-se:doc-hidden-variants, r=flip1995
Don't suggest doc(hidden) or unstable variants in wildcard lint

Clippy's wildcard lint would suggest doc(hidden) and unstable variants for non_exhaustive enums, even though those aren't part of the public interface (yet) and should only be matched on using a `_`, just like potential future additions to the enum. There was already some logic to exclude a *single* doc(hidden) variant. This extends that to all hidden variants, and also hides `#[unstable]` variants.

See https://github.com/rust-lang/rust/pull/85746#issuecomment-868886893

This PR includes https://github.com/rust-lang/rust-clippy/pull/7406 as the first commit.

Here's the diff that this PR adds on top of that PR: https://github.com/m-ou-se/rust-clippy/compare/std-errorkind...m-ou-se:doc-hidden-variants

---

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

changelog: No longer suggest unstable and doc(hidden) variants in wildcard lint. wildcard_enum_match_arm, match_wildcard_for_single_variants
2021-07-01 15:02:21 +00:00
flip1995
fae7a09eea
match_wildcard_for_single_variants: don't produce bad suggestion
This fixes a bug where match_wildcard_for_single_variants produced a
bad suggestion where besides the missing variant, one or more hidden
variants were left.

This also adds tests to the ui-tests match_wildcard_for_single_variants
and wildcard_enum_match_arm to make sure that the correct suggestion is
produced.
2021-07-01 12:38:30 +02:00
flip1995
0ffba7a684
Simplify wildcard_enum_match_arm test 2021-07-01 11:47:56 +02:00
bors
cadb93b6de Auto merge of #7400 - popzxc:restrict-locales, r=Manishearth
New lint: `disallowed_script_idents`

This PR implements a new lint to restrict locales that can be used in the code,
as proposed in #7376.

Current concerns / unresolved questions:

- ~~Mixed usage of `script` (as a Unicode term) and `locale` (as something that is easier to understand for the broad audience). I'm not sure whether these terms are fully interchangeable and whether in the current form it is more confusing than helpful.~~ `script` is now used everywhere.
- ~~Having to mostly copy-paste `AllowedScript`. Probably it's not a big problem, as the list of scripts is standardized and is unlikely to change, and even if we'd stick to the `unicode_script::Script`, we'll still have to implement custom deserialization, and I don't think that it will be shorter in terms of the amount of LoC.~~ `unicode::Script` is used together with a filtering deserialize function.
- Should we stick to the list of "recommended scripts" from [UAX #31](http://www.unicode.org/reports/tr31/#Table_Recommended_Scripts) in the configuration?

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

changelog: ``[`disallowed_script_idents`]``

r? `@Manishearth`
2021-06-30 18:14:16 +00:00
Igor Aleksanov
018be41dee Implement 'disallowed_script_idents' lint 2021-06-30 19:06:33 +03:00
bors
3525a6b61a Auto merge of #7390 - popzxc:issue-7331, r=flip1995
Improve lint message for match-same-arms lint

fixes #7331

Follow-up to #7377

This PR improves the lint message for `match-same-arms` lint and adds `todo!(..)`  example to the lint docs.

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

changelog: None
2021-06-30 15:12:55 +00:00
Mara Bos
38569c03eb Don't suggest unstable and doc(hidden) variants. 2021-06-26 15:28:38 +02:00
Mara Bos
3e59563394 Don't use exact definition of std's ErrorKind in test.
Every time we add something to this enum in std, this test breaks.
2021-06-26 14:50:42 +02:00
Cameron Steffen
f02632cee6 Move some lints to suspicious 2021-06-25 08:53:29 -05:00
Ryan Levick
abc9a46868 Fix clippy test 2021-06-25 15:29:14 +02:00
bors
8d427b624f Auto merge of #7379 - popzxc:issue-7305, r=flip1995
Do not spawn blacklisted_name lint in test context

---

fixed #7305

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

changelog: `blacklisted_name` lint is not spawned in the test context anymore.
2021-06-25 10:12:05 +00:00
Igor Aleksanov
28d3873ef5 Do not spawn blacklisted_name lint in test context
Fix detecting of the 'test' attribute

Update UI test to actually check that warning is not triggered in the test code

Fix approach for detecting the test module

Add nested test case

Remove code duplication by extracting 'is_test_module_or_function' into 'clippy_utils'

Cleanup the code
2021-06-25 12:36:22 +03:00
Igor Aleksanov
39856b17ec Improve lint message for match-same-arms lint
Simplify error message producing & remove extra example
2021-06-25 12:33:35 +03:00
bors
b286b38a29 Auto merge of #7300 - DevinR528:import-rename, r=camsteffen
Add import_rename lint, this adds a field on the Conf struct

fixes #7276

changelog: Add ``[`import_rename`]`` a lint that enforces import renaming defined in the config file.
2021-06-24 20:23:13 +00:00
Devin Ragotzy
9492de5843 Add import_rename lint, this adds a field on the Conf struct
Rename lint and fix review issues
2021-06-24 16:13:02 -04:00
Joe Ranweiler
642239c857 Update var name in test 2021-06-22 19:02:34 -07:00
Joe Ranweiler
d2087ad00d Remove bad cast in test, cover more cases 2021-06-22 18:45:03 -07:00
bors
48fa1dc8bb Auto merge of #7357 - ebobrow:unbalanced-tick, r=xFrednet,flip1995
check for unbalanced tick pairs in doc-markdown lint

fixes #6753

changelog: check for unbalanced tick pairs in doc-markdown lint
2021-06-21 17:15:12 +00:00
Elliot Bobrow
20cb1bc7c1 check for unbalanced tick pairs in doc-markdown 2021-06-21 08:52:09 -07:00
bors
404bd1a49a Auto merge of #7382 - matthiaskrgr:config_name, r=flip1995
Fix wrong config option being suggested for deprecated wrong_pub_self_convention lint

Problem:
for code like
````rust
#![warn(clippy::wrong_pub_self_convention)]
fn main() {
    println!("Hello, world!");
}
````
clippy will issue a warning to use a clippy.toml option instead:

````
warning: lint `clippy::wrong_pub_self_convention` has been removed: set the `avoid_breaking_exported_api` config option to `false` to enable the `wrong_self_convention` lint for public items
 --> src/main.rs:2:9
  |
2 | #![warn(clippy::wrong_pub_self_convention)]
  |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(renamed_and_removed_lints)]` on by default
````

But using the lint name as seen in the warning message
`echo "avoid_breaking_exported_api = true\n" > clippy.toml`

Will cause an error:
````
error: error reading Clippy's configuration file `/tmp/clippytest/clippy.toml`: unknown field `avoid_breaking_exported_api`, expected one of `avoid-breaking-exported-api`, ...
````

Replace the underscores with dashes in the deprecation message.

changelog: avoid_breaking_exported_api: suggest correct clippy config toml option in the deprecation message
2021-06-21 08:41:25 +00:00
Igor Aleksanov
310a204306 Provide different message for bootstrapped compiler 2021-06-21 06:57:57 +03:00
Matthias Krüger
8276f26a4d Fix wrong config option being suggested for deprecated wrong_pub_self_convention lint
Problem:
for code like
````
fn main() {
    println!("Hello, world!");
}
````
clippy will issue a warning to use a clippy.toml option instead:

````
warning: lint `clippy::wrong_pub_self_convention` has been removed: set the `avoid_breaking_exported_api` config option to `false` to enable the `wrong_self_convention` lint for public items
 --> src/main.rs:2:9
  |
2 | #![warn(clippy::wrong_pub_self_convention)]
  |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(renamed_and_removed_lints)]` on by default
````

But using the lint name as seen in the warning message
echo "avoid_breaking_exported_api = true\n" > clippy.toml

Will cause an error:
````
error: error reading Clippy's configuration file `/tmp/clippytest/clippy.toml`: unknown field `avoid_breaking_exported_api`, expected one of `avoid-breaking-exported-api`, ...
````

Replace the underscores with dashes in the deprecation message.

changelog: avoid_breaking_exported_api: suggest correct clippy config toml option in the deprecation message
2021-06-20 15:54:41 +02:00
Igor Aleksanov
faa2fa7490 Improve appearance 2021-06-20 08:32:43 +03:00
Igor Aleksanov
d4c9fe7549 Improve visibility&helpfulness of the 'found multiple rlibs' error 2021-06-20 08:25:30 +03:00
bors
3120b09151 Auto merge of #7299 - DevinR528:macro-brace, r=llogiq
Add macro_braces lint to check for irregular brace use in certain macros

The name is a bit long but this sounds good as `#[allow(unconventional_macro_braces)]` and it seems more clear that we are talking about the macro call not macro definitions, any feedback let me know. Thanks!
fixes #7278

changelog: Add ``[`unconventional_macro_braces`]`` lint that checks for uncommon brace usage with macros.
2021-06-19 17:56:56 +00:00
hi-rustin
e1cc628af4 Address comment 2021-06-18 16:20:30 +08:00
hi-rustin
6e8549e05e Make clippy tests happy 2021-06-18 16:11:32 +08:00
Devin Ragotzy
723f515b60 Add macro_braces lint to check for irregular brace use in certain macros
Rename unconventional -> nonstandard, add config field

Add standard_macro_braces fields so users can specify macro names and
brace combinations to lint for in the clippy.toml file.

Fix errors caused by nonstandard_macro_braces in other lint tests

Fix users ability to override the default nonstandard macro braces

Add type position macros impl `check_ty`
2021-06-17 07:02:36 -04:00
flip1995
e3eede7b90
Merge remote-tracking branch 'upstream/master' into rustup 2021-06-17 10:21:47 +02:00
bors
2d1e9ab980 Auto merge of #7345 - DevinR528:disallowed-fix, r=Manishearth
Remove requirement of fully qualified path for disallowed_method/type

changelog: Remove the need for fully qualified paths in disallowed_method and disallowed_type

After fixing this issue in [import_rename](https://github.com/rust-lang/rust-clippy/pull/7300#discussion_r650127720) I figured I'd fix it for these two.

If this does in fact fix the **Known problems:** section I was planning to remove them from both lints after confirmation.
2021-06-14 14:57:56 +00:00
bors
a36a7c808c Auto merge of #7270 - Valentine-Mario:vec_extend_to_append, r=flip1995
Vec extend to append

This PR adds a check to suggest changes of vector from

```
vec.extend(other_vec.drain(..))
```

could be written as

```
vec![].append(&mut vec![]);
```

changelog: Add vec_extend_to_append lint
issue: #7209
2021-06-14 06:58:12 +00:00
bors
6379d260e7 Auto merge of #7288 - camsteffen:use-self2, r=phansch
Fix use_self FPs on type params

changelog: Fix [`use_self`] false positives on type parameters

Fixes #4140
Fixes #7139
2021-06-14 05:49:29 +00:00
Devin Ragotzy
70ce0c2c55 Remove requirement of fully qualified path for disallowed_method/type 2021-06-11 17:25:32 -04:00
bors
f1f5ccd63a Auto merge of #7160 - flip1995:field_reassign_macros, r=xFrednet,camsteffen
Don't trigger `field_reassign_with_default` in macros

Fixes #7155

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.

changelog: [`field_reassign_with_default`] No longer triggers in macros

---

No that our reviewing queue is under control, I want to start hacking on Clippy myself again. Starting with an easy issue to get back in :)
2021-06-11 15:58:58 +00:00
valentine-mario
44608b1857 added lint to check for full range of vector and suggest append 2021-06-10 09:12:06 +01:00
bors
c4636abe72 Auto merge of #7315 - DevinR528:disallowed-ty, r=giraffate
Add disallowed_type lint, this adds a field to the conf struct

Fixes #7277

changelog: Add ``[`disallowed_type`]`` a lint that can enforce banning types specified in the config.
2021-06-10 00:30:36 +00:00
Thomas de Zeeuw
0d3f289b66 Add FreeBSD as identifier not needing ticks
For the doc-markdown lint.
2021-06-09 17:16:10 +02:00
Devin Ragotzy
ea45e2a9cf Add disallowed_types lint, this adds a field to the Conf struct
Replace use of node_type -> node_type_opt, fix clippy warnings

Don't walk the hir unnecessarily let the visitor do it
2021-06-09 07:21:16 -04:00
bors
dd0246813f Auto merge of #7326 - 1c3t3a:1c3t3a-issue-7324, r=flip1995
Fix false positive on `semicolon_if_nothing_returned`

Currently the [`semicolon_if_nothing_returned`](https://rust-lang.github.io/rust-clippy/master/index.html#semicolon_if_nothing_returned) lint fires in unwanted situations where a block only spans one line. An example of this was given in #7324. This code:

```rust
use std::mem::MaybeUninit;
use std::ptr;

fn main() {
    let mut s = MaybeUninit::<String>::uninit();
    let _d = || unsafe { ptr::drop_in_place(s.as_mut_ptr()) };
}
```

yields the following clippy error:
```
error: consider adding a `;` to the last statement for consistent formatting
 --> src/main.rs:6:26
  |
6 |     let _d = || unsafe { ptr::drop_in_place(s.as_mut_ptr()) };
  |                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add a `;` here: `ptr::drop_in_place(s.as_mut_ptr());`
  |
  = note: `-D clippy::semicolon-if-nothing-returned` implied by `-D clippy::pedantic`
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#semicolon_if_nothing_returned
```

I updated the lint to check if the statement is inside an `unsafe` block, a closure or a normal block and if the block only spans one line, in that case the lint is not emitted.

This closes #7324.

changelog: enhanced semicolon if nothing returned according to  #7324.
2021-06-09 08:39:56 +00:00
bors
da0538eaca Auto merge of #7330 - xFrednet:0000-refactor-map-identity, r=flip1995
Refactoring identity function lints

I've noticed that we have several lints that all check for identity functions and each used their own check implementation. I moved the `is_expr_identity_function` function to `clippy_utils` and adapted all lints to reuse that one function. This should make the addition of new lints like this also easier in the future.

I've also moved the `map_identity` lint into the `methods` module. It's probably the best to review this PR by checking each commit individually. And that's it, have a great day 🙃

changelog: none
2021-06-09 08:27:05 +00:00
bors
07217e3370 Auto merge of #7262 - Jarcho:while_let_on_iter_closure, r=xFrednet,flip1995
fix `while_let_on_iterator` suggestion in a closure

fixes: #7249

A future improvement would be to check if the closure is being used as `FnOnce`, in which case the original suggestion would be correct.

changelog: Suggest `&mut iter` inside a closure for `while_let_on_iterator`
2021-06-08 15:52:40 +00:00
xFrednet
9e54ce865c Reuse is_expr_identity_function for filter_map_identity 2021-06-07 23:31:17 +02:00
xFrednet
bb3b58cfcc Reuse is_expr_identity_function for flat_map_identity 2021-06-07 23:20:11 +02:00
Yoshitomo Nakanishi
d7a380e4b9 Fix FP in default_numeric_fallback with external macro expansion 2021-06-06 12:43:22 +09:00
Bastian Kersting
96747c1a46 Enhance semicolon_if_nothing_returned according to #7324 2021-06-05 18:54:41 +02:00
lyj
f877f54767 rc_mutex: fix test 2021-06-05 22:42:48 +08:00
lyj
896c19e2cf rc_mutex: update doc 2021-06-05 21:42:45 +08:00
lyj
e2ec85c697 rc_mutex: add struct test 2021-06-05 21:20:02 +08:00
lyj
a5ced1fc2b rc_mutex use span_lint instead of span_lint_and_sugg 2021-06-05 21:19:05 +08:00
Joshua Nelson
390893c600 Remove doc(include) 2021-06-04 08:05:54 -04:00
Mara Bos
38ab1a6166 Add test for not linting on assert!(cfg!(..)). 2021-06-04 10:47:03 +02:00
lyj
c0f3c2fe27 correct lint 2021-06-04 10:44:34 +08:00
flip1995
6c27482115 Merge commit '3ae8faff4d46ad92f194c2a4b941c3152a701b31' into clippyup 2021-06-03 08:41:37 +02:00
Jason Newcomb
cfddf0927b
Fix type checks for manual_str_repeat 2021-05-31 09:37:13 -04:00
Jason Newcomb
97311f0906
Add lint manual_str_repeat 2021-05-30 23:26:48 -04:00
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
29b4b4c10d Do not lint use_self on type parameters 2021-05-27 20:18:07 -05:00
Cameron Steffen
6c54f61beb Move mini-macro to auxilary 2021-05-27 11:32:14 -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
Cameron Steffen
f3e77a454a Fix allow on some statement lints 2021-05-26 22:07:53 -05:00
Cameron Steffen
3af95846a2 Add deprecated lint tests 2021-05-26 21:53:43 -05:00
Cameron Steffen
c51472b4b0 Add clippy.toml to project and tests 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
bors
6d50cff45a Auto merge of #7256 - xFrednet:7172-trick-cargos-caching-for-collection, r=flip1995
Adding the ability to invalidate caches to force metadata collection

This adds the discussed hack to touch `clippy_lints/src/lib.rs` to invalidate cargos cache and force metadata collection. I've decided to use the [`filetime`](https://github.com/alexcrichton/filetime) crate instead of the touch command to make is cross-platform and just cleaner in general. Looking at the maintainers I would say that it's a save crate to use xD.

---

cc: #7172 I know this ID without looking it up now... This is not good

changelog: none

r? `@flip1995`
2021-05-25 14:08:02 +00: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
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
xFrednet
e3a1ae7bfe Adding the ability to invalidate caches to force metadata collection 2021-05-20 22:30:49 +02: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
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
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
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
Cameron Steffen
8356c485a9 Fix manual_unwrap_or FP deref reference 2021-05-17 14:20:26 -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
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
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
6bbee5c584 Auto merge of #7217 - xFrednet:7172-metadata-collection-cargo-alias, r=flip1995
Add `cargo collect-metadata` as an cargo alias for the metadata collection lint

This PR adds a new alias to run the metadata collection monster on `clippy_lints`. I'm currently using it to create the `metadata_collection.json` file and I plan to use it in the `deply.sh` script. Having it as a new alias enables us to simply use:

```sh
cargo collect-metadata
```

It sometimes requires running `cargo clean` before collecting the metadata due to caching. I'm still debating if I should include a cargo clean as part of the `run_metadata_collection_lint` test or not. Input on this would be greatly appreciated 🙃

That's it, just a small change that can be reviewed and merged in parallel to #7214.

---

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

---

changelog: none

r? `@flip1995` btw. feel free to pass these PRs one to other team members as well if you want.
2021-05-16 16:57:15 +00: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
ayushmishra2005
9013bf299e Addressed PR coments 2021-05-14 17:30:26 +05:30
ayushmishra2005
7d83f98ff3 Improve match statements 2021-05-14 08:57:33 +05:30
ThibsG
18c702955b Add sized trait for wrong_self_convention lint test 2021-05-13 23:28:40 +02: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
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
cd0db8a459
Fix test comment for while_let_on_iterator 2021-05-12 21:51:23 -04: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
0d4604dc05 Added cargo collect-metadata as a alias for the metadata collection lint 2021-05-13 01:41:22 +02:00
Aaron Hill
4698b366c4 Show macro name in 'this error originates in macro' message
When there are multiple macros in use, it can be difficult to tell
which one was responsible for producing an error.
2021-05-12 19:03:06 -04:00
Arya Kumar
5ba236f303 added needless_bitwise_bool lint 2021-05-11 19:34:14 +00:00
bors
918a1a20b1 Auto merge of #85109 - RalfJung:remove-const_fn, r=oli-obk
remove const_fn feature gate

Fixes https://github.com/rust-lang/rust/issues/84510
r? `@oli-obk`
2021-05-11 10:25:14 +00:00
Ralf Jung
c0095be6ee fix clippy test 2021-05-11 11:15:33 +02:00
bors
a8804e7bdb Auto merge of #85053 - camsteffen:duplicate-lint, r=davidtwco
Fix duplicate unknown lint errors

Fixes rust-lang/rust-clippy#6602
2021-05-10 09:45:28 +00: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
Cameron Steffen
4d283ce8e4 Fix duplicate unknown lint errors 2021-05-07 17:26:32 -05: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
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