Commit Graph

6892 Commits

Author SHA1 Message Date
Cameron Steffen
2b5257e4c7 Remove method_call! macro 2021-12-30 13:37:14 -06:00
flip1995
97ab44ca97 Merge commit '0eff589afc83e21a03a168497bbab6b4dfbb4ef6' into clippyup 2021-12-30 15:10:43 +01:00
flip1995
e45842e360
Merge remote-tracking branch 'upstream/master' into rustup 2021-12-30 14:17:53 +01:00
Elliot Bobrow
828ddbe414 fix [redundant_closure] fp with Arc 2021-12-29 09:05:04 -08:00
bors
c1cd64b9c6 Auto merge of #8117 - hotate29:issue7320, r=camsteffen
update: ```Sugg::not()``` replacing the comparison operator. #7320

fixes #7320

changelog: ```needless_bool```: Changed to make a smart suggestion.
2021-12-28 22:15:53 +00:00
bors
16ef044e72 Auto merge of #8183 - alex-ozdemir:limit-ident, r=camsteffen
Limit the ``[`identity_op`]`` lint to integral operands.

changelog: limit ``[`identity_op`]`` to integral operands

In the ``[`identity_op`]`` lint, if the operands are non-integers, then the lint is likely
wrong.
2021-12-28 22:01:57 +00:00
bors
a139949ead Auto merge of #8187 - ApamNapat:fix_7651, r=llogiq
Fixed issues with to_radians and to_degrees lints

fixes #7651

I fixed the original problem as described in the issue, but the bug remains for complex expressions (the commented out TC I added is an example). I would also love some feedback on how to cleanup my code and reduce duplication. I hope it's not a problem that the issue has been claimed by someone else - that was over two months ago.

changelog: ``[`suboptimal_flops`]`` no longer proposes broken code with `to_radians` and `to_degrees`
2021-12-28 17:11:40 +00:00
BB
d5c4119d42 Fixed issues with to_radians and to_degrees lints 2021-12-28 17:49:18 +01:00
Alex Ozdemir
ee6d5c5cda contants peel_refs to catch x << &0 2021-12-28 08:32:55 -08:00
Alex Ozdemir
bc0579f5bf test 2021-12-28 08:19:58 -08:00
Guillaume Gomez
dfd32544fa Update pulldown-cmark version in clippy 2021-12-28 16:19:23 +01:00
bors
56ccd30a27 Auto merge of #8127 - dswij:8090, r=xFrednet
Fix `enum_variants` FP on prefixes that are not camel-case

closes #8090

Fix FP on `enum_variants` when prefixes are only a substring of a camel-case word. Also adds some util helpers on `str_utils` to help parsing camel-case strings.

This changes how the lint behaves:

1. previously if the Prefix is only a length of 1, it's going to get ignored, i.e. these were previously ignored and now is warned
```rust
enum Foo {
    cFoo,
    cBar,
    cBaz,
}

enum Something {
    CCall,
    CCreate,
    CCryogenize,
}
```

2. non-ascii characters that doesn't have casing will not be split,
```rust
enum NonCaps {
    PrefixXXX,
    PrefixTea,
    PrefixCake,
}
```
will be considered as `PrefixXXX`, `Prefix`, `Prefix`, so this won't lint as opposed to fired previously.

changelog: [`enum_variant_names`] Fix FP when first prefix are only a substring of a camel-case word.

---

 (Edited by `@xFrednet` removed some non ascii characters)
2021-12-28 12:01:21 +00:00
bors
fc72e910fb needless_return suggest return unit type on void returns
closes #8177

previously, `needless_return` suggests an empty block `{}` to replace void `return` on match arms, this PR improve the suggestion by suggesting a unit instead.

changelog: `needless_return` suggests `()` instead of `{}` on match arms
2021-12-28 11:15:53 +00:00
Alex Ozdemir
ba70842c62 Limit the identity_op lint to integral operands.
If operands are being applied to non-integers, then the lint is likely
wrong.
2021-12-27 16:06:27 -08:00
bors
adba132411 Auto merge of #8170 - rust-lang:numbered-fields, r=xFrednet
new lint: `init-numbered-fields`

