Commit graph

8949 commits

Author SHA1 Message Date
bors
e1da00210a Auto merge of #10363 - c410-f3r:lock-1, r=xFrednet
[significant_drop_tightening] Ignore inexpensive statements

Not all statements that follow the last use of a lock guard are expensive and can therefore be ignored by the lint.

```rust
pub fn foo() -> i32 {
    let mutex = Mutex::new(1);
    let lock = mutex.lock().unwrap();
    let rslt = *lock;
    let another = rslt;
   another
}
```

---

changelog: [`significant_drop_tightening`]: No longer lints for inexpensive statements after the lock guard
[#10363](https://github.com/rust-lang/rust-clippy/pull/10363)
<!-- changelog_checked -->
2023-02-18 10:25:15 +00:00
Caio
747f81ecd0 [significant_drop_tightening] Ignore inexpensive statements 2023-02-16 18:34:33 -03:00
bors
6444621c10 Auto merge of #10336 - samueltardieu:issue-10241, r=llogiq
manual_let_else: do not suggest semantically different replacements

The problem is that this lint does not consider the possibility that the divergent branch can come first and that the patterns may overlap. This led to incorrect suggestions, previously registered as correct in the tests themselves:

```rust
let v = match build_enum() {
    _ => continue,
    Variant::Bar(v) | Variant::Baz(v) => v,
};
```

had a `let Variant::Bar(v) | Variant::Baz(v) = v else { continue; }` suggestion, which is obviously wrong as the original code `continue`s in any case. Issue #10241 gives another example.

The code now checks that the divergent branch comes second. It could be extended later (I've added a TODO) to check for non-overlapping patterns.

Fixes #10241.

changelog: [`manual_let_else`] do not suggest non equivalent replacements in `match`
2023-02-16 20:30:42 +00:00
bors
eac0bd9da3 Auto merge of #10361 - nindalf:nth_bytes_copy, r=llogiq
Stop bytes_nth from suggesting code that does not compile

Fixes #10151

As discussed in the issue, this PR changes the lint in 2 ways

1. Replace `bytes().nth(n).unwrap()` with `as_bytes()[n]`
2. Replace other `bytes().nth(n)` with `as_bytes().get(n).copied()`

---

changelog: Stop bytes_nth from suggesting code that does not compile in some cases
2023-02-16 17:25:25 +00:00
bors
be7477381b Auto merge of #10357 - nindalf:doc_markdown_relax, r=llogiq
Stop doc_markdown requiring backticks on links to external websites

Fixes #10302

This lint currently checks that any link should be enclosed with `backticks` if the title looks like a lang item. This PR changes the lint to only run on internal links. External links, indicated by `http` or `https`, are skipped.

This PR also reorganises `pulldown_cmark` imports to bypass the clippy lint enforcing 100 line functions.

---

changelog: Stop doc_markdown requiring backticks on links to external websites
2023-02-16 17:09:18 +00:00
Krishna Sundarram
7e53e27dfd Stop bytes_nth from suggesting code that does not compile 2023-02-16 17:05:21 +00:00
Jirka Vebr
6d0df84f6f
Add the transmute_int_to_non_zero lint 2023-02-16 16:58:05 +01:00
Krishna Sundarram
9c9dbc2408 Fix DOC_MARKDOWN requiring backticks on links to external websites 2023-02-16 14:47:30 +00:00
bors
52c8b536c9 Auto merge of #10342 - mitsuhiko:feature/question-mark-used, r=Alexendoo
Add question-mark-used lint

This lint complains when the question mark operator (try operator) is used.  This is a restriction lint that can be useful on local scopes where a custom error handling macro is supposed to be used to augment the error based on local scope data before returning.

Fixes #10340

---

changelog: New lint [`question_mark_used`]
[#10342](https://github.com/rust-lang/rust-clippy/pull/10342)
<!-- changelog_checked -->
2023-02-16 14:21:43 +00:00
bors
99d4ea4f39 Auto merge of #10356 - JirkaVebr:let_underscore_untyped, r=llogiq
Add `let_underscore_untyped`

Fixes #6842

This adds a new pedantic `let_underscore_untyped` lint which checks for `let _ = <expr>`, and suggests to either provide a type annotation, or to remove the `let` keyword. That way the author is forced to specify the type they intended to ignore, and thus get forced to re-visit the decision should the type of `<expr>` change. Alternatively, they can drop the `let` keyword to truly just ignore the value no matter what.

r? `@llogiq`

changelog: New lint: [let_underscore_untyped]
2023-02-16 12:58:43 +00:00
bors
4369a67a9b Auto merge of #10163 - c410-f3r:lock-1, r=llogiq
[significant_drop_tightening] Add MVP

cc #9399

Creates the lint with minimum functionalities, which is a good start IMO.

---

changelog: new lint: [`significant_drop_tightening`]
[#10163](https://github.com/rust-lang/rust-clippy/pull/10163)
<!-- changelog_checked -->
2023-02-16 12:30:26 +00:00
Jirka Vebr
0b1ae20365
Fix dogfood tests by adding type annotations 2023-02-16 13:29:38 +01:00
Armin Ronacher
09337981b2 Added check for local spans 2023-02-16 13:21:34 +01:00
Jirka Vebr
2d4d39de53
Add the let_underscore_untyped lint 2023-02-16 13:05:33 +01:00
Krishna Sundarram
f12b492ee0 Change unusual_byte_groupings to require byte groupings of equal size 2023-02-16 11:31:42 +00:00
Michael Krasnitski
1ee4651ca1 Ignore synthetic type parameters for extra_unused_type_parameters 2023-02-15 10:01:33 -05:00
bors
595f783f22 Auto merge of #10321 - mkrasnitski:false-positives, r=flip1995
Fix false positives for `extra_unused_type_parameters`

Don't lint external macros. Also, if the function body is empty, any type parameters with bounds on them are not linted. Note that only the body needs be empty - this rule still applies if the function takes any arguments.

fixes #10318
fixes #10319
changelog: none
<!-- changelog_checked -->
2023-02-15 14:37:16 +00:00
bors
8754d5a6fb Auto merge of #10343 - samueltardieu:issue-10339, r=Alexendoo
uninlined_format_args: do not inline argument with generic parameters

Fix #10339

---

changelog: FP: [`uninlined_format_args`]: No longer lints for arguments with generic parameters
[#10343](https://github.com/rust-lang/rust-clippy/pull/10343)
<!-- changelog_checked -->
2023-02-15 13:35:49 +00:00
bors
d3d235dcbf Auto merge of #10345 - J-ZhengLi:issue_10049, r=xFrednet
fix [`needless_return`] incorrect suggestion when returning if sequence

fixes: #10049

---

changelog: [`needless_return`]: fix incorrect suggestion  on if sequence
2023-02-15 10:27:46 +00:00
Samuel Tardieu
75aa2b9ec8 uninlined_format_args: do not inline argument with generic parameters 2023-02-15 08:49:43 +01:00
bors
e018a2c8bd Auto merge of #10328 - compiler-errors:fix-re-erased-in-needless_pass_by_value, r=matthiaskrgr
Liberate late-bound regions rather than erasing them in `needless_pass_by_value`

changelog: [`needless_pass_by_value`]: fixes an ICE when there are late-bound regions in function arguments that are needlessly passed by value

Fixes rust-lang/rust#107147
r? `@matthiaskrgr`
2023-02-15 06:41:35 +00:00
J-ZhengLi
8b93eb8a9b add some adjustment regarding review suggestion 2023-02-15 11:26:30 +08:00
Samuel Tardieu
7f15a11aa1 manual_let_else: let/else is not divergent by default
The divergent `else` block of a `let`/`else` statement does not make
the `let`/`else` statement itself divergent.
2023-02-15 00:47:43 +01:00
Michael Goulet
17cb2e47e5 Liberate late-bound regions rather than erasing them in needless_pass_by_value 2023-02-14 23:27:46 +00:00
bors
0e40f94a86 Auto merge of #10346 - samueltardieu:issue-10331, r=Manishearth
Do not base map_entry lint suggestion on expanded code

Fixes #10331

changelog: [`map_entry`]: do not base suggestion on code expanded by the compiler
2023-02-14 23:21:08 +00:00
Samuel Tardieu
e4e5924b99 Do not base map_entry lint suggestion on expanded code 2023-02-14 15:37:48 +01:00
Samuel Tardieu
657ee48bec Ignore instructions following a break from block in never_loop lint
It is not sufficient to ignore break from a block inside the loop.
Instructions after the break must be ignored, as they are unreachable.
This is also true for all instructions in outer blocks and loops
until the right block is reached.
2023-02-14 09:55:44 +01:00
Samuel Tardieu
e9dffa3910 Fix a bug in never_loop when anonymous blocks are nested in named blocks
The following code

```
loop {
    'a: {
        { }
        break 'a;
    }
}
```

was detected as a never-looping loop.
2023-02-14 09:23:04 +01:00
J-ZhengLi
8e96adedd5 fix [needless_return] incorrect suggestion when returning if sequence 2023-02-14 11:31:42 +08:00
Samuel Tardieu
1fec2927c5 Replace combine_both by combine_seq
All evaluations now happen in order.
2023-02-13 22:34:05 +01:00
Samuel Tardieu
c231b41887 Remove useless call to combine_seq
`combine_seq(x, NeverLoopResult::Otherwise)`  always returns `x`
2023-02-13 22:34:05 +01:00
Armin Ronacher
89314a0805 Add question-mark-used lint
This lint complains when the question mark operator (try operator)
is used.  This is a restriction lint that can be useful on local
scopes where a custom error handling macro is supposed to be used
to augment the error based on local scope data before returning.
2023-02-13 20:59:26 +01:00
bors
ac60dcaa25 Auto merge of #10177 - chansuke:almost_swapped, r=Alexendoo
Almost swapped

Take over from https://github.com/rust-lang/rust-clippy/pull/8945

Fix https://github.com/rust-lang/rust-clippy/issues/8151

---

changelog: enhancement: [`almost_swapped`]: Now detects almost swaps using `let` statements
[#10177](https://github.com/rust-lang/rust-clippy/pull/10177)
<!-- changelog_checked -->
2023-02-13 13:20:18 +00:00
chansuke
ebca1b5d00 Refactor almost_swapped to lint with let statement correctly 2023-02-13 16:16:31 +09:00
bors
298f139798 Auto merge of #10317 - m-ou-se:suspicious-command-arg-space, r=Manishearth
Add `suspicious_command_arg_space` lint

Fixes #10316

---

changelog: New lint: [`suspicious_command_arg_space`]
[#10317](https://github.com/rust-lang/rust-clippy/pull/10317)
<!-- changelog_checked -->
2023-02-12 21:57:49 +00:00
Mara Bos
1f77866991 Add SUSPICIOUS_COMMAND_ARG_SPACE to lint pass. 2023-02-12 22:00:13 +01:00
bors
6f353fdf0a Auto merge of #10310 - c410-f3r:arith-2, r=Alexendoo
[arithmetic_side_effects] Fix #10209

Fix #10209

---

changelog: Enhancement: [`arithmetic_side_effects`]: No longer lints, if safe constant values are used.
[#10310](https://github.com/rust-lang/rust-clippy/pull/10310)
<!-- changelog_checked -->
2023-02-12 19:34:15 +00:00
Caio
1ed8ed3435 Address comment 2023-02-12 16:27:30 -03:00
Caio
e70a7a68bd [arithmetic_side_effects] Evaluate integers originated from constant declarations 2023-02-12 16:19:51 -03:00
Caio
1b286b128b Address comments 2023-02-12 16:17:37 -03:00
Samuel Tardieu
09d3097734 manual_let_else: do not suggest semantically different replacements 2023-02-12 20:07:23 +01:00
Samuel Tardieu
d9dc1679f5 cast_possible_truncation: issue proper help message 2023-02-12 08:56:21 +01:00
Michael Krasnitski
8789b37d06 Fix false positives for extra_unused_type_parameters 2023-02-11 12:22:25 -05:00
Caio
078f149aa4 [significant_drop_tightening] Add MVP 2023-02-10 15:07:34 -03:00
Mara Bos
8f56767c94 Update lints. 2023-02-10 19:03:20 +01:00
Mara Bos
984c47b9f4 Clarify description of suspicious_command_arg_space.
Co-authored-by: Manish Goregaokar <manishsmail@gmail.com>
2023-02-10 19:02:39 +01:00
Mara Bos
145e6a94d6 Add suspicious_command_arg_space lint. 2023-02-10 19:02:39 +01:00
Philipp Krones
7c61b4ed89
Merge remote-tracking branch 'upstream/master' into rustup 2023-02-10 11:33:45 +01:00
DevAccentor
179c037643 improve almost swap to look for let statement 2023-02-10 18:00:46 +09:00
bors
5adeebf92f Auto merge of #10292 - xFrednet:0000-support-trait-item-in-dump, r=flip1995
Make `[clippy::dump]` support trait items

Roses are red,
violets are blue,
trait items are rare,
`[clippy::dump]` is too

---

Let's just ignore the horrible poem... anyways. While working on Marker I noticed, that `[clippy::dump]` doesn't work on trait item (See [Playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=e2d9791ffa2872e7c09a9dfbd470350c)). This simply adds support for that. `[clippy::dump]` doesn't have UI tests, to make it more resistant to changes in the AST. I tested it locally and the dump works after these changes.

---

changelog: none
2023-02-09 13:22:00 +00:00