Commit graph

6325 commits

Author SHA1 Message Date
Caio
b97d4c062b Introduce hir::ExprKind::Let - Take 2 2021-08-15 16:18:26 -03: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
David Tolnay
3c8eaa8b2c
Downgrade option_if_let_else to nursery 2021-08-14 05:47:01 -07:00
Deadbeef
80bff87c6f move Constness into TraitPredicate 2021-08-13 09:26:33 +00:00
dswij
91b598a8e4 Fix false positive on filter_next 2021-08-13 14:56:37 +08:00
xFrednet
206741bf57 Use avoid_breaking_exported_api for types module lints
Addressed PR reviews regarding code style
2021-08-12 22:18:42 +02:00
xFrednet
09b7745f34 Updated lint message for rc_mutex 2021-08-12 13:53:23 +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
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
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
Jade
23d398b184 tree-wide: Fix all the rustdoc warnings 2021-08-10 14:40:26 -07:00
Jade
c78cc7ac1f Add is_trait_item, refactor or_fun_call and unwrap_or_else_default 2021-08-10 14:40:26 -07: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
14d2aa1582 Auto merge of #7542 - LeSeulArtichaut:cleanups, r=flip1995
Cleanup usage of `span_to_snippet` and `LintContext::sess`

- avoid using `SourceMap::span_to_snippet` directly and use `clippy_utils::source::snippet_opt` instead
- don't use `LintContext::sess()` on `EarlyContext`s which have a `sess` field directly available, saving the import of `LintContext`

changelog: none
2021-08-09 13:48:47 +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
Matthias Geier
bc9459f9d4
similar_names: allow "iter" and "item" 2021-08-07 18:11:49 +02:00
bors
176df7ca9a Auto merge of #7536 - LeSeulArtichaut:redundant-allocation-doc, r=giraffate
Add missing backtick in docs for `redundant_allocation`

changelog: none
2021-08-07 13:19:06 +00:00
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
ae700b42ed Use EarlyContext::sess instead of LintContext::sess() 2021-08-07 01:59:08 +02:00
LeSeulArtichaut
64ff2b05b9 Replace span_to_snippet calls with snippet_opt from clippy_utils 2021-08-07 01:59:05 +02:00
LeSeulArtichaut
15b87088be Add missing backtick in docs for redundant_allocation 2021-08-05 19:06:35 +02: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
afe6b12b33 Auto merge of #87568 - petrochenkov:localevel, r=cjgillot
rustc: Replace `HirId`s with `LocalDefId`s in `AccessLevels` tables

and passes using those tables - primarily privacy checking, stability checking and dead code checking.

All these passes work with definitions rather than with arbitrary HIR nodes.
r? `@cjgillot`
cc `@lambinoo` (#87487)
2021-08-04 02:04:04 +00:00
Matthias Krüger
54c41c049c needless_borrow: try to make lint example a bit more illustrating 2021-08-04 00:21:25 +02:00
Devin Ragotzy
bc7fac9526 fixup! Lint inside macro when owned by current crate 2021-08-03 08:19:13 -04:00
xFrednet
b7d80e7d65 Updated define_Conf! to support multi-line doc comments 2021-08-02 17:56:09 +02:00
bors
10bb28ce73 Auto merge of #87535 - lf-:authors, r=Mark-Simulacrum
rfc3052 followup: Remove authors field from Cargo manifests

Since RFC 3052 soft deprecated the authors field, hiding it from
crates.io, docs.rs, and making Cargo not add it by default, and it is
not generally up to date/useful information for contributors, we may as well
remove it from crates in this repo.
2021-08-02 05:49:17 +00:00
Pietro Albini
2f315b82af bump bootstrap compiler to 1.55 2021-08-01 11:19:24 -04: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
Vadim Petrochenkov
a1f790c8a9 Fix clippy 2021-07-31 19:31:30 +03: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
Jade
6c2199ea9f rfc3052: Remove authors field from Cargo manifests
Since RFC 3052 soft deprecated the authors field anyway, hiding it from
crates.io, docs.rs, and making Cargo not add it by default, and it is
not generally up to date/useful information, we should remove it from
crates in this repo.
2021-07-29 14:56:05 -07:00
Léo Lanteri Thauvin
e9004b063f
Remove or_patterns feature gate in example 2021-07-29 14:23:12 +02: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
80116f9009
Bump Clippy Version -> 0.1.56 2021-07-29 11:15:11 +02:00
flip1995
490beda6be
Merge remote-tracking branch 'upstream/master' into rustup 2021-07-29 11:14:25 +02:00
Philipp Krones
464c85c8c1
Rollup merge of #7420 - xFrednet:7172-update-lint-documentation, r=flip1995
Update lint documentation to use markdown headlines

This PR updates all lint documentation to use markdown headlines. It additionally removed the *Known problems* section for lints without any problems. I've double-checked all automatic replacements, but a second pair of eyes is definitely appreciated!

I wasn't sure when you wanted to switch to the new metadata collection tomorrow, I therefore prepared this PR today. And that's it this is a standalone PR to keep the other related PRs reviewable.

changelog:  none

r? `@flip1995`

cc: #7172

Note: This should be merged with the other metadata collection related PRs.
2021-07-28 15:06:27 +02:00
Philipp Krones
bcdf147aaf
Rollup merge of #7298 - flip1995:ci-switch-to-monster, r=xFrednet,flip1995
Switch CI to new metadata collection

r? `@xFrednet`

Things we have to keep in mind:

- This removes the template files and the scripts used for deployment from the checkout. This was added in #5517. I don't think we ever needed those there. Not sure though.
- ~~As a result, we can't remove the python scripts yet. We have to wait until this hits a stable Clippy release.~~ I'll just break the next stable deploy and do it by hand once.
- This should be merged together with #7279. Me and `@xFrednet` will coordinate the switch
- ...?

I still have to try out some things:

- [x] Is it worth caching? Yes
- [x] ~~Is it worth to do a release build?~~ Nope
- [x] Does it actually work? With a few changes, yes
- [ ] ...?

changelog: Clippy now uses a lint to generate its documentation 🎉
2021-07-28 15:06:26 +02:00
xFrednet
322a768c77
Adapting the lint list to Clippy's new metadata format
Changes included:
    - Minimum adaption to the new `lints.json` format
    - Fixing filtering for the new `lints.json` format; hardcoding the
      lint groups in the index
    - Recreating the original doc styling for the new format
    - Fixed sytax highlighting for rust,ignore code blocks
    - Fixed markdown table extraction in the metadata collector and
      fixed lint level output
    - Adding the additional information row for lints
    - Changed the website title to Clippy's lint list
    - Flexing the website for mobile users
    - Added (?) references for lint levels and groups
    - Making deprecated lints look dead
    - Removed JS code block language extraction in favor of a rust
      implementation `rust-clippy#7352`
    - Added the suspicious lint group to the lint list
    - Remove trailing whitespaces from index.html
    - Fix code highlighting
    - Use default value if the docVersion is empty

Co-authored-by: Philipp Krones <hello@philkrones.com>
2021-07-28 15:03:55 +02:00
flip1995
9bc5803195
Fix last occurence of **What it does:** 2021-07-28 14:32:02 +02:00
xFrednet
12c61612f7
Update lint documentation to use markdown headlines 2021-07-28 14:31:59 +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
bors
ea988afcda Auto merge of #83484 - JulianKnodt:infer, r=oli-obk,lcnr
Add hir::GenericArg::Infer

In order to extend inference to consts, make an Infer type on hir::GenericArg.
2021-07-27 16:24:45 +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
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
kadmin
74379d4d85 Actually infer args in visitors 2021-07-26 21:15:18 +00: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
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
bors
6d9036bc5f Auto merge of #7484 - camsteffen:author, r=flip1995
Some `clippy::author` improvements

changelog: none

* Use `Debug` instead of re-implementing it for some things
* Fix block trailing expression handing
* Don't double print on stmt/expr with `#[clippy::author]` attribute
2021-07-26 11:41:46 +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
Camille GILLOT
5b914f6e33 Introduce OwnerNode::Crate. 2021-07-25 12:22:47 +02:00
kadmin
8286824ab2 Add inferred args to typeck 2021-07-25 07:28:51 +00: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
fb9b13a69f Fix FP for nonstandard_macro_braces lint 2021-07-24 07:30:22 -04:00
Cameron Steffen
afe5962d38 clippy::author improvements 2021-07-23 17:03:12 -05:00
F3real
045dbb52d5 Clean up unnecessary unwraps 2021-07-23 17:34:27 +02:00
xFrednet
544c462d25 Documented constant expression evaluation for repeat_once 2021-07-23 17:07:43 +02: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
flip1995
26321b35c8
Merge remote-tracking branch 'upstream/master' into rustup 2021-07-19 11:48:49 +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
Cameron Steffen
98c500cf83 Factor BinOp utils 2021-07-17 20:49:19 -05:00
Cameron Steffen
efbf7ca61e Use From to convert BinOpKind 2021-07-17 20:25:26 -05:00
bors
1b0e57800c Auto merge of #87140 - camsteffen:pat-slice-refs, r=oli-obk
Remove refs from Pat slices

Changes `PatKind::Or(&'hir [&'hir Pat<'hir>])` to `PatKind::Or(&'hir [Pat<'hir>])` and others. This is more consistent with `ExprKind`, saves a little memory, and is a little easier to use.
2021-07-16 13:35:48 +00:00
Guillaume Gomez
5c54d04ef6 Rollup merge of #87069 - sexxi-goose:copy_ref_always, r=nikomatsakis
ExprUseVisitor: Treat ByValue use of Copy types as ImmBorrow

r? ```@nikomatsakis```
2021-07-16 10:08:05 +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
Cameron Steffen
81904a413e Remove refs from pat slices 2021-07-15 16:09:57 -05: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
xFrednet
6ce6b29527 Use diagnostic items for intrinsics::transmute, TryInto 2021-07-14 23:34:19 +02:00
xFrednet
6030428fd2 Use diagnostic items for Into, IntoIterator, LinkedList, ptr::null, prt::null_mut 2021-07-14 22:50:59 +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
2ac21889bc Use diagnostic items for BinaryHeap, BTreeMap, BTreeSet, HashMap, HashSet, Borrow, Default 2021-07-14 22:02:59 +02: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
Aman Arora
a9e9b7f9b2 ExprUseVisitor::Delegate consume only when moving 2021-07-14 02:21:08 -04:00
lyj
10910020ec rename possible_borrowed to possible_origin; pass dogfood 2021-07-14 13:46:33 +08:00