This fixes #7985.

r? `@xFrednet`

---

changelog: new lint: [`init_numbered_fields`]
2021-12-27 21:02:15 +00:00
Andre Bogus
3ebd2bc2e4 new lint: init-numbered-fields 2021-12-26 16:19:22 +01:00
bors
bb7b6beca3 Auto merge of #8133 - surechen:fix_8128, r=xFrednet
Fix 8128

Fixes #8128

changelog: Fix  error suggestion of `skip(..).next()` for immutable variable.
2021-12-26 14:05:35 +00:00
surechen
4ffd66074a Fixes #8128
changelog: Fix error suggestion of skip(..).next() for immutable variable.
2021-12-26 21:37:57 +08:00
dswij
b82c9ce3af Add limitation description for enum_variant_names
`enum_variant_names` will consider characters with no case to be a part
of prefixes/suffixes substring that are compared. This means `Foo1` and
`Foo2` has different prefixes (`Foo1` and `Foo2` prefix respeectively).
This applies to all non-ascii characters with no casing.
2021-12-25 21:55:20 +08:00
dswij
6f7e5cbe21 Some minor cleanup 2021-12-25 21:55:20 +08:00
dswij
c8f016f921 Fix reversed suggestion on postfix 2021-12-25 21:55:20 +08:00
dswij
d58fdfbf3c Fix False Positive on enum_variants when prefixes are not camel-case 2021-12-25 21:54:35 +08:00
dswij
f327f0e2b6 Refactor enum_variants 2021-12-25 21:54:35 +08:00
bors
547efad945 Auto merge of #8167 - rust-lang:fix-8166, r=xFredNet
fix an ICE on unwrapping a None

This very likely fixes #8166 though I wasn't able to meaningfully reduce a test case. This line is the only call to `unwrap` within that function, which was the one in the stack trace that triggered the ICE, so I think we'll be OK.

`@hackmad` can you pull and build this branch and check if it indeed fixes your problem?

---

changelog: Fixed ICE in [`unnecessary_cast`]
2021-12-25 13:38:08 +00:00
Andre Bogus
23ffa3ca04 fix an ICE on unwrapping a None 2021-12-25 13:11:54 +01:00
Elliot Bobrow
1b67aa74bd fix shadow_reuse false negative for if let bindings 2021-12-24 13:20:40 -08:00
hotate29
a172439f29
Change to enclose both sides of Range in parentheses. 2021-12-25 02:24:31 +09:00
hotate29
07b6927180
Change ``floating_point_arthmetic::detect_hypot()`` to enclose the expression in parentheses. 2021-12-25 02:02:37 +09:00
hotate29
0b6d1fdea2
refactor ``Sugg::BinOp`` 2021-12-25 00:29:29 +09:00
Piotr Mikulski
2a47dbc7a6 Simplify code 2021-12-23 22:12:08 -08:00
Piotr Mikulski
01b7411482 Refactor 2021-12-23 22:00:20 -08:00
Piotr Mikulski
4b3a87f886 clippy 2021-12-23 21:47:31 -08:00
Piotr Mikulski
8b19845ffb refactor 2021-12-23 21:46:21 -08:00
Piotr Mikulski
ab77c924e9 cargo dev fmt 2021-12-23 21:44:13 -08:00
Piotr Mikulski
26cc55133e rewrite the PR 2021-12-23 21:41:25 -08:00
Piotr Mikulski
79cf41297a Imrpove unwrap_or_else_default 2021-12-23 19:16:05 -08:00
lcnr
d5cbae90f9 fix clippy 2021-12-23 11:17:03 +01:00
Oussama
88e40bc73d Add support for suggestion when using an expression 2021-12-21 22:00:14 +01:00
Oussama
5ad37b1a4b add suggestion for neg_multiply lint 2021-12-21 20:53:01 +01:00
bors
790513056f Auto merge of #8138 - r00ster91:safety, r=giraffate
Fix `SAFETY` comment tag casing in undocumented_unsafe_blocks

