fix: correct suggestion for significant_drop_in_scrutinee in expressions (#14019)
This PR fixes an issue with the `significant_drop_in_scrutinee`, where
the lint generates invalid Rust syntax when suggesting fixes for match
expressions that are part of larger expressions, such as in assignment
contexts. For example:
```rust
let mutex = Mutex::new(State {});
let _ = match mutex.lock().unwrap().foo() {
true => 0,
false => 1,
};
```
would suggest:
```rust
let _ = let value = mutex.lock().unwrap().foo();
match value {
```
With this PR, it now suggests:
```rust
let value = mutex.lock().unwrap().foo();
let _ = match value {
```
closes: #13986
changelog: [`significant_drop_in_scrutinee`] Fix incorrect suggestion
for `significant_drop_in_scrutinee` lint in expression context
This commit is contained in:
commit
d1b5fa2416
3 changed files with 33 additions and 3 deletions
|
|
@ -2,7 +2,7 @@ use std::ops::ControlFlow;
|
|||
|
||||
use crate::FxHashSet;
|
||||
use clippy_utils::diagnostics::span_lint_and_then;
|
||||
use clippy_utils::source::{indent_of, snippet};
|
||||
use clippy_utils::source::{first_line_of_span, indent_of, snippet};
|
||||
use clippy_utils::ty::{for_each_top_level_late_bound_region, is_copy};
|
||||
use clippy_utils::{get_attr, is_lint_allowed};
|
||||
use itertools::Itertools;
|
||||
|
|
@ -152,7 +152,7 @@ fn set_suggestion<'tcx>(diag: &mut Diag<'_, ()>, cx: &LateContext<'tcx>, expr: &
|
|||
diag.multipart_suggestion(
|
||||
suggestion_message,
|
||||
vec![
|
||||
(expr.span.shrink_to_lo(), replacement),
|
||||
(first_line_of_span(cx, expr.span).shrink_to_lo(), replacement),
|
||||
(found.found_span, scrutinee_replacement),
|
||||
],
|
||||
Applicability::MaybeIncorrect,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue