diff options
| author | Amanieu d'Antras <amanieu@gmail.com> | 2025-05-09 21:27:18 +0100 |
|---|---|---|
| committer | Amanieu d'Antras <amanieu@gmail.com> | 2025-07-26 00:42:21 +0100 |
| commit | 1f4561b63d1bca64675373385ed8292dcd23e7e6 (patch) | |
| tree | 6d289869751a69b07ec571284ef2eaa3a2fcc699 /compiler/rustc_lint/src/builtin.rs | |
| parent | b56aaec52bc0fa35591a872fb4aac81f606e265c (diff) | |
| download | rust-1f4561b63d1bca64675373385ed8292dcd23e7e6.tar.gz rust-1f4561b63d1bca64675373385ed8292dcd23e7e6.zip | |
Don't lint against named labels in `naked_asm!`
Naked functions are allowed to define global labels, just like `global_asm!`.
Diffstat (limited to 'compiler/rustc_lint/src/builtin.rs')
| -rw-r--r-- | compiler/rustc_lint/src/builtin.rs | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index eb4c3703dbd..bf128b5914f 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -2870,7 +2870,7 @@ impl<'tcx> LateLintPass<'tcx> for AsmLabels { if let hir::Expr { kind: hir::ExprKind::InlineAsm(hir::InlineAsm { - asm_macro: AsmMacro::Asm | AsmMacro::NakedAsm, + asm_macro: asm_macro @ (AsmMacro::Asm | AsmMacro::NakedAsm), template_strs, options, .. @@ -2878,6 +2878,15 @@ impl<'tcx> LateLintPass<'tcx> for AsmLabels { .. } = expr { + // Non-generic naked functions are allowed to define arbitrary + // labels. + if *asm_macro == AsmMacro::NakedAsm { + let def_id = expr.hir_id.owner.def_id; + if !cx.tcx.generics_of(def_id).requires_monomorphization(cx.tcx) { + return; + } + } + // asm with `options(raw)` does not do replacement with `{` and `}`. let raw = options.contains(InlineAsmOptions::RAW); |
