Skip to content

Commit bac6b62

Browse files
committed
Convert NAMED_ASM_LABELS lint to diag struct
1 parent 36902fb commit bac6b62

File tree

5 files changed

+14
-20
lines changed

5 files changed

+14
-20
lines changed

compiler/rustc_lint/messages.ftl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ lint_builtin_anonymous_params = anonymous parameters are deprecated and will be
3030
.suggestion = try naming the parameter or explicitly ignoring it
3131
3232
lint_builtin_asm_labels = avoid using named labels in inline assembly
33+
.help = only local labels of the form `<number>:` should be used in inline asm
34+
.note = see the asm section of Rust By Example <https://doc.rust-lang.org/nightly/rust-by-example/unsafe/asm.html#labels> for more information
3335
3436
lint_builtin_box_pointers = type uses owned (Box type) pointers: {$ty}
3537

compiler/rustc_lint/src/builtin.rs

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ use crate::{
3030
BuiltinExplicitOutlivesSuggestion, BuiltinFeatureIssueNote, BuiltinIncompleteFeatures,
3131
BuiltinIncompleteFeaturesHelp, BuiltinInternalFeatures, BuiltinKeywordIdents,
3232
BuiltinMissingCopyImpl, BuiltinMissingDebugImpl, BuiltinMissingDoc,
33-
BuiltinMutablesTransmutes, BuiltinNoMangleGeneric, BuiltinNonShorthandFieldPatterns,
34-
BuiltinSpecialModuleNameUsed, BuiltinTrivialBounds, BuiltinTypeAliasGenericBounds,
35-
BuiltinTypeAliasGenericBoundsSuggestion, BuiltinTypeAliasWhereClause,
36-
BuiltinUngatedAsyncFnTrackCaller, BuiltinUnpermittedTypeInit,
33+
BuiltinMutablesTransmutes, BuiltinNamedAsmLabel, BuiltinNoMangleGeneric,
34+
BuiltinNonShorthandFieldPatterns, BuiltinSpecialModuleNameUsed, BuiltinTrivialBounds,
35+
BuiltinTypeAliasGenericBounds, BuiltinTypeAliasGenericBoundsSuggestion,
36+
BuiltinTypeAliasWhereClause, BuiltinUngatedAsyncFnTrackCaller, BuiltinUnpermittedTypeInit,
3737
BuiltinUnpermittedTypeInitSub, BuiltinUnreachablePub, BuiltinUnsafe,
3838
BuiltinUnstableFeatures, BuiltinUnusedDocComment, BuiltinUnusedDocCommentSub,
3939
BuiltinWhileTrue, SuggestChangingAssocTypes,
@@ -60,7 +60,7 @@ use rustc_middle::ty::GenericArgKind;
6060
use rustc_middle::ty::TypeVisitableExt;
6161
use rustc_middle::ty::Upcast;
6262
use rustc_middle::ty::{self, Ty, TyCtxt, VariantDef};
63-
use rustc_session::lint::{BuiltinLintDiag, FutureIncompatibilityReason};
63+
use rustc_session::lint::FutureIncompatibilityReason;
6464
use rustc_session::{declare_lint, declare_lint_pass, impl_lint_pass};
6565
use rustc_span::edition::Edition;
6666
use rustc_span::source_map::Spanned;
@@ -2882,16 +2882,7 @@ impl<'tcx> LateLintPass<'tcx> for NamedAsmLabels {
28822882
let target_spans: MultiSpan =
28832883
if spans.len() > 0 { spans.into() } else { (*template_span).into() };
28842884

2885-
cx.span_lint_with_diagnostics(
2886-
NAMED_ASM_LABELS,
2887-
Some(target_spans),
2888-
fluent::lint_builtin_asm_labels,
2889-
|_| {},
2890-
BuiltinLintDiag::NamedAsmLabel(
2891-
"only local labels of the form `<number>:` should be used in inline asm"
2892-
.to_string(),
2893-
),
2894-
);
2885+
cx.emit_span_lint(NAMED_ASM_LABELS, target_spans, BuiltinNamedAsmLabel);
28952886
}
28962887
}
28972888
}

compiler/rustc_lint/src/context/diagnostics.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,6 @@ pub(super) fn builtin(sess: &Session, diagnostic: BuiltinLintDiag, diag: &mut Di
179179
Applicability::MachineApplicable,
180180
);
181181
}
182-
BuiltinLintDiag::NamedAsmLabel(help) => {
183-
diag.help(help);
184-
diag.note("see the asm section of Rust By Example <https://doc.rust-lang.org/nightly/rust-by-example/unsafe/asm.html#labels> for more information");
185-
}
186182
BuiltinLintDiag::UnexpectedCfgName(name, value) => {
187183
check_cfg::unexpected_cfg_name(sess, diag, name, value)
188184
}

compiler/rustc_lint/src/lints.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1947,3 +1947,9 @@ pub struct UnitBindingsDiag {
19471947
#[label]
19481948
pub label: Span,
19491949
}
1950+
1951+
#[derive(LintDiagnostic)]
1952+
#[diag(lint_builtin_asm_labels)]
1953+
#[help]
1954+
#[note]
1955+
pub struct BuiltinNamedAsmLabel;

compiler/rustc_lint_defs/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,6 @@ pub enum BuiltinLintDiag {
592592
ReservedPrefix(Span),
593593
TrailingMacro(bool, Ident),
594594
BreakWithLabelAndLoop(Span),
595-
NamedAsmLabel(String),
596595
UnicodeTextFlow(Span, String),
597596
UnexpectedCfgName((Symbol, Span), Option<(Symbol, Span)>),
598597
UnexpectedCfgValue((Symbol, Span), Option<(Symbol, Span)>),

0 commit comments

Comments
 (0)