Commit Graph

10428 Commits

Author SHA1 Message Date
Hirochika Matsumoto
6c830ff9e4 Run cargo dev new_lint 2021-01-20 18:02:29 +09:00
bors
fb0d7f1714 Auto merge of #6578 - MarijnS95:size-in-element-count-divide-by-byte-size, r=flip1995
size_of_in_element_count: Disable lint on division by byte-size

Fixes #6511

It is fairly common to divide some length in bytes by the byte-size of a single element before creating a `from_raw_parts` slice or similar operation. This lint would erroneously disallow such expressions.

Just in case, instead of simply disabling this lint in the RHS of a division, keep track of the inversion and enable it again on recursive division.

---

changelog: Do not trigger size_of_in_element_count when dividing by element size
2021-01-20 07:24:34 +00:00
Marijn Suijten
d4bf59b6ef size_of_in_element_count: Disable lint on division by byte-size
It is fairly common to divide some length in bytes by the byte-size of a
single element before creating a `from_raw_parts` slice or similar
operation. This lint would erroneously disallow such expressions.

Just in case, instead of simply disabling this lint in the RHS of a
division, keep track of the inversion and enable it again on recursive
division.
2021-01-19 20:05:40 +01:00
Marijn Suijten
391bb218b5 size_of_in_element_count: Separate test file in expressions and functions
An upcoming test case for new expresssion variants make the stderr file
go over 200 lines. Split this test case in two to have a clear
distinction between checking whether the lint is still applying on
all the functions with member counts as argument, versus validating
various member-count expressions that may or may not be invalid.
2021-01-19 20:05:39 +01:00
bors
d71dea40cf Auto merge of #6577 - nahuakang:inspect_then_for_each, r=flip1995
New Lint: inspect_then_for_each

**Work In Progress**

