Rollup merge of #119710 - Nilstrieb:let-_-=-oops, r=TaKO8Ki
Improve `let_underscore_lock` - lint if the lock was in a nested pattern - lint if the lock is inside a `Result<Lock, _>` addresses https://github.com/rust-lang/rust/pull/119704#discussion_r1444044745
This commit is contained in:
@@ -930,8 +930,7 @@ pub enum NonBindingLet {
|
||||
|
||||
pub struct NonBindingLetSub {
|
||||
pub suggestion: Span,
|
||||
pub multi_suggestion_start: Span,
|
||||
pub multi_suggestion_end: Span,
|
||||
pub drop_fn_start_end: Option<(Span, Span)>,
|
||||
pub is_assign_desugar: bool,
|
||||
}
|
||||
|
||||
@@ -940,21 +939,31 @@ impl AddToDiagnostic for NonBindingLetSub {
|
||||
where
|
||||
F: Fn(&mut Diagnostic, SubdiagnosticMessage) -> SubdiagnosticMessage,
|
||||
{
|
||||
let prefix = if self.is_assign_desugar { "let " } else { "" };
|
||||
diag.span_suggestion_verbose(
|
||||
self.suggestion,
|
||||
fluent::lint_non_binding_let_suggestion,
|
||||
format!("{prefix}_unused"),
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
diag.multipart_suggestion(
|
||||
fluent::lint_non_binding_let_multi_suggestion,
|
||||
vec![
|
||||
(self.multi_suggestion_start, "drop(".to_string()),
|
||||
(self.multi_suggestion_end, ")".to_string()),
|
||||
],
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
let can_suggest_binding = self.drop_fn_start_end.is_some() || !self.is_assign_desugar;
|
||||
|
||||
if can_suggest_binding {
|
||||
let prefix = if self.is_assign_desugar { "let " } else { "" };
|
||||
diag.span_suggestion_verbose(
|
||||
self.suggestion,
|
||||
fluent::lint_non_binding_let_suggestion,
|
||||
format!("{prefix}_unused"),
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
} else {
|
||||
diag.span_help(self.suggestion, fluent::lint_non_binding_let_suggestion);
|
||||
}
|
||||
if let Some(drop_fn_start_end) = self.drop_fn_start_end {
|
||||
diag.multipart_suggestion(
|
||||
fluent::lint_non_binding_let_multi_suggestion,
|
||||
vec![
|
||||
(drop_fn_start_end.0, "drop(".to_string()),
|
||||
(drop_fn_start_end.1, ")".to_string()),
|
||||
],
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
} else {
|
||||
diag.help(fluent::lint_non_binding_let_multi_drop_fn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user