Commit graph

3078 commits

Author SHA1 Message Date
Manish Goregaokar
5c957b8a6f Merge remote-tracking branch 'origin/master' into rustup 2021-02-02 16:46:12 -08:00
Caden Haustein
bde667af7e
Add missing_panics_doc lint 2021-02-02 16:36:32 +01:00
bors
f870876d92 Auto merge of #6659 - phlip9:let_and_return_fix, r=phansch
Fix let_and_return false positive

The issue:

See this Rust playground link: https://play.rust-lang.org/?edition=2018&gist=12cb5d1e7527f8c37743b87fc4a53748

Run the above with clippy to see the following warning:

```
warning: returning the result of a `let` binding from a block
  --> src/main.rs:24:5
   |
23 |     let value = Foo::new(&x).value();
   |     --------------------------------- unnecessary `let` binding
24 |     value
   |     ^^^^^
   |
   = note: `#[warn(clippy::let_and_return)]` on by default
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#let_and_return
help: return the expression directly
   |
23 |
24 |     Foo::new(&x).value()
   |
```

Implementing the suggested fix, removing the temporary let binding,
yields a compiler error:

```
error[E0597]: `x` does not live long enough
  --> src/main.rs:23:14
   |
23 |     Foo::new(&x).value()
   |     ---------^^-
   |     |        |
   |     |        borrowed value does not live long enough
   |     a temporary with access to the borrow is created here ...
24 | }
   | -
   | |
   | `x` dropped here while still borrowed
   | ... and the borrow might be used here, when that temporary is dropped and runs the `Drop` code for type `Foo`
   |
   = note: the temporary is part of an expression at the end of a block;
           consider forcing this temporary to be dropped sooner, before the block's local variables are dropped
help: for example, you could save the expression's value in a new local variable `x` and then make `x` be the expression at the end of the block
   |
23 |     let x = Foo::new(&x).value(); x
   |     ^^^^^^^                     ^^^
```

The fix:

Of course, clippy looks like it should already handle this edge case;
however, it appears `utils::fn_def_id` is not returning a `DefId` for
`Foo::new`. Changing the `qpath_res` lookup to use the child Path
`hir_id` instead of the parent Call `hir_id` fixes the issue.

changelog: none
2021-02-02 15:04:35 +00:00
Philipp Krones
4a13c8c22e
Fix test formatting 2021-02-02 08:59:23 +01:00
Manish Goregaokar
0fb09d6b21 exhaustive_structs: don't trigger for structs with private fields 2021-02-01 18:42:08 -08:00
bors
9607b5c6ac Auto merge of #80851 - m-ou-se:panic-2021, r=petrochenkov
Implement Rust 2021 panic

This implements the Rust 2021 versions of `panic!()`. See https://github.com/rust-lang/rust/issues/80162 and https://github.com/rust-lang/rfcs/pull/3007.

It does so by replacing `{std, core}::panic!()` by a bulitin macro that expands to either `$crate::panic::panic_2015!(..)` or `$crate::panic::panic_2021!(..)` depending on the edition of the caller.

This does not yet make std's panic an alias for core's panic on Rust 2021 as the RFC proposes. That will be a separate change: c5273bdfb2 That change is blocked on figuring out what to do with https://github.com/rust-lang/rust/issues/80846 first.
2021-02-01 10:25:31 +00:00
bors
c5f3f9df3b Auto merge of #6603 - ThibsG:MatchOverlappingArm5986, r=flip1995
Do not lint when range is completely included into another one

This fix has been developed following this [comment](https://github.com/rust-lang/rust-clippy/issues/5986#issuecomment-703313548).
So this will be linted:
```
|----------|
        |-----------|
```
Now this won't be linted:
```
              |---|
|--------------------|
```
and this will still lint:
```
|--------|
|--------------|
```

Fixes: #5986

changelog: Fix FPs in match_overlapping_arm, when first arm is completely included in second arm
2021-01-31 15:09:55 +00:00
Mara Bos
3a0ae08ae2 Update clippy test output for panic macros. 2021-01-30 19:33:21 +01:00
flip1995
ac912be984 Merge commit '95c0459217d1661edfa794c8bb122452b92fb485' into clippyup 2021-01-30 18:06:34 +01:00
flip1995
e2859437f9
Merge remote-tracking branch 'upstream/master' into rustup 2021-01-30 15:51:16 +01:00
Philip Hayes
7f1595e18f Fix let_and_return false positive
The issue:

See this Rust playground link: https://play.rust-lang.org/?edition=2018&gist=12cb5d1e7527f8c37743b87fc4a53748

Run the above with clippy to see the following warning:

```
warning: returning the result of a `let` binding from a block
  --> src/main.rs:24:5
   |
23 |     let value = Foo::new(&x).value();
   |     --------------------------------- unnecessary `let` binding
24 |     value
   |     ^^^^^
   |
   = note: `#[warn(clippy::let_and_return)]` on by default
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#let_and_return
help: return the expression directly
   |