This changes the lint introduced in #7748 to suggest adding a `SAFETY` comment instead of a `Safety` comment.

Searching for `// Safety:` in rust-lang/rust yields 67 results while `// SAFETY:` yields 1072.
I think it's safe to say that this comment tag is written in upper case, just like `TODO`, `FIXME` and so on are. As such I would expect this lint to follow the official convention as well.

Note that I intentionally introduced some casing diversity in `tests/ui/undocumented_unsafe_blocks.rs` to test more cases than just `Safety:`.

changelog: Capitalize `SAFETY` comment in [`undocumented_unsafe_blocks`]
2021-12-20 00:15:18 +00:00
bors
1962ce08ef Auto merge of #8146 - GuillaumeGomez:must-use-self, r=xFrednet
Don't emit RETURN_SELF_NOT_MUST_USE lint if `Self` already is marked as `#[must_use]`

New bug discovered with this lint. Hopefully, this is the last one.

---

changelog: none
2021-12-19 14:54:12 +00:00
Guillaume Gomez
07a00efe61 Don't emit RETURN_SELF_NOT_MUST_USE lint if Self already is marked as #[must_use] 2021-12-19 15:48:57 +01:00
bors
879eccead7 Auto merge of #91957 - nnethercote:rm-SymbolStr, r=oli-obk
Remove `SymbolStr`

This was originally proposed in https://github.com/rust-lang/rust/pull/74554#discussion_r466203544. As well as removing the icky `SymbolStr` type, it allows the removal of a lot of `&` and `*` occurrences.

Best reviewed one commit at a time.

r? `@oli-obk`
2021-12-19 09:31:37 +00:00
bors
25e90ec1ab Auto merge of #8143 - GuillaumeGomez:RETURN_SELF_NOT_MUST_USE, r=xFrednet
Ensure that RETURN_SELF_NOT_MUST_USE is not emitted if the method already has `#[must_use]`

Fixes https://github.com/rust-lang/rust-clippy/issues/8140.

---

Edit:

changelog: none

(The lint is not in beta yet, this should therefore not be included inside the changelog :) )
2021-12-18 15:06:09 +00:00
Guillaume Gomez
4da5520205 Ensure that RETURN_SELF_NOT_MUST_USE is not emitted if the method already has a must_use attribute 2021-12-18 15:26:16 +01:00
bors
af1eea3f0a Auto merge of #89841 - cormacrelf:let-else-typed, r=nagisa
Implement let-else type annotations natively

Tracking issue: #87335

Fixes #89688, fixes #89807, edit: fixes  #89960 as well

As explained in https://github.com/rust-lang/rust/issues/89688#issuecomment-940405082, the previous desugaring moved the let-else scrutinee into a dummy variable, which meant if you wanted to refer to it again in the else block, it had moved.

This introduces a new hir type, ~~`hir::LetExpr`~~ `hir::Let`, which takes over all the fields of `hir::ExprKind::Let(...)` and adds an optional type annotation. The `hir::Let` is then treated like a `hir::Local` when type checking a function body, specifically:

