Commit graph

3048 commits

Author SHA1 Message Date
Cameron Steffen
a752d31e0a Replace find_map with manual_find_map 2021-01-21 18:18:21 -06:00
Cameron Steffen
c92bdc4dbb Split filter_map into manual_filter_map 2021-01-21 18:18:18 -06:00
bors
043cf97abc Auto merge of #6609 - giraffate:fix_wrong_suggestion_of_ref_in_deref, r=llogiq
Fix a wrong suggestion of `ref_in_deref`

Fix #6358.

changelog: Fix a wrong suggestion of `ref_in_deref`
2021-01-21 19:16:11 +00:00
bors
4d381c3a84 Auto merge of #6605 - kawogi:doc-markdown, r=llogiq
Doc markdown

I added "WebGL" along the lines of the existing "OpenGL" to the whitelist of `doc_markdown` as I found this to be a pretty common term.

(this is a follow-up of the now closed https://github.com/rust-lang/rust-clippy/pull/6388)

changelog: Whitelist "WebGL" in `doc_markdown`.
2021-01-21 19:05:50 +00:00
bors
a982ab4cee Auto merge of #6532 - matthiaskrgr:mlmm, r=llogiq
match_like_matches_macro: strip refs in suggestion

fixes #6503

changelog: match_like_matches_macro: strip refs in suggestion (#6503)
2021-01-21 18:34:55 +00:00
bors
7b50a4ead7 Auto merge of #6408 - pro-grammer1:master, r=oli-obk
Fix false positive in write_literal and print_literal (numeric literals)

changelog: No longer lint numeric literals in [`write_literal`] and [`print_literal`].

Fixes #6335
2021-01-21 14:23:25 +00:00
pastchick3
e42208f1b7 Improve the suggestion message of stable_sort_primitive. 2021-01-21 20:44:52 +08:00
Hirochika Matsumoto
ab1da8f865 Add new lint upper_case_acronyms 2021-01-20 18:03:06 +09:00
Hirochika Matsumoto
6c830ff9e4 Run cargo dev new_lint 2021-01-20 18:02:29 +09: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
Takayuki Nakata
966320642b Fix a wrong suggestion of ref_in_deref 2021-01-20 00:21:33 +09: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
ThibsG
e33ab3fdd8 Add test for needless_return lint 2021-01-18 22:33:25 +01:00
kai.giebeler
c3244c25ac add test for doc_valid_idents "WebGL" 2021-01-17 22:57:08 +01:00
pro-grammer1
32b2a3f944 Add numeric literals to the write_literal and print_literal tests that shouldn't fail 2021-01-17 19:21:33 +00:00
pro-grammer1
fb2a06dcce Remove numeric literals from print_literal and write_literal tests 2021-01-17 18:55:59 +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
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
flip1995
f18cf82ca8
Don't trigger needless_return lint in macros 2021-01-15 10:41:29 +01:00
flip1995
9bd037d0b5
Merge remote-tracking branch 'upstream/master' into rustup 2021-01-15 10:39:53 +01: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
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
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
Jason Newcomb
8d7417d807
Add: single_match will suggest using if .. == .. instead of if let when applicable 2021-01-10 23:32:23 -05: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
rail
ee9b47dae6 Move is_hir_ty_cfg_dependant to util,
add stuff on pointer::cast` to the document for `cast_ptr_alignment`
and fix line numbers in the test.
2021-01-08 14:15:12 +13:00
Takayuki Nakata
0e14a75506 Reduce the span in from_over_into to impl header 2021-01-08 09:16:11 +09:00
Caio
7d42172899 Reintroduce hir::ExprKind::If 2021-01-07 18:54:12 -03:00
rail
f50ded0592 Catch pointer::cast too in cast_ptr_alignment 2021-01-07 16:56:19 +13:00
Philipp Hansch
92f2bbbe06
Fix macro issues with field_reassign_with_default 2021-01-05 20:31:13 +01:00
Javier Alvarez
61f3d9d46b Add case_sensitive_file_extensions lint
Closes #6425

Looks for ends_with methods calls with case sensitive extensions.
2021-01-05 14:22:26 +01:00
bors
a6b72d378f Auto merge of #6542 - rail-rain:ptr_as_ptr, r=flip1995
Add a new lint `ptr_as_ptr`

This PR adds a new lint `ptr_as_ptr` which checks for `as` casts between raw pointers without changing its mutability and suggest replacing it with `pointer::cast`. Closes #5890.

Open question: should this lint be `pedantic` or `style`? I set it `pedantic` for now because the original post suggests using it, but I think the lint also fits well to `style`.

---

changelog: New lint `ptr_as_ptr`
2021-01-05 09:54:34 +00:00
bors
311186b9bb Auto merge of #6513 - nahuakang:fix/empty_enum_lint_never_type, r=flip1995
Fix: Empty enum never type suggested only if the feature is enabled

This PR addresses [Issue 6422](https://github.com/rust-lang/rust-clippy/issues/6422). Instead of always recommending `never type` for empty enums, Clippy would only recommend [the lint](https://rust-lang.github.io/rust-clippy/master/index.html#empty_enum) if [LatePass.TyCtxt](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/context/struct.TyCtxt.html) has `features().never_type` enabled.

- \[ ] 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`
---

*Please write a short comment explaining your change (or "none" for internal only changes)*
changelog: Only trigger [`empty_enum`] lint if `never_type` feature is enabled.
2021-01-05 09:37:19 +00:00
rail
dfa5d7e818 Fix the MSRV and add the tests for MSRV 2021-01-05 10:21:55 +13:00
rail
4b478a5731 Add a new lint ptr_as_ptr,
which checks for `as` casts between raw pointers
without changing its mutability
and suggest replacing it with `pointer::cast`.
2021-01-05 10:19:03 +13:00
bors
976850b69b Auto merge of #6538 - Jarcho:vec_init_then_push, r=llogiq
New lint: vec_init_then_push

fixes: #1483

This will trigger on `new`, `default`, and `with_capacity` when the given capacity is less than or equal to the number of push calls. Is there anything else this should trigger on?

changelog: Added lint: `vec_init_then_push`
2021-01-04 20:42:18 +00:00
nahuakang
a8d47b4b78 Run cargo dev fmt 2021-01-04 18:41:42 +01:00
nahuakang
bc97f5d215 Address flip1995's review comments 2021-01-04 18:34:05 +01:00
bors
ae9ae9713c Auto merge of #6507 - bengsparks:lint/issue6410, r=flip1995
Needless Question Mark Lint

Fixes #6410, i.e the needless question mark lint

changelog: [`needless_question_mark`] New lint
2021-01-04 14:17:24 +00:00
Benjamin Sparks
ba87acb440
Implemented needless question mark lint 2021-01-04 14:51:48 +01:00
Matthias Krüger
6dcec6ae86 collapsible_if: split collapsible_else_if into its own lint so we can enable/disable it particularly
This splits up clippy::collapsible_if into collapsible_if for
if x {
  if y { }
}
=>
if x && y { }

and collapsible_else_if for

if x {
} else {
 if y { }
}

=>
if x {

} else if y {

}

so that we can lint for only the latter but not the first if we desire.

changelog: collapsible_if: split up linting for if x {} else { if y {} } into collapsible_else_if lint
2021-01-04 13:34:14 +01:00