23 |
24 |     Foo::new(&x).value()
   |
```

Implementing the suggested fix, removing the temporary let binding,
yields a compiler error:

```
error[E0597]: `x` does not live long enough
  --> src/main.rs:23:14
   |
23 |     Foo::new(&x).value()
   |     ---------^^-
   |     |        |
   |     |        borrowed value does not live long enough
   |     a temporary with access to the borrow is created here ...
24 | }
   | -
   | |
   | `x` dropped here while still borrowed
   | ... and the borrow might be used here, when that temporary is dropped and runs the `Drop` code for type `Foo`
   |
   = note: the temporary is part of an expression at the end of a block;
           consider forcing this temporary to be dropped sooner, before the block's local variables are dropped
help: for example, you could save the expression's value in a new local variable `x` and then make `x` be the expression at the end of the block
   |
23 |     let x = Foo::new(&x).value(); x
   |     ^^^^^^^                     ^^^
```

The fix:

Of course, clippy looks like it should already handle this edge case;
however, it appears `utils::fn_def_id` is not returning a `DefId` for
`Foo::new`. Changing the `qpath_res` lookup to use the child Path
`hir_id` instead of the parent Call `hir_id` fixes the issue.
2021-01-29 22:19:09 -08:00
bors
8d57cee9ca Auto merge of #6617 - Manishearth:exhaustive_enums, r=camsteffen
New lint: exhaustive_enums, exhaustive_structs

Fixes #6616

changelog: Added restriction lint: `exhaustive_enums`, `exhaustive_structs`
2021-01-25 23:06:39 +00:00
Manish Goregaokar
3e3dff7135 Add test with attrs 2021-01-25 14:39:03 -08:00
ThibsG
051891173d Add more tests for match_overlapping_arm lint 2021-01-24 12:28:59 +01:00
bors
70386ff352 Auto merge of #6403 - camsteffen:similar-names-underscore, r=Manishearth
Similar names ignore underscore prefixed names

changelog: Ignore underscore-prefixed names for similar_names

IMO, this lint is not very helpful for underscore-prefixed variables. Usually they are unused or are just there to ignore part of a destructuring.
2021-01-22 23:44:12 +00:00
bors
41d750c76c Auto merge of #6619 - camsteffen:collapsible-match, r=camsteffen
Improve collapsible_match

changelog: Fix collapsible_match false negatives

Allow `&` and/or `*` on the binding and make sure the type still matches.
2021-01-22 22:45:43 +00:00
Cameron Steffen
66afdd1f42 Enhance collapsible_match for adjusted bindings 2021-01-22 16:44:47 -06:00
Manish Goregaokar
65d003a112 Clean up suggestion span; clarify help message 2021-01-22 12:08:47 -08:00
Manish Goregaokar
752274eabd Fix indentation of suggestion 2021-01-22 11:59:36 -08:00
Manish Goregaokar
8cb7e85006 Add exhaustive_structs lint 2021-01-22 11:59:36 -08:00
bors
a1b89f07f0 Auto merge of #81135 - jyn514:no-backticks, r=flip1995
Fix formatting for removed lints

- Don't add backticks for the reason a lint was removed. This is almost
never a code block, and when it is the backticks should be in the reason
itself.
- Don't assume clippy is the only tool that needs to be checked for
backwards compatibility

I split this out of https://github.com/rust-lang/rust/pull/80527/ because it kept causing tests to fail, and it's a good change to have anyway.

r? `@flip1995`
2021-01-22 06:13:19 +00:00
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
Manish Goregaokar
09d4d49299 ExhaustiveEnums -> ExhaustiveItems 2021-01-21 13:39:00 -08:00
Manish Goregaokar
f6cb96ef07 Make exhaustive_enums only warn on exported items 2021-01-21 13:34:44 -08:00
Manish Goregaokar
f1ab3024b2 New lint: exhaustive_enums 2021-01-21 13:31:06 -08: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
Ashley Mannix
9009f8f031 Rollup merge of #81038 - flip1995:clippyup, r=Manishearth
Update Clippy

Biweekly Clippy update

r? ``@Manishearth``
2021-01-18 21:53:22 +10:00
kai.giebeler
c3244c25ac add test for doc_valid_idents "WebGL" 2021-01-17 22:57:08 +01:00
Joshua Nelson
abb40c965f Fix formatting for removed lints
- Don't add backticks for the reason a lint was removed. This is almost
never a code block, and when it is the backticks should be in the reason
itself.
- Don't assume clippy is the only tool that needs to be checked for
backwards compatibility
2021-01-17 16:18:02 -05:00
ThibsG
70704db36f Do not lint when range is completely included into another one 2021-01-17 21:07:01 +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
flip1995
7449dc96c0 Deprecate unknown_clippy_lints
This is now handled by unknown_lints
2021-01-16 19:44:46 +01:00
Jason Newcomb
837bc99065
Initial implementation of redundant_slicing lint 2021-01-15 16:41:13 -05:00