Skip to content

Commit afc694c

Browse files
committed
Convert NAMED_ASM_LABELS lint to diag struct
1 parent eb1df77 commit afc694c

File tree

5 files changed

+14
-20
lines changed

5 files changed

+14
-20
lines changed

compiler/rustc_lint/messages.ftl

+2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ lint_builtin_anonymous_params = anonymous parameters are deprecated and will be
5151
.suggestion = try naming the parameter or explicitly ignoring it
5252
5353
lint_builtin_asm_labels = avoid using named labels in inline assembly
54+
.help = only local labels of the form `<number>:` should be used in inline asm
55+
.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
5456
5557
lint_builtin_box_pointers = type uses owned (Box type) pointers: {$ty}
5658

compiler/rustc_lint/src/builtin.rs

+6-14
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,
@@ -58,7 +58,7 @@ use rustc_middle::ty::GenericArgKind;
5858
use rustc_middle::ty::ToPredicate;
5959
use rustc_middle::ty::TypeVisitableExt;
6060
use rustc_middle::ty::{self, Ty, TyCtxt, VariantDef};
61-
use rustc_session::lint::{BuiltinLintDiag, FutureIncompatibilityReason};
61+
use rustc_session::lint::FutureIncompatibilityReason;
6262
use rustc_span::edition::Edition;
6363
use rustc_span::source_map::Spanned;
6464
use rustc_span::symbol::{kw, sym, Ident, Symbol};
@@ -2829,15 +2829,7 @@ impl<'tcx> LateLintPass<'tcx> for NamedAsmLabels {
28292829
let target_spans: MultiSpan =
28302830
if spans.len() > 0 { spans.into() } else { (*template_span).into() };
28312831

2832-
cx.span_lint_with_diagnostics(
2833-
NAMED_ASM_LABELS,
2834-
Some(target_spans),
2835-
|_| {},
2836-
BuiltinLintDiag::NamedAsmLabel(
2837-
"only local labels of the form `<number>:` should be used in inline asm"
2838-
.to_string(),
2839-
),
2840-
);
2832+
cx.emit_span_lint(NAMED_ASM_LABELS, target_spans, BuiltinNamedAsmLabel);
28412833
}
28422834
}
28432835
}

compiler/rustc_lint/src/context/diagnostics.rs

-5
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,6 @@ pub(super) fn builtin(sess: &Session, diagnostic: BuiltinLintDiag, diag: &mut Di
183183
Applicability::MachineApplicable,
184184
);
185185
}
186-
BuiltinLintDiag::NamedAsmLabel(help) => {
187-
diag.help(help);
188-
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");
189-
}
190186
BuiltinLintDiag::UnexpectedCfgName(name, value) => {
191187
check_cfg::unexpected_cfg_name(sess, diag, name, value)
192188
}
@@ -431,7 +427,6 @@ pub(super) fn builtin_message(diagnostic: &BuiltinLintDiag) -> DiagMessage {
431427
}
432428
BuiltinLintDiag::TrailingMacro(_, _) => fluent::lint_trailing_semi_macro,
433429
BuiltinLintDiag::BreakWithLabelAndLoop(_) => fluent::lint_break_with_label_and_loop,
434-
BuiltinLintDiag::NamedAsmLabel(_) => fluent::lint_builtin_asm_labels,
435430
BuiltinLintDiag::UnicodeTextFlow(_, _) => fluent::lint_unicode_text_flow,
436431
BuiltinLintDiag::UnexpectedCfgName((name, _), _) => {
437432
format!("unexpected `cfg` condition name: `{}`", name).into()

compiler/rustc_lint/src/lints.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1941,3 +1941,9 @@ pub struct UnitBindingsDiag {
19411941
#[label]
19421942
pub label: Span,
19431943
}
1944+
1945+
#[derive(LintDiagnostic)]
1946+
#[diag(lint_builtin_asm_labels)]
1947+
#[help]
1948+
#[note]
1949+
pub struct BuiltinNamedAsmLabel;

compiler/rustc_lint_defs/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,6 @@ pub enum BuiltinLintDiag {
611611
ReservedPrefix(Span, String),
612612
TrailingMacro(bool, Ident),
613613
BreakWithLabelAndLoop(Span),
614-
NamedAsmLabel(String),
615614
UnicodeTextFlow(Span, String),
616615
UnexpectedCfgName((Symbol, Span), Option<(Symbol, Span)>),
617616
UnexpectedCfgValue((Symbol, Span), Option<(Symbol, Span)>),

0 commit comments

Comments
 (0)