Skip to content

Commit b3c5b2d

Browse files
committed
Convert NAMED_ASM_LABELS lint to diag struct
1 parent 20d1c8a commit b3c5b2d

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
@@ -37,6 +37,8 @@ lint_builtin_anonymous_params = anonymous parameters are deprecated and will be
3737
.suggestion = try naming the parameter or explicitly ignoring it
3838
3939
lint_builtin_asm_labels = avoid using named labels in inline assembly
40+
.help = only local labels of the form `<number>:` should be used in inline asm
41+
.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
4042
4143
lint_builtin_box_pointers = type uses owned (Box type) pointers: {$ty}
4244

compiler/rustc_lint/src/builtin.rs

+6-15
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};
@@ -2871,16 +2871,7 @@ impl<'tcx> LateLintPass<'tcx> for NamedAsmLabels {
28712871
let target_spans: MultiSpan =
28722872
if spans.len() > 0 { spans.into() } else { (*template_span).into() };
28732873

2874-
cx.span_lint_with_diagnostics(
2875-
NAMED_ASM_LABELS,
2876-
Some(target_spans),
2877-
fluent::lint_builtin_asm_labels,
2878-
|_| {},
2879-
BuiltinLintDiag::NamedAsmLabel(
2880-
"only local labels of the form `<number>:` should be used in inline asm"
2881-
.to_string(),
2882-
),
2883-
);
2874+
cx.emit_span_lint(NAMED_ASM_LABELS, target_spans, BuiltinNamedAsmLabel);
28842875
}
28852876
}
28862877
}

compiler/rustc_lint/src/context/diagnostics.rs

-4
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

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

compiler/rustc_lint_defs/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,6 @@ pub enum BuiltinLintDiag {
593593
ReservedPrefix(Span),
594594
TrailingMacro(bool, Ident),
595595
BreakWithLabelAndLoop(Span),
596-
NamedAsmLabel(String),
597596
UnicodeTextFlow(Span, String),
598597
UnexpectedCfgName((Symbol, Span), Option<(Symbol, Span)>),
599598
UnexpectedCfgValue((Symbol, Span), Option<(Symbol, Span)>),

0 commit comments

Comments
 (0)