* `GatherLocalsVisitor` overrides a new `Visitor::visit_let_expr` and does pretty much exactly what it does for `visit_local`, assigning a local type to the `hir::Let` ~~(they could be deduplicated but they are right next to each other, so at least we know they're the same)~~
* It reuses the code in `check_decl_local` to typecheck the `hir::Let`, simply returning 'bool' for the expression type after doing that.

* ~~`FnCtxt::check_expr_let` passes this local type in to `demand_scrutinee_type`, and then imitates check_decl_local's pattern checking~~
* ~~`demand_scrutinee_type` (the blindest change for me, please give this extra scrutiny) uses this local type instead of of creating a new one~~
    * ~~Just realised the `check_expr_with_needs` was passing NoExpectation further down, need to pass the type there too. And apparently this Expectation API already exists.~~

Some other misc notes:

* ~~Is the clippy code supposed to be autoformatted? I tried not to give huge diffs but maybe some rustfmt changes simply haven't hit it yet.~~
* in `rustc_ast_lowering/src/block.rs`, I noticed some existing `self.alias_attrs()` calls in `LoweringContext::lower_stmts` seem to be copying attributes from the lowered locals/etc to the statements. Is that right? I'm new at this, I don't know.
2021-12-17 22:12:34 +00:00
r00ster91
eba441391d Fix SAFETY comment tag casing in undocumented_unsafe_blocks 2021-12-17 20:48:38 +01:00
flip1995
ece0946d7f Merge commit '23d11428de3e973b34a5090a78d62887f821c90e' into clippyup 2021-12-17 13:40:22 +01:00
flip1995
fad9407c5a
Merge remote-tracking branch 'upstream/master' into rustup 2021-12-17 13:22:25 +01:00
Samuel E. Moelius III
b8913894a1 Expand is_clone_like comment 2021-12-15 05:25:47 -05:00
Nicholas Nethercote
a83c935a18 Remove unnecessary sigils around Ident::as_str() calls. 2021-12-15 17:32:42 +11:00
Nicholas Nethercote
ecd4919ebb Remove unnecessary sigils around Symbol::as_str() calls. 2021-12-15 17:32:14 +11:00
Nicholas Nethercote
a89a063ba0 Remove SymbolStr.
By changing `as_str()` to take `&self` instead of `self`, we can just
return `&str`. We're still lying about lifetimes, but it's a smaller lie
than before, where `SymbolStr` contained a (fake) `&'static str`!
2021-12-15 13:30:26 +11:00
Matthias Krüger
55df990a9b Rollup merge of #91881 - Patrick-Poitras:stabilize-iter-zip, r=scottmcm
Stabilize `iter::zip`

Hello all!

As the tracking issue (#83574) for `iter::zip` completed the final commenting period without any concerns being raised, I hereby submit this stabilization PR on the issue.

As the pull request that introduced the feature (#82917) states, the `iter::zip` function is a shorter way to zip two iterators. As it's generally a quality-of-life/ergonomic improvement, it has been integrated into the codebase without any trouble, and has been
used in many places across the rust compiler and standard library since March without any issues.

For more details, I would refer to `@cuviper's` original PR, or the [function's documentation](https://doc.rust-lang.org/std/iter/fn.zip.html).
2021-12-15 01:28:08 +01:00
Samuel E. Moelius III
3beb6b1908 Address review comments 2021-12-14 18:36:19 -05:00
PFPoitras
288afb366a Remove iter::zip feature gate from clippy 2021-12-14 18:50:46 -04:00
Samuel E. Moelius III
cb609a9904 Add comma 2021-12-13 12:27:47 -05:00
Esteban Kuber
1c3747e7dd Fix rebase and clippy tests 2021-12-13 17:09:16 +00:00
Esteban Kuber
d8af82e4bb Fix clippy uses of QPath::LangItem 2021-12-13 17:09:16 +00:00
Samuel E. Moelius III
3807905e08 Handle to_vec on for loop expression #8069 2021-12-13 07:04:57 -05:00
Samuel E. Moelius III
290f74be4e Address review comments
* Share a list of methods with `implicit_clone`
* Ensure no overlap with `redundant_clone`
2021-12-13 06:31:17 -05:00
Samuel E. Moelius III
468c86e4a3 Add unnecessary_to_owned lint 2021-12-13 06:31:17 -05:00
Cormac Relf
17c1ff9faa let-else: use hir::Let in clippy
fix clippy format using `cargo fmt -p clippy_{lints,utils}`
manually revert rustfmt line truncations
rename to hir::Let in clippy
Undo the shadowing of various `expr` variables after renaming `scrutinee`
reduce destructuring of hir::Let to avoid `expr` collisions
cargo fmt -p clippy_{lints,utils}
bless new clippy::author output
2021-12-13 14:02:41 +11:00
Deadbeef
adf8c381f2 Revert "Auto merge of #91491 - spastorino:revert-91354, r=oli-obk"
This reverts commit ff2439b7b9, reversing
changes made to 2a9e0831d6.
2021-12-12 12:34:46 +08:00
bors
aa3648af50 Auto merge of #8100 - c410-f3r:blah-blah-blah, r=giraffate
Fix `blocks_in_if_conditions` false positive

Fix #8099

changelog: Fix [`blocks_in_if_conditions`] false positive with an empty closure
2021-12-09 23:50:02 +00:00
Caio
392b2eff4b Fix blocks_in_if_conditions false positive 2021-12-08 20:02:28 -03:00
bors
53059792e9 Auto merge of #8071 - GuillaumeGomez:method-must-use, r=xFrednet
Add new lint to warn when #[must_use] attribute should be used on a method

This lint is somewhat similar to https://rust-lang.github.io/rust-clippy/master/index.html#must_use_candidate but also different: it emits a warning by default and only targets methods (so not functions nor associated functions).

Someone suggested it to me after this tweet: https://twitter.com/m_ou_se/status/1466439813230477312

I think it would reduce the number of cases of API misuses quite a lot.

What do you think?

---

changelog: Added new [`return_self_not_must_use`] lint
2021-12-08 19:09:25 +00:00
bors
3c8f90bd5a Auto merge of #8030 - WaffleLapkin:ignore_trait_assoc_types_type_complexity, r=llogiq
Ignore associated types in traits when considering type complexity

changelog: Ignore associated types in traits when checking ``[`type_complexity`]`` lint.

fixes #1013
2021-12-08 11:54:03 +00:00
Maybe Waffle
c176568abd Ignore associated items in trait *implementations* when considering type complexity 2021-12-08 14:38:59 +03:00
Guillaume Gomez
8dfb3ec8a4 Add new lint to warn when #[must_use] attribute should be used on a method 2021-12-08 11:16:14 +01:00
bors
86cea73449 Auto merge of #8086 - dswij:7991, r=giraffate
Fix bad suggestion on `option_if_let_else` when there is complex subpat

closes #7991

Prefer not warning any complex subpat in `option_if_let_else` rather than suggesting obscure suggestions.

changelog: [`option_if_let_else`] does not warn when complex subpat is present
2021-12-07 23:45:58 +00:00
Yechan Bae
5d63a28638 Move non_send_fields_in_send_ty back to nursery 2021-12-07 10:45:59 -05:00
Yechan Bae
c0fd250c62 Fix grammar issues 2021-12-07 10:08:22 -05:00
Yechan Bae
ee0d71e103 Clarify the purpose of the lint 2021-12-07 10:06:34 -05:00
dswij
b5fa5b37cc option_if_let_else Do not warn when complex subpat is present 2021-12-07 15:47:28 +08:00
bors
1c7df44e2d Auto merge of #8085 - jqnatividad:8084-needless_lifetimes_typo, r=giraffate
`needless_lifetimes` Known problems typo

fixes #8084

[needless_lifetimes]

changelog: none
2021-12-07 00:45:59 +00:00
Joel Natividad
d91b91ae57 needless_lifetimes Known problems typo
fixes #8084
2021-12-06 19:11:19 -05:00
bors
f615ea474b Auto merge of #8080 - dswij:8019, r=giraffate
Fix FP on `question_mark` if returned object is not local

Closes #8019

changelog: [`question_mark`] Fix FP when returned object is not local
2021-12-07 00:07:46 +00:00
Cameron Steffen
16bbd243f9 Simplify needless_bool 2021-12-06 12:33:02 -06:00
Cameron Steffen
f690ef6f5c Refactors with peel_blocks 2021-12-06 12:33:02 -06:00
Cameron Steffen
284b63a687 Rename remove_blocks to peel_blocks 2021-12-06 12:33:02 -06:00
bors
9e0852705e Auto merge of #8066 - rust-lang:needless_bool_parenthesize, r=camsteffen
Parenthesize blocks in `needless_bool` suggestion

Because the `if .. {}` statement already puts the condition in expression scope, contained blocks would be parsed as complete
statements, so any `&` binary expression whose left operand ended in a block would lead to a non-compiling suggestion.

We identify such expressions and add parentheses. Note that we don't make a difference between normal and unsafe blocks because the parsing problems are the same for both.

This fixes #8052.

---

changelog: none
2021-12-06 15:15:26 +00:00
Andre Bogus
4a39707795 Parenthesize blocks in needless_bool suggestion
Because the `if .. {}` statement already puts the condition in
expression scope, contained blocks would be parsed as complete
statements, so any `&` binary expression whose left operand ended in a
block would lead to a non-compiling suggestion.

This adds a visitor to identify such expressions and add parentheses.

This fixes #8052.
2021-12-06 13:15:31 +01:00
flip1995
8fea1d94f3 Merge commit 'a5d597637dcb78dc73f93561ce474f23d4177c35' into clippyup 2021-12-06 12:33:31 +01:00
dswij
01ca66cbd7 Fix FP on question_mark if returned object is not local 2021-12-06 17:51:00 +08:00
nixx quality
01e302b2f7
Fix dogfood 2021-12-05 23:04:56 +01:00
nixx quality
e3c60444ce
fix some false negatives for single_char_pattern 2021-12-05 17:33:52 +01:00
Mara Bos
35a0060aba Use IntoIterator for array impl everywhere. 2021-12-04 19:40:33 +01:00
bors
907f6d9294 Auto merge of #8074 - Qwaz:send_nonnull, r=xFrednet
Consider NonNull as a pointer type

PR 1/2 for issue #8045. Add `NonNull` as a pointer class to suppress false positives like `UnsafeCell<NonNull<()>>`. However, this change is not sufficient to handle the cases shared in gtk-rs and Rug in the issue.

changelog: none

r? `@xFrednet`
2021-12-04 17:19:07 +00:00
bors
9eabec9f07 Auto merge of #8054 - camsteffen:map-flatten-style, r=giraffate
Upgrade map_flatten to complexity

changelog: upgrade [`map_flatten`] to complexity

Resolves #7999
2021-12-04 13:30:09 +00:00
Yechan Bae
844996b42e Consider NonNull as a pointer type 2021-12-03 19:11:40 -05:00
Amanieu d'Antras
c813bfa424 Add initial AST and MIR support for unwinding from inline assembly 2021-12-03 23:51:46 +01:00
Cameron Steffen
de9de4fef1 Upgrade map_flatten to complexity 2021-12-03 13:21:48 -06:00
xFrednet
11ad5a26a9
Add note about crate lint level attributes to pre-expansion lints 2021-12-03 19:29:57 +01:00
Santiago Pastorino
23f752f278 Revert "Auto merge of #91354 - fee1-dead:const_env, r=spastorino"
This reverts commit 18bb8c61a9, reversing
changes made to d9baa36190.
2021-12-03 10:11:21 -03:00
bors
be1a73b894 Auto merge of #8061 - vallentin:fix-same-name-method-desc, r=flip1995
Fixed same_name_method description

Noticed some odd phrasing, while checking out the new release.

changelog: none
2021-12-03 00:37:52 +00:00
frobiac
5cc451bc6c Escape backslash for singe_char_pattern.rs 2021-12-02 23:47:23 +01:00
bors
d5d830a50f Auto merge of #7463 - ThibsG:find_any_7392, r=xFrednet
Fix `any()` not taking reference in `search_is_some` lint

`find` gives reference to the item, but `any` does not, so suggestion is broken in some specific cases.

Fixes: #7392

changelog: [`search_is_some`] Fix suggestion for `any()` not taking item by reference
2021-12-02 17:27:54 +00:00
vallentin
f26821c969
Fixed same_name_method description 2021-12-02 18:25:09 +01:00
bors
dd03c0ff3e Auto merge of #91354 - fee1-dead:const_env, r=spastorino
Cleanup: Eliminate ConstnessAnd

This is almost a behaviour-free change and purely a refactoring. "almost" because we appear to be using the wrong ParamEnv somewhere already, and this is now exposed by failing a test using the unstable `~const` feature.

We most definitely need to review all `without_const` and at some point should probably get rid of many of them by using `TraitPredicate` instead of `TraitRef`.

This is a continuation of https://github.com/rust-lang/rust/pull/90274.

r? `@oli-obk`

cc `@spastorino` `@ecstatic-morse`
2021-12-02 11:48:58 +00:00