Commit graph

11338 commits

Author SHA1 Message Date
Philipp Hansch
cbdebd97ec Explain why we use char_indices() instead of chars() 2021-04-14 06:30:51 +02:00
Philipp Hansch
47a4865406 Fix dogfood 2021-04-10 15:30:51 +02:00
Philipp Hansch
8b9331b49d Fix rustfmt error / Add comment for tab character 2021-04-10 14:43:52 +02:00
Philipp Hansch
dde46c9340 Replace complex conditional with pattern matching 2021-04-10 14:42:33 +02:00
Philipp Hansch
1573d10325
tabs_in_doc_comments: Fix ICE due to char indexing
This is a quick-fix for an ICE in `tabs_in_doc_comments`. The problem
was that we we're indexing into possibly multi-byte characters, such as '位'.

More specifically `get_chunks_of_tabs` was returning indices into
multi-byte characters. Those were passed on to a `Span` creation that
then caused the ICE.

This fix makes sure that we don't return indices that point inside a
multi-byte character. *However*, we are still iterating over unicode
codepoints, not grapheme clusters. So a seemingly single character like y̆ ,
which actually consists of two codepoints, will probably still cause
incorrect spans in the output.
2021-04-06 07:20:55 +02:00
bors
e315437bd6 Auto merge of #7031 - xFrednet:5234-quick-fix-dark-mode-themes, r=llogiq
Quick fix for the updated website theaming to access the correct css files

This fixes a problem from #7030 that the service used to access css files was blocked by GitHub pages due to `SSL_ERROR_BAD_CERT_DOMAIN`. The css file loading worked fine during local development. The browser probably disabled some security options due to the local address.

