rustc_lint: make let-underscore-lock
translatable
This commit is contained in:
parent
66e5852c3b
commit
c9346a1f05
3 changed files with 9 additions and 8 deletions
|
@ -518,8 +518,8 @@ lint_non_binding_let_multi_suggestion =
|
||||||
lint_non_binding_let_on_drop_type =
|
lint_non_binding_let_on_drop_type =
|
||||||
non-binding let on a type that implements `Drop`
|
non-binding let on a type that implements `Drop`
|
||||||
|
|
||||||
lint_non_binding_let_on_sync_lock =
|
lint_non_binding_let_on_sync_lock = non-binding let on a synchronization lock
|
||||||
non-binding let on a synchronization lock
|
.label = this lock is not assigned to a binding and is immediately dropped
|
||||||
|
|
||||||
lint_non_binding_let_suggestion =
|
lint_non_binding_let_suggestion =
|
||||||
consider binding to an unused variable to avoid immediately dropping the value
|
consider binding to an unused variable to avoid immediately dropping the value
|
||||||
|
|
|
@ -104,7 +104,6 @@ const SYNC_GUARD_SYMBOLS: [Symbol; 3] = [
|
||||||
];
|
];
|
||||||
|
|
||||||
impl<'tcx> LateLintPass<'tcx> for LetUnderscore {
|
impl<'tcx> LateLintPass<'tcx> for LetUnderscore {
|
||||||
#[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable
|
|
||||||
fn check_local(&mut self, cx: &LateContext<'_>, local: &hir::LetStmt<'_>) {
|
fn check_local(&mut self, cx: &LateContext<'_>, local: &hir::LetStmt<'_>) {
|
||||||
if matches!(local.source, rustc_hir::LocalSource::AsyncFn) {
|
if matches!(local.source, rustc_hir::LocalSource::AsyncFn) {
|
||||||
return;
|
return;
|
||||||
|
@ -156,12 +155,12 @@ impl<'tcx> LateLintPass<'tcx> for LetUnderscore {
|
||||||
is_assign_desugar: matches!(local.source, rustc_hir::LocalSource::AssignDesugar(_)),
|
is_assign_desugar: matches!(local.source, rustc_hir::LocalSource::AssignDesugar(_)),
|
||||||
};
|
};
|
||||||
if is_sync_lock {
|
if is_sync_lock {
|
||||||
let mut span = MultiSpan::from_span(pat.span);
|
let span = MultiSpan::from_span(pat.span);
|
||||||
span.push_span_label(
|
cx.emit_span_lint(
|
||||||
pat.span,
|
LET_UNDERSCORE_LOCK,
|
||||||
"this lock is not assigned to a binding and is immediately dropped".to_string(),
|
span,
|
||||||
|
NonBindingLet::SyncLock { sub, pat: pat.span },
|
||||||
);
|
);
|
||||||
cx.emit_span_lint(LET_UNDERSCORE_LOCK, span, NonBindingLet::SyncLock { sub });
|
|
||||||
// Only emit let_underscore_drop for top-level `_` patterns.
|
// Only emit let_underscore_drop for top-level `_` patterns.
|
||||||
} else if can_use_init.is_some() {
|
} else if can_use_init.is_some() {
|
||||||
cx.emit_span_lint(LET_UNDERSCORE_DROP, local.span, NonBindingLet::DropType { sub });
|
cx.emit_span_lint(LET_UNDERSCORE_DROP, local.span, NonBindingLet::DropType { sub });
|
||||||
|
|
|
@ -957,6 +957,8 @@ pub struct BadOptAccessDiag<'a> {
|
||||||
pub enum NonBindingLet {
|
pub enum NonBindingLet {
|
||||||
#[diag(lint_non_binding_let_on_sync_lock)]
|
#[diag(lint_non_binding_let_on_sync_lock)]
|
||||||
SyncLock {
|
SyncLock {
|
||||||
|
#[label]
|
||||||
|
pat: Span,
|
||||||
#[subdiagnostic]
|
#[subdiagnostic]
|
||||||
sub: NonBindingLetSub,
|
sub: NonBindingLetSub,
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue