Commit graph

4120 commits

Author SHA1 Message Date
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
d037b28025
Merge remote-tracking branch 'upstream/master' into rustup 2022-01-27 14:23:31 +01: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
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