This PR addresses [Issue 5209](https://github.com/rust-lang/rust-clippy/issues/5209) and adds a new lint called `inspect_then_for_each`.

Current seek some guidance.

If you added a new lint, here's a checklist for things that will be
checked during review or continuous integration.

- \[x] Followed [lint naming conventions][lint_naming]
- \[x] Added passing UI tests (including committed `.stderr` file)
- \[x] `cargo test` passes locally
- \[x] Executed `cargo dev update_lints`
- \[x] Added lint documentation
- \[x] Run `cargo dev fmt`

[lint_naming]: https://rust-lang.github.io/rfcs/0344-conventions-galore.html#lints

---

changelog: Add [`inspect_for_each`] lint for the use of `inspect().for_each()` on `Iterators`.
2021-01-19 13:12:39 +00:00
nahuakang
3269070261 Create new lint for the usage of inspect for each. 2021-01-19 11:30:20 +01:00
bors
e21270ba0e Auto merge of #6608 - rail-rain:note_on_as_conversions, r=phansch
Add a note to `as_conversions`

I have seen a couple of examples where there are some misunderstandings of `as_conversions` ([1](https://github.com/rust-lang/rust-clippy/issues/5890#issuecomment-671852546), [2](https://github.com/rust-lang/rust-clippy/issues/6116#issuecomment-704251710) and [3](https://github.com/rust-lang/rust-clippy/issues/6428)). This PR adds the note that explains its purpose and relationship with other `as` related casts. Open question: should I list every related lints for discoverbility, or just suggest how to find these? I chose the former because there's no way to list only and all `as` related lints (e.g. on All the Clippt Lints, 'cast' includes some noises, but `cast_` excludes some) even though I cannot guarantee the list will be updated to include future changes.

---

changelog: Add a note to the document of `as_conversions`
2021-01-19 08:01:56 +00:00
bors
ab1020b162 Auto merge of #6606 - ThibsG:AddTestNeedlessReturn, r=flip1995
Add test for `needless_return` lint

Just a follow up of #6549 that adds a test for this lint.

changelog: none
2021-01-19 07:30:55 +00:00
rail
c53192c347 Add a note to as_conversions
… to clalify its purpose.
2021-01-19 12:58:48 +13:00
ThibsG
e33ab3fdd8 Add test for needless_return lint 2021-01-18 22:33:25 +01:00
bors
91292f1eef Auto merge of #6585 - Daniel-B-Smith:false-positive-issue, r=flip1995
Explicitly document false positives

Adds documentation for known false positives for the `await_holding*` lints.

Issues:

https://github.com/rust-lang/rust-clippy/issues/6353
https://github.com/rust-lang/rust-clippy/issues/6446

changelog: document FPs for the ``await_holding_*`` lints
2021-01-17 17:14:13 +00:00
bors
990e2b35b2 Auto merge of #6528 - Jarcho:redundant_slicing, r=flip1995
New lint: redundant_slicing

changelog: Added lint: `redundant_slicing`
fixes #6519

This will trigger on any type which implements `Index<RangeFull>` that returns the input type. This would be a false positive if the implementation does something other than return itself, but I'm not sure why you would ever want to do that.
2021-01-17 16:26:28 +00:00
bors
e0d331fbf4 Auto merge of #6582 - rail-rain:ice_6539, r=flip1995
Fix the ICE 6539

Fixes #6539

It happened because `zero_sized_map_values` used `layout_of` with types from type aliases, which is essentially the same as the ICE 4968.

---

changelog: Fix an ICE in `zero_sized_map_values`
2021-01-17 15:38:50 +00:00
bors
40ce9f83b6 Auto merge of #6549 - ThibsG:FixClosureNeedlessReturn, r=phansch
Fix FP with empty return for `needless_return` lint

This fixes a false positive in `needless_return` lint, when triggered in a closure using `return` statement without value.

Fixes: #6501

changelog: none
2021-01-17 10:29:10 +00:00
Jason Newcomb
9146a77032
Update clippy_lints/src/redundant_slicing.rs
Co-authored-by: Philipp Krones <hello@philkrones.com>
2021-01-15 16:41:24 -05:00
Jason Newcomb
bf028b3f4a
fix copy-paste error 2021-01-15 16:41:22 -05:00
Jason Newcomb
27c0d6c14b
don't lint external macro expansions 2021-01-15 16:41:20 -05:00
Jason Newcomb
2a41d40807
fix new lint error 2021-01-15 16:41:17 -05:00
Jason Newcomb
837bc99065
Initial implementation of redundant_slicing lint 2021-01-15 16:41:13 -05:00
bors
3577cf79de Auto merge of #6500 - Javier-varez:case_sensitive_file_extensions, r=llogiq
Case sensitive file extensions

Closes #6425

Looks for ends_with methods calls with case sensitive extension comparisons.

changelog: Add new lint that warns about case-sensitive file extension comparisons.
2021-01-15 19:49:39 +00:00
ThibsG
46aa654c2d Fix test due to recent Rustup merge 2021-01-15 18:58:48 +01:00
ThibsG
83f1abff48 Fix FP with empty return for needless_return lint 2021-01-15 18:57:56 +01:00
bors
2d1e129851 Auto merge of #6574 - Jarcho:single_match_eq, r=Manishearth
single_match: suggest `if` over `if let` when possible

fixes: #173
changelog: single_match: suggest `if` over `if let` when possible
2021-01-15 16:25:03 +00:00
bors
9490fdca09 Auto merge of #6589 - giraffate:add_notes_of_prioritization_labels_to_doc, r=flip1995
Add notes of prioritization labels to doc

Refer to https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/New.20prioritization.20labels.

changelog: none
2021-01-15 10:40:35 +00:00
Philipp Krones
8a77f63879
Fix formulations in label descriptions 2021-01-15 11:30:58 +01:00
bors
9ea66e946e Auto merge of #6555 - stanislav-tkach:patch-1, r=flip1995
Remove duplication in the manual_ok_or lint example

changelog: none
2021-01-15 10:27:47 +00:00
bors
953f024793 Auto merge of #6586 - flip1995:rustup, r=flip1995
Rustup

r? `@ghost`

changelog: FP fix: [`needless_return`] no longer triggers inside macros.
2021-01-15 09:48:15 +00:00
flip1995
f18cf82ca8
Don't trigger needless_return lint in macros 2021-01-15 10:41:29 +01:00
flip1995
0c5ba9a883
Bump nightly version to 2021-01-15 2021-01-15 10:40:17 +01:00
flip1995
9bd037d0b5
Merge remote-tracking branch 'upstream/master' into rustup 2021-01-15 10:39:53 +01:00
Jason Newcomb
36ff2f739c
Rename function 2021-01-14 22:02:04 -05:00
Takayuki Nakata
d72cb252f2 Add notes of prioritization labels to doc 2021-01-15 09:17:43 +09:00
Jason Newcomb
85edd65bf6
Address review comments
Add: attempt to remove address of expressions from the scrutinee expression before adding references to the pattern
2021-01-14 14:26:26 -05:00
bors
7b3af4145b Auto merge of #79328 - c410-f3r:hir-if, r=matthewjasper
Reintroduce hir::ExprKind::If

Basically copied and paste #59288/https://github.com/rust-lang/rust-clippy/pull/4080 with some modifications.

The vast majority of tests were fixed and now there are only a few remaining. Since I am still unable to figure out the missing pieces, any help with the following list is welcome.

- [ ] **Unnecessary `typeck` exception**: [Cheated on this one to make CI green.](https://github.com/rust-lang/rust/pull/79328/files#diff-3faee9ba23fc54a12b7c43364ba81f8c5660045c7e1d7989a02a0cee1c5b2051)
- [x] **Incorrect span**: [Span should reference `then` and `else` separately.](https://github.com/rust-lang/rust/pull/79328/files#diff-cf2c46e82222ee4b1037a68fff8a1af3c4f1de7a6b3fd798aacbf3c0475abe3d)
- [x] **New note regarding `assert!`**: [Modified but not "wrong". Maybe can be a good thing?](https://github.com/rust-lang/rust/pull/79328/files#diff-9e0d7c89ed0224e2b62060c957177c27db43c30dfe3c2974cb6b5091cda9cfb5)
- [x] **Inverted report location**: [Modified but not "wrong". Locations were inverted.](https://github.com/rust-lang/rust/pull/79328/files#diff-f637ce7c1f68d523a165aa9651765df05e36c4d7d279194b1a6b28b48a323691)
- [x] **`src/test/ui/point-to-type-err-cause-on-impl-trait-return.rs` has weird errors**: [Not sure why this is happening.](https://github.com/rust-lang/rust/pull/79328/files#diff-c823c09660f5b112f95e97e8ff71f1797b6c7f37dbb3d16f8e98bbaea8072e95)
- [x] **Missing diagnostic**: [???](https://github.com/rust-lang/rust/pull/79328/files#diff-6b8ab09360d725ba4513933827f9796b42ff9522b0690f80b76de067143af2fc)
2021-01-14 14:41:58 +00:00
Daniel Smith
02f99bea87 Explicitly document false positives 2021-01-13 16:08:15 -05:00
bors
dcd8c8e739 Auto merge of #77524 - Patryk27:fixes/66228, r=estebank
Rework diagnostics for wrong number of generic args (fixes #66228 and #71924)

This PR reworks the `wrong number of {} arguments` message, so that it provides more details and contextual hints.
2021-01-13 20:35:58 +00:00
bors
00586dfdcd Auto merge of #6584 - giraffate:make_references_to_issues_links, r=llogiq
Make a reference a link in doc

I think it's incovenient that references in doc are just a text.

changelog: none
2021-01-13 08:16:43 +00:00
Joshua Nelson
dfb41f4797 Separate out a hir::Impl struct
This makes it possible to pass the `Impl` directly to functions, instead
of having to pass each of the many fields one at a time. It also
simplifies matches in many cases.
2021-01-12 20:32:33 -05:00
Takayuki Nakata
ea028497ed Make a reference a link in doc 2021-01-13 09:21:26 +09:00
rail
feee45c872 Fix the ICE 6539
It happened because `zero_sized_map_values` used `layout_of` with types
from type aliases, which is essentially the same as the ICE 4968.
2021-01-13 12:07:33 +13:00
bors
13ca5c88f1 Auto merge of #6462 - flip1995:roadmap, r=flip1995,llogiq,killercup,Manishearth,oli-obk,matthiaskrgr,phansch,mikerite,mcarton,yaahc,ebroto
Roadmap for 2021

[Rendered](https://github.com/flip1995/rust-clippy/blob/roadmap/doc/roadmap-2021.md)

This is the first time Clippy gets its own roadmap. The reason for this roadmap is, that with the Rust language growing, also Clippy is growing. With this keeping track of and implementing bigger projects gets quite hard. This roadmap should help in exactly this regard.

After having the approval of this roadmap by the Clippy team, we want to know from the community:

- What do you think in general about this roadmap?
- Are there any pain points in Clippy, that should be included here?
- What of the points listed here has the highest priority for you?

We're looking forward to getting your feedback!

changelog: Add roadmap for Clippy 2021

r? `@rust-lang/clippy`
2021-01-12 16:33:47 +00:00
bors
7f4599a848 Auto merge of #6557 - rail-rain:extending_cast_ptr_alignment, r=phansch
Catch `pointer::cast` too in `cast_ptr_alignment`

Fixes #4708

Although there were some discussion in the issue, this PR implements the original feature. I think `cast_ptr_alignment` should exist as it is, separated from `ptr_as_ptr`.

---

changelog: Extend `cast_ptr_alignment` lint for the `pointer::cast` method
2021-01-11 22:03:46 +00:00
rail
53f87310cd Simplify cast_ptr_alignment pointer::casr case 2021-01-12 10:06:41 +13:00
bors
1eed27f374 Auto merge of #6575 - flip1995:stop_linting_deps, r=Manishearth
Change env var used for testing Clippy

This changes the variable used for testing Clippy in the internal test
suite:

```
CLIPPY_TESTS -> __CLIPPY_INTERNAL_TESTS
```

`CLIPPY_TESTS` is understandably used in environments of Clippy users,
so we shouldn't use it in our test suite.

changelog: Fix oversight which caused Clippy to lint deps in some environments.

Once again fixes https://github.com/rust-lang/rust-clippy/issues/3874
2021-01-11 16:49:32 +00:00
Jason Newcomb
8d7417d807
Add: single_match will suggest using if .. == .. instead of if let when applicable 2021-01-10 23:32:23 -05:00
Patryk Wychowaniec
2c6dc8801f Rework diagnostics for wrong number of generic args 2021-01-10 13:07:40 +01:00
Vadim Petrochenkov
9e45a23ab9 ast: Remove some indirection layers from values in key-value attributes 2021-01-09 21:50:39 +03:00
bors
583715f583 Auto merge of #6565 - giraffate:small_fixes_of_doc_in_needless_question_mark, r=phansch
Small fixes of doc in `needless_question_mark`

changelog: none
2021-01-09 15:28:10 +00:00
bors
ee0598e254 Auto merge of #6571 - ThibsG:BoxedLocalTrait, r=phansch
Fix FP for `boxed_local` lint in default trait fn impl

Fix FP on default trait function implementation on `boxed_local` lint.

Maybe I checked too much when looking if `self` is carrying `Self` in its bound type.
I can't find a good test case for this, so it could be too much conservative.
Let me know if you think only detecting `self` parameter is enough.

Fixes: #4804

changelog: none
2021-01-09 13:42:28 +00:00
ThibsG
8a6fea4fb8 Fix FP for boxed_local lint in default trait fn impl 2021-01-09 12:26:24 +01:00