This fix works locally and should also work online as it references the direct css files used by the [mdBook User Guide](https://rust-lang.github.io/mdBook/index.html) the disadvantage of this is that refactorings within the mdBook project can have effects on the theme loading of Clippy. This PR is therefor more meant as a quick fix until I find a better solution.

I've tested these changes using the page editor in the browser and can now confirm that they work :)

changelog: none

r?  `@llogiq`
2021-04-05 07:45:05 +00:00
bors
a15d987c8f Auto merge of #7021 - camsteffen:7012, r=giraffate
Fix ICE #7012

changelog: none

Fixes #7012
2021-04-04 23:51:31 +00:00
xFrednet
da04e873b3 Quick fix to access the correct css files 2021-04-04 20:15:41 +02:00
bors
6bb608c00c Auto merge of #7030 - xFrednet:6877-clippy-going-dark, r=llogiq
Clippy going dark: Adding a dark theme to Clippy's lint list

This PR adds the MdBook color themes to the lint list of Clippy. Well at least an adaption of these themes.

<details>
<summary>Here are some beautiful screenshots:</summary>

**light theme**
![image](https://user-images.githubusercontent.com/17087237/113510593-e31fb280-955b-11eb-8ab1-8b5bcf287475.png)

**Rust theme**
![image](https://user-images.githubusercontent.com/17087237/113510734-79ec6f00-955c-11eb-981c-8ebe890acf79.png)

**Coal theme**
![image](https://user-images.githubusercontent.com/17087237/113510752-8ec90280-955c-11eb-8f5c-c87ca07c35c2.png)

**Navy theme**
![image](https://user-images.githubusercontent.com/17087237/113510675-3f82d200-955c-11eb-8992-8c784abe19ea.png)

**Ayu theme**
![image](https://user-images.githubusercontent.com/17087237/113510700-588b8300-955c-11eb-83e0-a8f770e9f913.png)

</details>

The theme is also stored in the browser to ensure that the next session applies the theme and doesn't burn your eyes out.

cc: `@matthiaskrgr`

---

Closes #6877

changelog: [Clippy's lint list](https://rust-lang.github.io/rust-clippy/master/index.html) now supports themes
2021-04-04 16:59:14 +00:00
xFrednet
e25b1060f5 Adding a dark theme to the clippy lint list 2021-04-04 15:36:30 +02:00
Cameron Steffen
7014340d57 Fix ICE 2021-04-03 14:17:58 -05:00
bors
86fb0e8266 Auto merge of #7020 - camsteffen:needless-collect, r=Manishearth
Improve needless_collect output

changelog: Improve needless_collect output

Fixes #6908
Partially addresses #6164
2021-04-02 15:27:54 +00:00
Cameron Steffen
33798bb064 Improve needless_collect output 2021-04-02 10:10:54 -05:00
bors
9ce23730e2 Auto merge of #7016 - camsteffen:bind-map-paths, r=Manishearth
Remove paths from bind_instead_of_map

changelog: none
2021-04-02 15:10:24 +00:00
Cameron Steffen
4356a8f8f7 Remove redundant emit() 2021-04-02 09:38:13 -05:00
Cameron Steffen
a064534b9e Refactor needless_collect 2021-04-02 08:41:05 -05:00
bors
1931db20b1 Auto merge of #6988 - mikerite:fix-6984, r=camsteffen
Fix hidden variant suggestion on single variant

Fixes #6984

changelog: Fix hidden variant suggestion on `match_wildcard_for_single_variants`
2021-04-02 12:42:40 +00:00
Cameron Steffen
08a8ad3a36 Remove paths from bind_instead_of_map 2021-04-01 15:41:25 -05:00
bors
72eb60a28b Auto merge of #7013 - Y-Nak:fix-needless-paren, r=flip1995
clippy_utils: fix needless parenthesis output from sugg::Sugg::maybe_par

changelog: clippy_utils: fix needless parenthesis output from `sugg::Sugg::maybe_par`

fixes: #6767
2021-04-01 15:09:46 +00:00
bors
92c4fc3cd8 Auto merge of #7011 - Jarcho:redundant_clone_fp, r=flip1995
Fix `redundant_clone` fp

fixes: #5973
fixes: #5595
fixes: #6998

changelog: Fix `redundant_clone` fp  where the cloned value is modified while the clone is in use.
2021-04-01 14:06:04 +00:00
bors
38b1fd0fa7 Auto merge of #7002 - mgacek8:issue6983_wrong_self_convention_inside_trait_impls, r=phansch
wrong_self_convention: fix FP inside trait impl for `to_*` method taking `&self`

fixes #6983
changelog: `wrong_self_convention`: fix FP inside trait impl for `to_*` method taking `&self`
2021-04-01 05:48:16 +00:00
bors
75d73e95a0 Auto merge of #6976 - Jarcho:manual_map_const, r=phansch
Don't lint `manual_map` in const functions

fixes: #6967

changelog: Don't lint `manual_map` in const functions
2021-04-01 05:34:34 +00:00
Yoshitomo Nakanishi
6325fe1f54 clippy_utils: fix needless parenthesis output from sugg::Sugg::maybe_par 2021-04-01 10:40:44 +09:00
bors
8cf7d9b037 Auto merge of #7010 - camsteffen:if-chain-lint, r=llogiq
Internal `if_chain!` lints

changelog: none

We use `if_chain!` a lot. So this enforces some style rules around it, internal only.

Lints when...
* Nested `if`/`if_chain!` can be collapsed
* An `if_chain!` starts with `let` or ends with `let ..; then {..}`
* An `if_chain!` has only one `if`
* An `if_chain!` contains `if .. && ..;` that spans multiple lines
2021-03-31 21:57:48 +00:00
Jason Newcomb
aaba9b78a2
Fix redundant_clone fp where the cloned value is modified while the clone is in use. 2021-03-31 15:35:34 -04:00
Cameron Steffen
827d6aaad4 Eat dogfood 2021-03-31 14:06:27 -05:00
Cameron Steffen
5f887d09b8 Add if_chain lints 2021-03-31 14:06:27 -05:00
bors
459bca84b7 Auto merge of #7008 - matthiaskrgr:ltchk, r=camsteffen
lintcheck: warn if we get a bad exit status while running clippy

Right now we won't notice if a crate fails to build.
Print a warning message to indicate that there is a problem of some sort.
I'll still have to do more investigation on why this actually happens.

I suspect that the problem is that `clippy fix` might run  --all-targets  but when we download the crate source from crates.io, some path deps (used for internal tests etc...) are not available (which is usually not a problem because the internal tests are not needed when using the crate as a lib..?)

changelog: none
2021-03-31 18:58:52 +00:00
bors
487c2e8d4e Auto merge of #6913 - camsteffen:method-chain, r=flip1995
Destructure args in `methods`

changelog: none

This changes the main pattern in `methods` to match and destructure the method call args at the same time as the method name, and pass individual arg `Expr`s to the lint impls.

```rust
// before
["expect", ..] => expect::check(cx, expr, arg_lists[0]);
// after
("expect", [arg]) => expect::check(cx, expr, recv, arg);
```

This makes the code safer since there is no risk of out of bounds `args[n]` everywhere. There will be no more collecting `method_names`, `arg_lists`, `method_spans` as a separate step - everything comes out of the `match`es. Chained methods are parsed in a nested `match`. This makes the code more verbose in some ways, but IMO it is much easier to follow.

~Definitely should wait for #6896. Just putting out the idea.~
2021-03-31 18:30:32 +00:00
Cameron Steffen
21083875d2 Destructure args in methods module 2021-03-31 13:25:55 -05:00
bors
775ef473d7 Auto merge of #6342 - bbqbaron:issue-6061, r=flip1995
Lint: filter(Option::is_some).map(Option::unwrap)

Fixes #6061

*Please write a short comment explaining your change (or "none" for internal only changes)*
changelog:
* add new lint for filter(Option::is_some).map(Option::unwrap)

First Rust PR, so I'm sure I've violated some idioms. Happy to change anything.

I'm getting one test failure locally -- a stderr diff for `compile_test`. I'm having a hard time seeing how I could be causing it, so I'm tentatively opening this in the hopes that it's an artifact of my local setup against `rustc`. Hoping it can at least still be reviewed in the meantime.

I'm gathering that since this is a method lint, and `.filter(...).map(...)` is already checked, the means of implementation needs to be a little different, so I didn't exactly follow the setup boilerplate. My way of checking for method calls seems a little too direct (ie, "is the second element of the expression literally the path for `Option::is_some`?"), but it seems like that's how some other lints work, so I went with it. I'm assuming we're not concerned about, eg, closures that just end up equivalent to `Option::is_some` by eta reduction.
2021-03-31 16:19:07 +00:00
bors
c1021b806c Auto merge of #6706 - Y-Nak:excessive-for-each, r=camsteffen
New Lint: needless_for_each

resolves: #6543

changelog: Added pedantic lint: `needless_for_each`
2021-03-31 15:59:55 +00:00
Eric Loren
56fbbf7b8f Suggest flatten instead of is_some -> unwrap 2021-03-31 11:35:24 -04:00
Yoshitomo Nakanishi
e61f9782c8 Tweak a suggestion message of needless_for_each 2021-04-01 00:08:59 +09:00
Yoshitomo Nakanishi
bf1e3f7a9f Skip needless_for_each if an input stmt is local 2021-04-01 00:05:42 +09:00
Yoshitomo Nakanishi
1109dc8838 Fix codes that make dogfood fail 2021-04-01 00:05:42 +09:00
Yoshitomo Nakanishi
f2cc995bcf Remove method_calls 2021-04-01 00:05:42 +09:00
Yoshitomo Nakanishi
527fbbef48 Refactor excessive_for_each 2021-04-01 00:05:42 +09:00
Yoshitomo Nakanishi
5543c34699 Use ".." as default value of snippet in excessive_for_each 2021-04-01 00:05:42 +09:00
Yoshitomo Nakanishi
3843171299 Improve the document of excessive_for_each 2021-04-01 00:05:42 +09:00
Yoshitomo Nakanishi
25d8b94cec Add comments to clarify why RetCollector is needed 2021-04-01 00:05:42 +09:00
Yoshitomo Nakanishi
ccd7a60023 Refactor: Remove duplicated codes from excessive_for_each 2021-04-01 00:05:42 +09:00
Yoshitomo Nakanishi
90cbbb2da3 Avoid to suggest using label 2021-04-01 00:05:42 +09:00
Yoshitomo Nakanishi
5bb0f16552 Trigger the lint iff exposure's body is ExprKind::Block. 2021-04-01 00:05:42 +09:00
Yoshitomo Nakanishi
54a04711ed Change a category of excessive_for_each: Style -> Restriction 2021-04-01 00:05:42 +09:00
Yoshitomo Nakanishi
30952530c5 Fix codes that fails dogfood 2021-04-01 00:05:42 +09:00
Yoshitomo Nakanishi
5029dc805f New Lint: excessive_for_each 2021-04-01 00:05:42 +09:00
bors
3e42c35b72 Auto merge of #6981 - matthiaskrgr:6803_take_2, r=flip1995
disable upper_case_acronyms for pub items - enum edition

Fixes https://github.com/rust-lang/rust-clippy/issues/6803 (again... 😅  )

My previous fix did not work for enums because enum variants were checked separately in the `check_variant` function but it looks like we can't use that because we can't tell if the enum the variants belong to is declared as public or not (it always said `Inherited` for me)

I went and special-cased enums and iterated over all the variants "manually", but only, if the enums is not public.

---

changelog: fix upper_case_acronyms still firing on public enums (#6803)
2021-03-31 15:02:40 +00:00
bors
2e33bf6347 Auto merge of #6938 - Y-Nak:refactor-types, r=flip1995
Refactor types

r? `@flip1995`
This is the last PR to close #6724 🎉
Also, this fixes #6936.

changelog: `vec_box`: Fix FN in `const` or `static`
changelog: `linkedlist`: Fix FN in `const` or `static`
changelog: `option_option`: Fix FN in `const` or `static`
2021-03-31 14:35:48 +00:00
Matthias Krüger
225f7e0617 lintcheck: warn if checking a program results in bad exit status 2021-03-31 14:36:56 +02:00