Commit graph

4394 commits

Author SHA1 Message Date
bors
2c8d5a2500 Auto merge of #8453 - tamaroning:fix_large_enum_variant, r=camsteffen
fix false positives of large_enum_variant

fixes: #8321
The size of enums containing generic type was calculated to be 0.
I changed [large_enum_variant] so that such enums are not linted.

changelog: none
2022-02-26 02:42:43 +00:00
Alex Macleod
52f3d61a2a Add print_in_format_impl lint 2022-02-25 21:10:06 +00:00
Florian Nagel
862211d540 Disable `[new-without-default]` for new() methods that are marked with '#[doc(hidden)]'
Fixes issue #8152
2022-02-25 16:34:37 +01:00
J-ZhengLi
30fb8229e1 add tests, add base bone for the new lint 2022-02-25 18:08:52 +08:00
Vadim Petrochenkov
a30eba2c7e Update clippy tests 2022-02-24 22:55:40 +03:00
tamaron
db62821c03 fix 2022-02-24 00:16:24 +09:00
Jason Newcomb
382b3f0601 Fix counting the number of unchangeable arguments in ptr_arg 2022-02-23 01:04:49 -05:00
Ken Matsui
7412e6976e
Use the precise namespace for Reverse 2022-02-23 06:06:09 +09:00
bors
9e605ef80f Auto merge of #8443 - Jarcho:match_cfg_arm, r=flip1995
Don't lint `match` expressions with `cfg`ed arms

Somehow there are no open issues related to this for any of the affected lints. At least none that I could fine from a quick search.

changelog: Don't lint `match` expressions with `cfg`ed arms in many cases
2022-02-21 08:46:42 +00:00
tamaron
e3b5cac3c8 fix 2022-02-21 13:25:53 +09:00
Jason Newcomb
d28d19d74c Fix transmute_undefined_repr when converting between a fat pointer and a type containing a fat pointer 2022-02-18 15:02:28 -05:00
Jason Newcomb
7c07022c98 Allow transmuting fat pointers to some types in transmute_undefined_repr 2022-02-18 15:02:28 -05:00
Jason Newcomb
447a24588a Allow various type erasure patterns in transmute_undefined_repr 2022-02-18 15:02:25 -05:00
Jason Newcomb
c02dff7167 Fix transmute_undefined_repr when converting between a pointer and a type containing a pointer 2022-02-18 15:01:58 -05:00
Jason Newcomb
90bb7a3476 New lint cast_enum_truncation 2022-02-18 09:16:17 -05:00
Jason Newcomb
8a466454ab Lint enum-to-int casts with cast_possible_truncation 2022-02-18 09:11:15 -05:00
bors
02f3c17593 Auto merge of #8419 - flip1995:await_parking_alot, r=llogiq
Fix `await_holding_lock` not linting `parking_lot` Mutex/RwLock

This adds tests for `RwLock` and `parking_lot::{Mutex, RwLock}`, which were added before in 2dc8c083f5, but never tested in UI tests. I noticed this while reading [fasterthanli.me](https://fasterthanli.me/articles/a-rust-match-made-in-hell) latest blog post, complaining that Clippy doesn't catch this for `parking_lot`. (Too many people read his blog, he's too powerful)

Some more things:
- Adds a test for #6446
- Improves the lint message

changelog: [`await_holding_lock`]: Now also lints for `parking_lot::{Mutex, RwLock}`
2022-02-18 10:55:05 +00:00
bors
a703a82035 Auto merge of #94088 - oli-obk:revert, r=jackh726
Revert #91403

fixes #94004

r? `@pnkfelix` `@cjgillot`
2022-02-18 07:35:37 +00:00
bors
76f91b6f5a Auto merge of #8442 - rsmantini:issue-8120-fix, r=Manishearth
trigger  `ptr_as_ptr` inside macros

This PR makes `ptr_as_ptr` trigger inside macros

Fixes issue #8120

changelog: ``[`ptr_as_ptr`]`` is now triggered inside macros

r? `@llogiq`
2022-02-17 22:57:23 +00:00
Jason Newcomb
8912d659cd Remove hack testing for cfg attribute in match_single_binding 2022-02-17 14:16:21 -05:00
Rodrigo Mantini
aaeeed6a59 trigger ptr_as_ptr inside macros 2022-02-17 20:16:14 +01:00
Jason Newcomb
8ce2d46cac Check for cfg attrubutes before linting match expressions 2022-02-17 14:04:10 -05:00
flip1995
c5709419b1
Add test for drop-before-await FP 2022-02-17 18:03:13 +01:00
flip1995
c4944fb60d
Actually lint parking_lot in await_holding_lock
This adapts the paths for the parking_lot mutex guards, so that
parking_lot mutexes and RwLocks actually get linted. This is now also
tested.
2022-02-17 18:02:31 +01:00
flip1995
cdf9a28006
Improve lint message of await_holding_*
Improves the message of the lints await_holding_lock and
await_holding_refcell_ref. Now also actually tests RwLock.
2022-02-17 18:00:40 +01:00
bors
668b3e47f9 Auto merge of #8218 - Jarcho:redundant_slicing_deref, r=camsteffen
Improve `redundant_slicing` lint

fixes #7972
fixes #7257

This can supersede #7976

changelog: Fix suggestion for `redundant_slicing` when re-borrowing for a method call
changelog: New lint `deref_as_slicing`
2022-02-17 16:08:45 +00:00
Oli Scherer
4abaa0239a Revert "Auto merge of #91403 - cjgillot:inherit-async, r=oli-obk"
This reverts commit 3cfa4def7c87d571bd46d92fed608edf8fad236e, reversing
changes made to 5d8767cb229b097fedb1dd4bd9420d463c37774f.
2022-02-17 16:00:04 +00:00
bors
7ee2081fb6 Auto merge of #8441 - Jarcho:needless_borrow_temp, r=flip1995
Don't lint `needless_borrow` in method receiver positions

fixes #8408
fixes #8407
fixes #8391
fixes #8367
fixes #8380

This is a temporary fix for `needless_borrow`. The proper fix is included in #8355.

This should probably be merged into rustc before beta branches on Friday. This issue has been reported six or seven times in the past couple of weeks.

changelog: Fix various issues with `needless_borrow` n´. Note to changelog writer: those issues might have been introduced in this release cycle, so this might not matter in the changelog.
2022-02-17 15:51:30 +00:00
Jason Newcomb
9af2be8e96 Don't lint needless_borrow in method receiver positions 2022-02-17 16:21:53 +01:00
bors
a4cf91b9c8 Auto merge of #8433 - hellow554:update_default_trait, r=flip1995
Don't lint Default::default if it is the udpate syntax base

changelog: Don't lint `Default::default` it is part of the update syntax

Current clippy warns about this:

```
warning: calling `Foo::default()` is more clear than this expression
  --> src/main.rs:12:11
   |
12 |         ..Default::default()
   |           ^^^^^^^^^^^^^^^^^^ help: try: `Foo::default()`
   |
```

With these changes, it will not lint that particular expression anymore.
2022-02-17 09:13:30 +00:00
Marcel Hellwig
504f3af70e Don't lint Default::default if it is the udpate syntax base
An Update Syntax looks like this:

   Foo {
      a: 3,
      ..Default::default()
    }

Don't lint `Default::default` here
2022-02-17 10:04:25 +01:00
Jason Newcomb
7724d6773d Move some cases from redundant_slicing to deref_by_slicing 2022-02-17 00:02:33 -05:00
Jason Newcomb
113ac6e15e Split off new lint deref_by_slicing from redundant_slicing 2022-02-17 00:02:26 -05:00
Jason Newcomb
4bdc97c4a6 Account for auto-borrows and precedence in redundant_slicing lint 2022-02-16 23:52:23 -05:00
Jason Newcomb
faeeef3b9c Improve redundant_slicing lint
* Lint when slicing triggers auto-deref
* Lint when slicing returns the same type as dereferencing
2022-02-16 23:52:23 -05:00
Jason Newcomb
a135b52102 Don't lint needless_borrow in method receiver positions 2022-02-16 23:14:39 -05:00
James McMurray
b162b11abc Add recursive_format_impl lint
The to_string_in_display lint is renamed to recursive_format_impl
A check is added for the use of self formatted with Display or Debug
inside any format string in the same impl
The to_string_in_display check is kept as is - like in the
format_in_format_args lint

For now only Display and Debug are checked
This could also be extended to other Format traits (Binary, etc.)
2022-02-14 18:49:51 +01:00
bors
4931cab709 Auto merge of #8425 - Jarcho:transmute_8417, r=giraffate
Fix `transmute_undefined_repr` with single field `#[repr(C)]` structs

Fixes: #8417

The description has also been made more precise.

changelog: Fix `transmute_undefined_repr` with single field `#[repr(C)]` structs
changelog: Move `transmute_undefined_repr` back to `correctness`
2022-02-14 06:58:51 +00:00
nsunderland1
78c2e0bfe9 Document pub requirement for new_without_default lint 2022-02-13 17:07:14 -08:00
Jason Newcomb
662df33e97 Fix transmute_undefined_repr with single field #[repr(C)] structs 2022-02-13 13:22:17 -05:00
Jaeyong Sung
2ebe7516a8
add documentation 2022-02-13 13:32:40 +09:00
Jaeyong Sung
1a69b17c8c
fix parameters applying lint 2022-02-13 04:43:27 +09:00
Jaeyong Sung
9055f34b71
Merge remote-tracking branch 'upstream/master' into only_used_in_recursion
# Conflicts:
#	clippy_lints/src/lib.rs
2022-02-13 02:43:23 +09:00
Jaeyong Sung
4f96ca353e
add only_used_in_recursion lint
- fix code that have variables that is "only used in recursion"
- add test
2022-02-13 02:32:09 +09:00
Camille GILLOT
9f75aff391 Bless clippy test. 2022-02-12 01:26:17 +01:00
Alex Macleod
41d7c7e059 Migrate dbg_macro to late pass 2022-02-11 15:56:10 +00:00
flip1995
611d039814 Merge commit '57b3c4b90f4346b3990c1be387c3b3ca7b78412c' into clippyup 2022-02-10 18:40:06 +01:00
flip1995
0775c06d32
Merge remote-tracking branch 'upstream/master' into rustup 2022-02-10 18:11:27 +01:00
Cameron Steffen
88fd090531 Factor out ui_test suite 2022-02-08 15:11:48 -06:00
bors
caeebd6b09 Auto merge of #8374 - Alexendoo:bless-revisions, r=camsteffen
Support `cargo dev bless` for tests with revisions

changelog: internal: Support `cargo dev bless` for tests with revisions

Previously bless wouldn't pick up the saved stderr from `target/debug/tests/manual_assert.stage-id.edition2021.stderr` or `target/debug/tests/manual_assert.stage-id.edition2018.stderr` due to there being multiple revisions of the test output

This tweaks compile-test so the built files end up in e.g. `target/debug/tests/ui`, `target/debug/tests/ui-cargo` rather than share the `tests` dir. `cargo dev bless` then uses that to update all the `.stdout/stdout/fixed` files it can find

Also removes an empty file I found, and the logic to remove empty outputs as compiletest doesn't produce empty `.stdout/stderr` files
2022-02-08 20:50:41 +00:00
bors
093e32052e Auto merge of #8398 - Jarcho:unordered_transmute, r=llogiq
Add lint `transmute_undefined_repr`

Partially implements #3999 and #546

This doesn't consider `enum`s at all right now as those are going to be a pain to deal with. This also allows `#[repr(Rust)]` structs with only one non-zero sized fields. I think those are technically undefined when transmuted.

changelog: Add lint `transmute_undefined_repr`
2022-02-06 16:05:00 +00:00
Alex Macleod
04dce4aed4 Support cargo dev bless for tests with revisions 2022-02-06 13:00:17 +00:00
Jason Newcomb
3403b3e717 Add lint transumte_undefined_repr 2022-02-05 16:28:25 -05:00
bors
68b44986de Auto merge of #8365 - Alexendoo:explicit-write-suggestion, r=camsteffen
Add `explicit_write` suggestions for `write!`s with format args

changelog: Add [`explicit_write`] suggestions for `write!`s with format args

Fixes #4542

```rust
writeln!(std::io::stderr(), "macro arg {}", one!()).unwrap();
```

Now suggests:

```
error: use of `writeln!(stderr(), ...).unwrap()`
  --> $DIR/explicit_write.rs:36:9
   |
LL |         writeln!(std::io::stderr(), "macro arg {}", one!()).unwrap();
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `eprintln!("macro arg {}", one!())`
```

---------

r? `@camsteffen` (again, sorry 😛) for the `FormatArgsExpn` change

Before this change `inputs_span` returned a span pointing to just `1` in

```rust
macro_rules! one {
    () => { 1 };
}

`writeln!(std::io::stderr(), "macro arg {}", one!()).unwrap();`
```

And the `source_callsite` of that span didn't include the format string, it was just `one!()`
2022-02-05 17:44:37 +00:00
bors
29cc0d8e59 Auto merge of #8372 - tamaroning:unwrap_used, r=llogiq
make unwrap_used also trigger on .get().unwrap()

fixes #8124
changelog: make the [unwrap_used] lint trigger for code of the form such as `.get(i).unwrap()` and `.get_mut(i).unwrap()`
2022-02-05 14:56:42 +00:00
Alex Macleod
144b4a59c7 Add explicit_write suggestions for write!s with format args 2022-02-05 13:05:08 +00:00
Alex Macleod
4bae06d73c Use source callsite in FormatArgsExpn::inputs_span 2022-02-05 13:05:08 +00:00
bors
699ee5e31c Auto merge of #8376 - dswij:8373, r=camsteffen
[`chars_next_cmp`] Fix unescaped suggestion

closes #8373

changelog: [`chars_next_cmp`] Fix unescaped suggestion
2022-02-05 00:32:10 +00:00
bors
bef92b864d Auto merge of #8382 - tamaroning:suggest_iter_instead_of_into_iter, r=giraffate
[explicit_counter_loop] suggests `.into_iter()`, despite that triggering [into_iter_on_ref] in some cases

I have modified `fn make_iterator_snippet` in clippy_lints/src/loops/utils.rs ,so this change has some little influence on another lint [manual_flatten] .

fixes #8155

---
changelog: Fix that [`explicit_counter_loop`] suggests `into_iter()` despite that triggering [`into_iter_on_ref`] in some cases
2022-02-02 12:37:18 +00:00
Jason Newcomb
e4f45c22e2 Fix ICE in ptr_arg 2022-02-01 15:05:20 -05:00
lcnr
544ed0b3cf silence lint in clippy 2022-02-01 10:13:32 +01:00
tamaron
b13704a9cd update test suites 2022-02-01 13:44:24 +09:00
bors
7bb69c0ae0 Auto merge of #8369 - Jarcho:ptr_arg_8366, r=flip1995
Don't lint `ptr_arg` for `&mut _` types in trait items

fixes #8366

changelog: Don't lint `ptr_arg` for `&mut _` types in trait items
2022-01-31 15:17:38 +00:00
dswij
5faa7ebb70 Fix chars_next_cmp suggestion not escaped 2022-01-31 13:35:14 +08:00
bors
0ed8ca45f4 Auto merge of #8322 - jubnzv:8282-single-match, r=llogiq
single_match: Don't lint non-exhaustive matches; support tuples

`single_match` lint:
* Don't lint exhaustive enum patterns without a wild.
  Rationale: The definition of the enum could be changed, so the user can get non-exhaustive match after applying the suggested lint (see https://github.com/rust-lang/rust-clippy/issues/8282#issuecomment-1013566068 for context).
* Lint `match` constructions with tuples (as suggested at https://github.com/rust-lang/rust-clippy/issues/8282#issuecomment-1015621148)

Closes #8282

---

changelog: [`single_match`]: Don't lint exhaustive enum patterns without a wild.
changelog: [`single_match`]: Lint `match` constructions with tuples
2022-01-30 22:00:36 +00:00
tamaron
447ed5ce52 add attributes 2022-01-30 15:39:47 +09:00
tamaron
df6ef6059b update get_unwrap.rs 2022-01-30 14:59:46 +09:00
tamaron
ba80d45b3c update testsuite 2022-01-30 12:58:49 +09:00
Jason Newcomb
66bb7263b5 Don't lint ptr_arg for &mut _ types in trait items 2022-01-29 12:03:54 -05:00
bors
7ceffdee9b Auto merge of #8289 - jubnzv:unspecified-layout-union, r=camsteffen
Add `default_union_representation` lint

Closes #8235

changelog: Added a new lint  [`default_union_representation`]
2022-01-29 10:58:16 +00:00
Georgy Komarov
b7000b2a53 Add default_union_representation lint
Closes #8235
2022-01-29 07:02:28 +03:00
bors
8d5d9e0103 Auto merge of #8250 - pr2502:fix_repeat_underflow, r=giraffate
Fix underflow in `manual_split_once` lint

Hi, a friend found clippy started crashing on a suspiciously large allocation of `u64::MAX` memory on their code.

The mostly minimized repro is:
```rust
fn _f01(title: &str) -> Option<()> {
    let _ = title[1..].splitn(2, '[').next()?;
    Some(())
}
```

The underflow happens in this case on line 57 of the patch but I've changed the other substraction to saturating as well since it could potentially cause the same issue.

I'm not sure where to put a regression test, or if it's even worth for such a thing.

Aside, has it been considered before to build clippy with overflow checks enabled?

changelog: fix ICE of underflow in `manual_split_once` lint
2022-01-28 13:31:51 +00:00
max
23fd95a5e9 fix underflow in check_manual_split_once lint 2022-01-27 17:54:40 +01:00
flip1995
bf66aeda0a Merge commit 'a98e7ab8b94485be6bd03e0c6b8682ecab5b52e6' into clippyup 2022-01-27 15:12:45 +01:00
flip1995
d037b28025
Merge remote-tracking branch 'upstream/master' into rustup 2022-01-27 14:23:31 +01:00
Georgy Komarov
467a0bfdea matches: Restore match_type logic; add tests for these cases 2022-01-26 18:20:35 +03:00
Georgy Komarov
5416a71dae Merge remote-tracking branch 'origin/master' into 8282-single-match 2022-01-26 14:16:15 +03:00
Dharma Saputra Wijaya
0d7273fef6 fix bad suggestion on numeric_literal 2022-01-26 15:02:13 +08:00
bors
60d3597cd2 Auto merge of #8315 - dswij:8306, r=giraffate
`trait_duplication_in_bounds` checks path segments for trait items

closes #8306

changelog: [`trait_duplication_in_bounds`] Fix FP when path segments exists for trait items
2022-01-24 00:03:40 +00:00
bors
d976d8ad87 Auto merge of #8311 - dswij:8277, r=llogiq
fix `needless_question_mark` not considering async fn

closes #8277

changelog: [`needless_question_mark`] Fix FN on async functions
2022-01-23 12:59:52 +00:00
dswij
a05276620c fix needless_question_mark not considering async fn 2022-01-23 20:31:27 +08:00
bors
788a8bc740 Auto merge of #8217 - Jarcho:needless_borrow_8191, r=camsteffen
Fix `needless_borrow` causing mutable borrows to be moved

fixes #8191

changelog: Fix `needless_borrow` causing mutable borrows to be moved
changelog: Rename `ref_in_deref` to `needless_borrow`
changelog: Suggest removing the borrow on method call receivers in `needless_borrow`
2022-01-23 03:01:39 +00:00
Jason Newcomb
c61514086d Subsume ref_in_deref into needless_borrow 2022-01-22 21:22:33 -05:00
Jason Newcomb
9e9110e4f3 Remove final reference on fields and method calls in needless_borrow 2022-01-22 20:35:32 -05:00
Alex Macleod
9ef6e2199c needless_lifetimes: ignore lifetimes in explicit self types 2022-01-22 12:27:57 +00:00
bors
4992548f28 Auto merge of #8271 - Jarcho:ptr_arg_214, r=flip1995
Check usages in `ptr_arg`

fixes #214
fixes #1981
fixes #3381
fixes #6406
fixes #6964

This does not take into account the return type of the function currently, so `(&Vec<_>) -> &Vec<_>` functions may still be false positives.

The name given for the type also has to match the real type name, so `type Foo = Vec<u32>` won't trigger the lint, but `type Vec = Vec<u32>` will. I'm not sure if this is the best way to handle this, or if a note about the actual type should be added instead.

changelog: Check if the argument is used in a way which requires the original type in `ptr_arg`
changelog: Lint mutable references in `ptr_arg`
2022-01-21 15:43:57 +00:00
Jason Newcomb
15c068ed0f Fix needless_borrow causing mutable borrows to be moved 2022-01-21 09:50:11 -05:00
Jason Newcomb
048297b5b2 ptr_arg cleanup 2022-01-21 09:43:41 -05:00
Cameron Steffen
82f613ee3b Remove a span from hir::ExprKind::MethodCall 2022-01-21 07:48:10 -06:00
Alex Macleod
7c563175c7 Don't suggest an empty variant name in enum_variant_names 2022-01-21 13:10:19 +00:00
bors
ec00cf80a3 Auto merge of #91359 - dtolnay:args, r=Mark-Simulacrum
Emit simpler code from format_args

I made this PR so that `cargo expand` dumps a less overwhelming amount of formatting-related code.

<br>

`println!("rust")` **Before:**

```rust
{
    ::std::io::_print(::core::fmt::Arguments::new_v1(&["rust\n"],
                                                     &match () {
                                                          _args => [],
                                                      }));
};
```

**After:**

```rust
{ ::std::io::_print(::core::fmt::Arguments::new_v1(&["rust\n"], &[])); };
```

`println!("{}", x)` **Before:**

```rust
{
    ::std::io::_print(::core::fmt::Arguments::new_v1(
        &["", "\n"],
        &match (&x,) {
            _args => [::core::fmt::ArgumentV1::new(
                _args.0,
                ::core::fmt::Display::fmt,
            )],
        },
    ));
};
```

**After:**

```rust
{
    ::std::io::_print(::core::fmt::Arguments::new_v1(
        &["", "\n"],
        &[::core::fmt::ArgumentV1::new(&x, ::core::fmt::Display::fmt)],
    ));
};
```
2022-01-21 06:20:18 +00:00
Georgy Komarov
a0c5087520 single_match: Clarify the don't lint test case 2022-01-21 07:28:26 +03:00
Georgy Komarov
a5a07e503f single_match: Don't lint non-exhaustive matches; support tuples
This commit changes the behavior of `single_match` lint.

After that, we won't lint non-exhaustive matches like this:

```rust
match Some(v) {
    Some(a) => println!("${:?}", a),
    None => {},
}
```

The rationale is that, because the type of `a` could be changed, so the
user can get non-exhaustive match after applying the suggested lint (see
https://github.com/rust-lang/rust-clippy/issues/8282#issuecomment-1013566068
for context).

We also will lint `match` constructions with tuples. When we see the
tuples on the both arms, we will check them both at the same time, and
if they form exhaustive match, we could display the warning.

Closes #8282
2022-01-20 15:14:25 +03:00
dswij
4c1549ecc8 trait_duplication_in_bounds checks path segments for trait items 2022-01-20 13:38:48 +08:00
bors
fff8e78f6d Auto merge of #8298 - ebobrow:op_ref_fp, r=giraffate
fix op_ref false positive

fixes #7572

changelog: `op_ref` don't lint for unnecessary reference in BinOp impl if removing the reference will lead to unconditional recursion
2022-01-18 00:12:42 +00:00
David Tolnay
c422824275 Bless clippy ui tests after format_args change 2022-01-17 11:04:46 -08:00
flip1995
ddad101b8a Merge commit '8d14c94b5c0a66241b4244f1c60ac5859cec1d97' into clippyup 2022-01-17 13:29:07 +01:00
bors
8d14c94b5c Auto merge of #8292 - marekdownar:8239, r=xFrednet
issue #8239: Printed hint for lint or_fun_call is cropped and does no…

fixes rust-lang/rust-clippy#8239

changelog: [`or_fun_call`]: if suggestion contains more lines than MAX_SUGGESTION_HIGHLIGHT_LINES it is stripped to one line
2022-01-17 12:08:30 +00:00
xFrednet
2d3eb5082a
Move return_self_not_must_use to pedantic 2022-01-17 12:35:19 +01:00
Marek Downar
69d78ceeba
removing unsafe from test fn's && renaming shrink to sugg_span 2022-01-17 12:34:03 +01:00
bors
d364d8ad5b Auto merge of #8299 - marekdownar:8214, r=Manishearth
#8214 cmp_owned suggestion flips the comparison

changelog: ``[`cmp_owned`]`` fixes #8214 so that the suggestion does not flip the comparison
2022-01-17 07:04:06 +00:00
bors
537a7f3e44 Auto merge of #8297 - Jarcho:if_same_then_else_7579, r=Manishearth
Don't lint `if_same_then_else` with `if let` conditions

fixes #7579

changelog: Don't lint `if_same_then_else` with `if let` conditions
2022-01-17 06:48:01 +00:00
Jason Newcomb
5461ed670e Don't lint if_same_then_else with if let conditions 2022-01-16 18:39:46 -05:00
Marek Downar
5b6ec8c57d
#8214 cmp_owned suggestion flips the comparison 2022-01-16 20:27:00 +01:00
Piotr Mikulski
1c9b31d350 New line: cloned_next 2022-01-16 09:59:29 -08:00
Elliot Bobrow
fb5f51d3eb fix op_ref false positive 2022-01-16 09:20:33 -08:00
Jason Newcomb
cb384ff03b Handle implicit named arguments in useless_format 2022-01-15 16:28:49 -05:00
Marek Downar
49502727e7
issue #8239: fix to prev commit && 4 test cases 2022-01-15 22:19:01 +01:00
Jason Newcomb
70a6d7b012 Erase late bound regions in iter_not_returning_iterator 2022-01-15 00:15:25 -05:00
bors
7a4acf9fa6 Auto merge of #8231 - Jarcho:implicit_clone_8227, r=camsteffen
Fix `implicit_clone` for `&&T`

fixes #8227

changelog: Don't lint `implicit_clone` on `&&T`
2022-01-14 22:17:29 +00:00
SeeSpring
875b240083 Apply not_unsafe_ptr_arg_deref to type aliases 2022-01-13 09:47:56 -05:00
flip1995
fb0142ae41 Merge commit '97a5daa65908e59744e2bc625b14849352231c75' into clippyup 2022-01-13 13:18:19 +01:00
flip1995
11be495bde
Merge remote-tracking branch 'upstream/master' into rustup 2022-01-13 12:47:48 +01:00
Jason Newcomb
7ed86bf822 Changes to ptr_arg
* Track the argument when used to initialize simple `let` bindings
* Check if the argument is passed to a function requiring the original type
* Use `multipart_suggestion` rather than multiple suggestions
* Check if the name given in the source code matches the name of the actual type
2022-01-12 20:57:50 -05:00
bors
60e68d68c6 Auto merge of #8226 - Jarcho:manual_memcpy_8160, r=flip1995
`manual_memcpy` fix

fixes #8160

Ideally this would work with `VecDeque`, but the current interface is unsuitable for it. At a minimum something like `range_as_slices` would be needed.

changelog: Don't lint `manual_memcpy` on `VecDeque`
changelog: Suggest `copy_from_slice` for `manual_memcpy` when applicable
2022-01-12 18:44:34 +00:00
Jason Newcomb
ad95279c34 Suggest deref when needed in implicit_clone 2022-01-12 13:03:38 -05:00
Jason Newcomb
062db10c12 Add manual_memcpy_test for VecDeque 2022-01-12 12:33:47 -05:00
Paolo Barbolini
166737f3cb Add manual_bits lint 2022-01-12 16:46:57 +01:00
Jason Newcomb
d32277d78e Don't lint deref_addrof when the two operations occur in different expansions 2022-01-12 00:25:42 -05:00
Federico Guerinoni
3298de7f66 Add borrow_as_ptr lint
Closes: #6995

Signed-off-by: Federico Guerinoni <guerinoni.federico@gmail.com>
Co-authored-by: Paolo Barbolini <paolo@paolo565.org>
2022-01-11 09:53:29 +01:00
Taiki Endo
cf86cee4fe Downgrade mutex_atomic to nursery 2022-01-10 23:36:13 +09:00
bors
b66dbe87f1 Auto merge of #8228 - Jarcho:iter_not_returning_iterator_8225, r=giraffate
fix `iter_not_returning_iterator`

fixes #8225

changelog: Handle type projections in `iter_not_returning_iterator`
changelog: Don't lint `iter_not_returning_iterator` in trait implementations
changelog: Lint `iter_not_returning_iterator` in trait definitions
2022-01-10 12:34:15 +00:00
bors
88cfd70100 Auto merge of #8252 - dswij:8229, r=xFrednet
cover trait for `trait_duplication_in_bounds`

closes #8229

changelog: [`trait_duplication_in_bounds`] covers trait functions with `Self` bounds
2022-01-10 10:31:59 +00:00
dswij
f4dc348ad5 trait_duplication_in_bounds Update description and add test 2022-01-10 12:45:22 +08:00
bors
a6f80fccb1 new lint: single_char_lifetime_names
This pull request adds a lint against single character lifetime names, as they might not divulge enough information about the purpose of the lifetime. This can make code harder to understand. I placed this in `restriction` rather than `pedantic` (as suggested in #8233) since most of the Rust ecosystem already uses single character lifetime names (to my knowledge, at least) and since single character lifetime names aren't incorrect. I'd be happy to change this upon request, however. Fixes #8233.

- [x] Followed lint naming conventions
- [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`

changelog: new lint: [`single_char_lifetime_names`]
2022-01-09 14:27:36 +00:00
dswij
f690978023 cover trait for trait_duplication_in_bounds 2022-01-09 13:35:01 +08:00
Vadim Petrochenkov
c8ea0420cb rustc_metadata: Rename item_children(_untracked) to module_children(_untracked)
And `each_child_of_item` to `for_each_module_child`
2022-01-09 09:22:06 +08:00
Jason Newcomb
d98339d3e0 Handle type projections in iter_not_returning_iterator 2022-01-05 17:19:13 -05:00
Jason Newcomb
2cc38a2322 Lint iter_not_returning_iterator on the trait definition rather than the implementation 2022-01-05 13:46:35 -05:00
Jason Newcomb
3925def9cf Suggest copy_from_slice for manual_memcpy when possible 2022-01-05 12:35:35 -05:00
bors
92048f4826 Auto merge of #8221 - Jarcho:while_let_on_iterator_8113, r=llogiq
Better detect when a field can be moved from in `while_let_on_iterator`

fixes #8113

changelog: Better detect when a field can be moved from in `while_let_on_iterator`
2022-01-05 06:45:58 +00:00
bors
20f2a89026 Auto merge of #8224 - Jarcho:type_repetition_in_bounds_8162, r=llogiq
Fix `type_repetition_in_bounds`

fixes #7360
fixes #8162
fixes #8056

changelog: Check for full equality in `type_repetition_in_bounds` rather than just equal hashes
2022-01-05 01:05:18 +00:00
bors
ba03dc70fd Auto merge of #8219 - camsteffen:macro-decoupling, r=llogiq
New macro utils

changelog: none

Sorry, this is a big one. A lot of interrelated changes and I wanted to put the new utils to use to make sure they are somewhat battle-tested. We may want to divide some of the lint-specific refactoring commits into batches for smaller reviewing tasks. I could also split into more PRs.

Introduces a bunch of new utils at `clippy_utils::macros::...`. Please read through the docs and give any feedback! I'm happy to introduce `MacroCall` and various functions to retrieve an instance. It feels like the missing puzzle piece. I'm also introducing `ExpnId` from rustc as "useful for Clippy too". `@rust-lang/clippy`

Fixes #7843 by not parsing every node of macro implementations, at least the major offenders.

I probably want to get rid of `is_expn_of` at some point.
2022-01-04 22:32:02 +00:00
bors
786f874c34 New macro utils
changelog: none

Sorry, this is a big one. A lot of interrelated changes and I wanted to put the new utils to use to make sure they are somewhat battle-tested. We may want to divide some of the lint-specific refactoring commits into batches for smaller reviewing tasks. I could also split into more PRs.

Introduces a bunch of new utils at `clippy_utils::macros::...`. Please read through the docs and give any feedback! I'm happy to introduce `MacroCall` and various functions to retrieve an instance. It feels like the missing puzzle piece. I'm also introducing `ExpnId` from rustc as "useful for Clippy too". `@rust-lang/clippy`

Fixes #7843 by not parsing every node of macro implementations, at least the major offenders.

I probably want to get rid of `is_expn_of` at some point.
2022-01-04 22:32:02 +00:00
Matthias Krüger
d7a60337fc Rollup merge of #91907 - lcnr:const-arg-infer, r=BoxyUwU
Allow `_` as the length of array types and repeat expressions

r? `@BoxyUwU` cc `@varkor`
2022-01-04 21:23:06 +01:00
Jason Newcomb
2dd216a186 Check for full equality in type_repetition_in_bounds rather than just equal hashes 2022-01-04 14:28:27 -05:00
Jason Newcomb
a7097b80c3 Consider auto-deref when linting manual_swap 2022-01-04 13:22:30 -05:00
Jason Newcomb
ff58efb2b2 Better detect when a field can be moved from in while_let_on_iterator 2022-01-03 23:13:31 -05:00
Wigy
e8b6b2ac0c
erasing_op lint ignored when output type is different from the non-const one 2022-01-02 19:36:02 +01:00
bors
b25dbc6a4d Auto merge of #8208 - nmathewson:selfkind_no_fix, r=xFrednet
wrong_self_convention: Match `SelfKind::No` more restrictively

The `wrong_self_convention` lint uses a `SelfKind` type to decide
whether a method has the right kind of "self" for its name, or whether
the kind of "self" it has makes its name confusable for a method in
a common trait.  One possibility is `SelfKind::No`, which is supposed
to mean "No `self`".

Previously, SelfKind::No matched everything _except_ Self, including
references to Self.  This patch changes it to match Self, &Self, &mut
Self, Box<Self>, and so on.

For example, this kind of method was allowed before:

```
impl S {
    // Should trigger the lint, because
    // "methods called `is_*` usually take `self` by reference or no `self`"
    fn is_foo(&mut self) -> bool { todo!() }
}
```

But since SelfKind::No matched "&mut self", no lint was triggered
(see #8142).

With this patch, the code above now gives a lint as expected.

fixes #8142

changelog: [`wrong_self_convention`] rejects `self` references in more cases
2022-01-02 17:14:18 +00:00
bors
262b148d88 return_self_not_must_use document #[must_use] on the type
Inspired by a discussion in rust-lang/rust-clippy#8197

---

r? `@llogiq`

changelog: none

The lint is this on nightly, therefore no changelog entry for you xD
2022-01-01 13:16:49 +00:00
Josh Triplett
f5bbd1b529 Make tidy check for magic numbers that spell things
Remove existing problematic cases.
2021-12-31 21:13:07 -08:00
Nick Mathewson
3d41358a55 wrong_self_convention: Match SelfKind::No more restrictively
The `wrong_self_convention` lint uses a `SelfKind` type to decide
whether a method has the right kind of "self" for its name, or whether
the kind of "self" it has makes its name confusable for a method in
a common trait.  One possibility is `SelfKind::No`, which is supposed
to mean "No `self`".

Previously, SelfKind::No matched everything _except_ Self, including
references to Self.  This patch changes it to match Self, &Self, &mut
Self, Box<Self>, and so on.

For example, this kind of method was allowed before:

```
impl S {
    // Should trigger the lint, because
    // "methods called `is_*` usually take `self` by reference or no `self`"
    fn is_foo(&mut self) -> bool { todo!() }
}
```

But since SelfKind::No matched "&mut self", no lint was triggered
(see #8142).

With this patch, the code above now gives a lint as expected.

Fixes #8142

changelog: [`wrong_self_convention`] rejects `self` references in more cases
2021-12-31 23:39:40 -05:00
bors
c736a63123 Auto merge of #8193 - ebobrow:redundant_closure_fp, r=Manishearth
fix [`redundant_closure`] fp with `Rc<F>`/`Arc<F>`

fixes #8073

changelog: don't trigger [`redundant_closure`] on `Arc<F>` or `Rc<F>`
2021-12-31 19:01:42 +00:00
Nick Mathewson
b6bcf0c51b unused_io_amount: Use span_lint_and_help.
This improves the quality of the genrated output and makes it
more in line with other lint messages.

changelog: [`unused_io_amount`]: Improve help text
2021-12-31 12:21:43 -05:00
Nick Mathewson
65d1f83d2c Extend [unused_io_amount] to cover AsyncRead and AsyncWrite.
Clippy helpfully warns about code like this, telling you that you
probably meant "write_all":

    fn say_hi<W:Write>(w: &mut W) {
       w.write(b"hello").unwrap();
    }

This patch attempts to extend the lint so it also covers this
case:

    async fn say_hi<W:AsyncWrite>(w: &mut W) {
       w.write(b"hello").await.unwrap();
    }

(I've run into this second case several times in my own programming,
and so have my coworkers, so unless we're especially accident-prone
in this area, it's probably worth addressing?)

This patch covers the Async{Read,Write}Ext traits in futures-rs,
and in tokio, since both are quite widely used.

changelog: [`unused_io_amount`] now supports AsyncReadExt and AsyncWriteExt.
2021-12-31 12:10:59 -05: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
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
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
c8f016f921 Fix reversed suggestion on postfix 2021-12-25 21:55:20 +08:00
dswij
df2e4d17c6 update enum_variants test 2021-12-25 21:55:20 +08:00
Elliot Bobrow
1b67aa74bd fix shadow_reuse false negative for if let bindings 2021-12-24 13:20:40 -08:00
hotate29
0b6d1fdea2
refactor ``Sugg::BinOp`` 2021-12-25 00:29:29 +09:00
hotate29
b3b65a1bf6
Add test 2021-12-25 00:29:24 +09:00
Piotr Mikulski
db236e668c Fix tests 2021-12-23 21:43:44 -08:00
Piotr Mikulski
88871bffdf Fix tests 2021-12-23 21:42:56 -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
13cc452286 Add allow unused 2021-12-23 10:51:17 +01:00
Oussama
dce3151872 Add allow precedence lint to prevent rustfix from failing 2021-12-23 09:22:29 +01:00
Mara Bos
01217f6f4c Bless clippy test. 2021-12-22 17:25:44 +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
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
hotate29
13ad14b22d
update: ``Sugg::not()`` replacing the comparison operator. #7320
When inverting an expression, the output is now like ```foo != 0``` instead of ```!(foo == 0)```, the comparison operator is now replaced.
2021-12-18 00:07:36 +09: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
Matthias Krüger
b2f8a27ff2 Rollup merge of #90521 - jhpratt:stabilize-destructuring_assignment, r=jackh726,pnkfelix
Stabilize `destructuring_assignment`

Closes #71126

- [Stabilization report](https://github.com/rust-lang/rust/issues/71126#issuecomment-941148058)
- [Completed FCP](https://github.com/rust-lang/rust/issues/71126#issuecomment-954914819)

`@rustbot` label +F-destructuring-assignment +T-lang
Also needs +relnotes but I don't have permission to add that tag.
2021-12-15 08:36:19 +01:00
Jacob Pratt
f8817f63e1 Stabilize destructuring_assignment 2021-12-14 22:38:51 -05:00
Matthias Krüger
b166642c35 Rollup merge of #90939 - estebank:wg-af-polish, r=tmandry
Tweak errors coming from `for`-loop, `?` and `.await` desugaring

 * Suggest removal of `.await` on non-`Future` expression
 * Keep track of obligations introduced by desugaring
 * Remove span pointing at method for obligation errors coming from desugaring
 * Point at called local sync `fn` and suggest making it `async`

```
error[E0277]: `()` is not a future
  --> $DIR/unnecessary-await.rs:9:10
   |
LL |     boo().await;
   |     -----^^^^^^ `()` is not a future
   |     |
   |     this call returns `()`
   |
   = help: the trait `Future` is not implemented for `()`
help: do not `.await` the expression
   |
LL -     boo().await;
LL +     boo();
   |
help: alternatively, consider making `fn boo` asynchronous
   |
LL | async fn boo () {}
   | +++++
```

Fix #66731.
2021-12-15 01:28:04 +01:00
bors
6b6cc5d576 Auto merge of #91728 - Amanieu:stable_asm, r=joshtriplett
Stabilize asm! and global_asm!

Tracking issue: #72016

It's been almost 2 years since the original [RFC](https://github.com/rust-lang/rfcs/pull/2850) was posted and we're finally ready to stabilize this feature!

The main changes in this PR are:
- Removing `asm!` and `global_asm!` from the prelude as per the decision in #87228.
- Stabilizing the `asm` and `global_asm` features.
- Removing the unstable book pages for `asm` and `global_asm`. The contents are moved to the [reference](https://github.com/rust-lang/reference/pull/1105) and [rust by example](https://github.com/rust-lang/rust-by-example/pull/1483).
  - All links to these pages have been removed to satisfy the link checker. In a later PR these will be replaced with links to the reference or rust by example.
- Removing the automatic suggestion for using `llvm_asm!` instead of `asm!` if you're still using the old syntax, since it doesn't work anymore with `asm!` no longer being in the prelude. This only affects code that predates the old LLVM-style `asm!` being renamed to `llvm_asm!`.
- Updating `stdarch` and `compiler-builtins`.
- Updating all the tests.

r? `@joshtriplett`
2021-12-14 21:15:22 +00:00
Esteban Kuber
c5287b37fa fix clippy tests 2021-12-13 17:09:16 +00:00
Esteban Kuber
1c3747e7dd Fix rebase and clippy tests 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
Amanieu d'Antras
e1139cf570 Fix clippy tests 2021-12-13 00:00:51 +00:00
Ellen
603b865ae4 clippy owo 2021-12-12 12:34:21 +00: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
2b35edbb84 Update other UI tests as well 2021-12-08 11:16:14 +01: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
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
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
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
e3c60444ce
fix some false negatives for single_char_pattern 2021-12-05 17:33:52 +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
Cameron Steffen
de9de4fef1 Upgrade map_flatten to complexity 2021-12-03 13:21:48 -06: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
flip1995
abddd6c491
Merge remote-tracking branch 'upstream/master' into rustup 2021-12-02 09:32:09 +00:00
bors
8ad56c8fb7 Auto merge of #8049 - surechen:fixes_7946, r=flip1995
Add test for pattern_type_mismatch.

This issue has been fixed by [commit](8c1c763c2d)
This PR is used for close #7946(Fixes #7946).

changelog: Add test for pattern_type_mismatch.
2021-12-01 09:58:54 +00:00
homersimpsons
522f3f901f
no_std_swap: Remove obsolete TODO from test 2021-12-01 09:43:35 +00:00
surechen
bd63686e0f Add test for pattern_type_mismatch.
This issue has been fixed by [commit](8c1c763c2d)
This PR is used for close #7946(Fixes #7946).

changelog: Add test for pattern_type_mismatch.
2021-12-01 17:37:50 +08:00
bors
908815ce98 Auto merge of #8001 - Jarcho:unprefixed_strlen, r=giraffate
Improve `strlen_on_c_string`

fixes: #7436

changelog: lint `strlen_on_c_string` when used without a fully-qualified path
changelog: suggest removing the surrounding unsafe block for `strlen_on_c_string` when possible
2021-11-29 01:03:48 +00:00
bors
4e84dd121f Auto merge of #8006 - togami2864:generalize-copied, r=camsteffen
apply iter_cloned_collect to collect() using copied()

fix: #6703

changelog: apply `iter_cloned_collect` to `collect()` using`copied()`
2021-11-28 20:59:20 +00:00
togami2864
f51bbc7db9 apply iter_cloned_collect to copied() 2021-11-28 23:59:31 +09:00
Aaron Hill
3c8b644d0d Only check for errors in predicate when skipping impl assembly
Prior to PR #91205, checking for errors in the overall obligation
would check checking the `ParamEnv`, due to an incorrect
`super_visit_with` impl. With this bug fixed, we will now
bail out of impl candidate assembly if the `ParamEnv` contains
any error types.

In practice, this appears to be overly conservative - when an error
occurs early in compilation, we end up giving up early for some
predicates that we could have successfully evaluated without overflow.
By only checking for errors in the predicate itself, we avoid causing
additional spurious 'type annotations needed' errors after a 'real'
error has already occurred.

With this PR, the diagnostic changes caused by PR #91205 are reverted.
2021-11-27 11:33:55 -06:00
bors
3720735f9a Auto merge of #7995 - Alexendoo:needless_late_init, r=giraffate
Add `needless_late_init` lint

examples:

```rust
let a;
a = 1;
// to
let a = 1;
```
```rust
let b;
match 3 {
    0 => b = "zero",
    1 => b = "one",
    _ => b = "many",
}
// to
let b = match 3 {
    0 => "zero",
    1 => "one",
    _ => "many",
};
```
```rust
let c;
if true {
    c = 1;
} else {
    c = -1;
}
// to
let c = if true {
    1
} else {
    -1
};
```

changelog: Add [`needless_late_init`]
2021-11-27 14:24:02 +00:00
Alex Macleod
d346ec94fe Add async/const fn tests for needless-late-init
+nits
2021-11-26 14:27:53 +00:00
bors
6b997b6576 Auto merge of #91205 - Aaron1011:visit_param_env, r=lcnr
Visit `param_env` field in Obligation's `TypeFoldable` impl

This oversight appears to have gone unnoticed for a long time
without causing issues, but it should still be fixed.
2021-11-26 09:55:06 +00:00
togami2864
e8ef6ca5e3 fix stderr 2021-11-26 18:49:14 +09:00
togami2864
140ba610e4 add test suit 2021-11-26 18:34:07 +09:00
Aaron Hill
9274ec5691 Visit param_env field in Obligation's TypeFoldable impl
This oversight appears to have gone unnoticed for a long time
without causing issues, but it should still be fixed.
2021-11-25 15:33:37 -06:00
Esteban Kuber
5fc61a24c4 Fix clippy test 2021-11-25 18:39:32 +00:00
Maybe Waffle
40a6c519b4 Update tests for type_complexity lint 2021-11-25 12:47:29 +03:00
Maybe Waffle
063f8aa094 Ignore associated types in traits when considering type complexity 2021-11-25 12:08:18 +03:00
Dharma Saputra Wijaya
c0bad8bcab Add more descriptive help info for needless_question_mark 2021-11-25 14:01:14 +08:00
Jason Newcomb
a135347f5d Run rustfix for strlen_on_c_strings tests 2021-11-24 20:16:27 -05:00
Alex Macleod
3957244120 Add needless_late_init lint 2021-11-23 15:08:49 +00:00
flip1995
5740230ec7
Merge remote-tracking branch 'upstream/master' into rustup 2021-11-23 11:22:34 +01:00
dswij
ec3d1c8ca3 Fix FP on if_then_some_else_none when there is early return 2021-11-23 10:11:30 +08:00
bors
57a8804ef9 Auto merge of #8007 - birkenfeld:octal_escapes, r=xFrednet
Add new lint `octal_escapes`

This checks for sequences in strings that would be octal character
escapes in C, but are not supported in Rust.  It suggests either
to use the `\x00` escape, or an equivalent hex escape if the octal
was intended.

Fixes #7981

---

*Please write a short comment explaining your change (or "none" for internal only changes)*

changelog: Add new lint [`octal_escapes`], which checks for literals like `"\033[0m"`.
2021-11-22 20:29:53 +00:00
Georg Brandl
0bc25d04c6 octal_escapes: emit only one lint for all cases found each literal 2021-11-22 21:00:19 +01:00
Georg Brandl
850e7f533e octal_escapes: updates from review, fix byte string prefix 2021-11-22 18:02:17 +01:00
bors
5fbfdfa319 Auto merge of #8009 - xFrednet:8004-suboptimal-flops-in-const, r=giraffate
Allow `suboptimal_flops` in const functions

This PR allows `clippy::suboptimal_flops` in constant functions. The check also effects the `clippy::imprecise_flops` lint logic. However, this doesn't have any effects as all functions checked for are not const and can therefore not be found in such functions.

---

changelog: [`suboptimal_flops`]: No longer triggers in constant functions

Closes: rust-lang/rust-clippy#8004
2021-11-22 00:01:49 +00:00
bors
de2208a351 Auto merge of #7997 - surechen:Fixes_7915, r=giraffate
Fixes shadow_same's false positive for #7915

Fix shadow_same's false positive for async function's params(Fixes #7915):

Example Code:
```rust
#![deny(clippy::shadow_same)]

pub async fn foo(_a: i32) {
}
```
Output:
```
error: `_a` is shadowed by itself in `_a
```

Hir:
```rust
pub async fn foo(_a: i32)
 ->
     /*impl Trait*/ #[lang = "from_generator"](move |mut _task_context|
                                                   {
                                                       let _a = _a;
                                                       { let _t = { }; _t }
                                                   })
```

Skip checking async function's params.

changelog: Fix shadow_same's false positive for async function's params
2021-11-21 23:48:24 +00:00