From 75915ad16f5e30c822e5a1be35c69f78f98e2c1f Mon Sep 17 00:00:00 2001
From: asquared31415 <34665709+asquared31415@users.noreply.github.com>
Date: Tue, 20 Jul 2021 16:35:26 -0400
Subject: [PATCH 1/8] Lint against named asm labels

---
 compiler/rustc_builtin_macros/src/asm.rs |  76 +++++-
 compiler/rustc_lint/src/context.rs       |   4 +
 compiler/rustc_lint_defs/src/builtin.rs  |  32 +++
 compiler/rustc_lint_defs/src/lib.rs      |   5 +-
 src/test/ui/asm/named_asm_labels.rs      |  95 +++++++
 src/test/ui/asm/named_asm_labels.stderr  | 300 +++++++++++++++++++++++
 6 files changed, 506 insertions(+), 6 deletions(-)
 create mode 100644 src/test/ui/asm/named_asm_labels.rs
 create mode 100644 src/test/ui/asm/named_asm_labels.stderr

diff --git a/compiler/rustc_builtin_macros/src/asm.rs b/compiler/rustc_builtin_macros/src/asm.rs
index ff13f0d4e4207..9a82561db5e65 100644
--- a/compiler/rustc_builtin_macros/src/asm.rs
+++ b/compiler/rustc_builtin_macros/src/asm.rs
@@ -7,7 +7,7 @@ use rustc_errors::{Applicability, DiagnosticBuilder};
 use rustc_expand::base::{self, *};
 use rustc_parse::parser::Parser;
 use rustc_parse_format as parse;
-use rustc_session::lint;
+use rustc_session::lint::{self, BuiltinLintDiagnostics};
 use rustc_span::symbol::Ident;
 use rustc_span::symbol::{kw, sym, Symbol};
 use rustc_span::{InnerSpan, Span};
@@ -397,7 +397,11 @@ fn parse_reg<'a>(
     Ok(result)
 }
 
-fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, args: AsmArgs) -> Option<ast::InlineAsm> {
+fn expand_preparsed_asm(
+    ecx: &mut ExtCtxt<'_>,
+    args: AsmArgs,
+    is_local_asm: bool,
+) -> Option<ast::InlineAsm> {
     let mut template = vec![];
     // Register operands are implicitly used since they are not allowed to be
     // referenced in the template string.
@@ -469,6 +473,70 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, args: AsmArgs) -> Option<ast::Inl
             }
         }
 
+        if is_local_asm {
+            let find_label_span = |needle: &str| -> Option<Span> {
+                if let Some(snippet) = &template_snippet {
+                    if let Some(pos) = snippet.find(needle) {
+                        let end = pos
+                            + &snippet[pos..]
+                                .find(|c| c == ':')
+                                .unwrap_or(snippet[pos..].len() - 1);
+                        let inner = InnerSpan::new(pos, end);
+                        return Some(template_sp.from_inner(inner));
+                    }
+                }
+
+                None
+            };
+
+            let mut found_labels = Vec::new();
+
+            // A semicolon might not actually be specified as a separator for all targets, but it seems like LLVM accepts it always
+            let statements = template_str.split(|c| matches!(c, '\n' | ';'));
+            for statement in statements {
+                let mut start_idx = 0;
+                for (idx, _) in statement.match_indices(':') {
+                    let possible_label = statement[start_idx..idx].trim();
+                    let mut chars = possible_label.chars();
+                    if let Some(c) = chars.next() {
+                        // A label starts with an alphabetic character and continues with alphanumeric characters
+                        if c.is_alphabetic() {
+                            if chars.all(char::is_alphanumeric) {
+                                found_labels.push(possible_label);
+                            }
+                        }
+                    }
+
+                    start_idx = idx + 1;
+                }
+            }
+
+            if found_labels.len() > 0 {
+                let spans =
+                    found_labels.into_iter().filter_map(find_label_span).collect::<Vec<Span>>();
+                if spans.len() > 0 {
+                    for span in spans.into_iter() {
+                        ecx.parse_sess().buffer_lint_with_diagnostic(
+                            lint::builtin::NAMED_ASM_LABELS,
+                            span,
+                            ecx.current_expansion.lint_node_id,
+                            "do not use named labels in inline assembly",
+                            BuiltinLintDiagnostics::NamedAsmLabel("Only GAS local labels of the form `N:` where N is a number may be used in inline asm".to_string()),
+                        );
+                    }
+                } else {
+                    // If there were labels but we couldn't find a span, combine the warnings and use the template span
+                    ecx.parse_sess().buffer_lint_with_diagnostic(
+                        lint::builtin::NAMED_ASM_LABELS,
+                        template_span,
+                        ecx.current_expansion.lint_node_id,
+                        "do not use named labels in inline assembly",
+                        BuiltinLintDiagnostics::NamedAsmLabel("Only GAS local labels of the form `N:` where N is a number may be used in inline asm".to_string()),
+                    );
+                }
+            }
+        }
+
         // Don't treat raw asm as a format string.
         if args.options.contains(ast::InlineAsmOptions::RAW) {
             template.push(ast::InlineAsmTemplatePiece::String(template_str.to_string()));
@@ -670,7 +738,7 @@ pub fn expand_asm<'cx>(
 ) -> Box<dyn base::MacResult + 'cx> {
     match parse_args(ecx, sp, tts, false) {
         Ok(args) => {
-            let expr = if let Some(inline_asm) = expand_preparsed_asm(ecx, args) {
+            let expr = if let Some(inline_asm) = expand_preparsed_asm(ecx, args, true) {
                 P(ast::Expr {
                     id: ast::DUMMY_NODE_ID,
                     kind: ast::ExprKind::InlineAsm(P(inline_asm)),
@@ -697,7 +765,7 @@ pub fn expand_global_asm<'cx>(
 ) -> Box<dyn base::MacResult + 'cx> {
     match parse_args(ecx, sp, tts, true) {
         Ok(args) => {
-            if let Some(inline_asm) = expand_preparsed_asm(ecx, args) {
+            if let Some(inline_asm) = expand_preparsed_asm(ecx, args, false) {
                 MacEager::items(smallvec![P(ast::Item {
                     ident: Ident::invalid(),
                     attrs: Vec::new(),
diff --git a/compiler/rustc_lint/src/context.rs b/compiler/rustc_lint/src/context.rs
index 4a646013ff891..60d9e8e0e71f9 100644
--- a/compiler/rustc_lint/src/context.rs
+++ b/compiler/rustc_lint/src/context.rs
@@ -758,6 +758,10 @@ pub trait LintContext: Sized {
                         Applicability::MachineApplicable
                     );
                 }
+                BuiltinLintDiagnostics::NamedAsmLabel(help) => {
+                    db.help(&help);
+                    db.note("See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information");
+                }
             }
             // Rewrap `db`, and pass control to the user.
             decorate(LintDiagnosticBuilder::new(db));
diff --git a/compiler/rustc_lint_defs/src/builtin.rs b/compiler/rustc_lint_defs/src/builtin.rs
index 9b1ee53df23bd..88288e1a6a63f 100644
--- a/compiler/rustc_lint_defs/src/builtin.rs
+++ b/compiler/rustc_lint_defs/src/builtin.rs
@@ -2470,6 +2470,38 @@ declare_lint! {
     "incorrect use of inline assembly",
 }
 
+declare_lint! {
+    /// The `named_asm_labels` lint detects the use of named labels in the
+    /// inline `asm!` macro.
+    ///
+    /// ### Example
+    ///
+    /// ```rust,compile_fail
+    /// fn main() {
+    ///     unsafe {
+    ///         asm!("foo: bar");
+    ///     }
+    /// }
+    /// ```
+    ///
+    /// {{produces}}
+    ///
+    /// ### Explanation
+    ///
+    /// LLVM's assembler is allowed to duplicate inline assembly blocks for any
+    /// reason, for example when it is in a function that gets inlined. Because
+    /// of this, GNU assembler [local labels] *must* be used instead of labels
+    /// with a name. Using named labels might cause assembler or linker errors.
+    ///
+    /// See the [unstable book] for more details.
+    ///
+    /// [local labels]: https://sourceware.org/binutils/docs/as/Symbol-Names.html#Local-Labels
+    /// [unstable book]: https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels
+    pub NAMED_ASM_LABELS,
+    Deny,
+    "named labels in inline assembly",
+}
+
 declare_lint! {
     /// The `unsafe_op_in_unsafe_fn` lint detects unsafe operations in unsafe
     /// functions without an explicit unsafe block.
diff --git a/compiler/rustc_lint_defs/src/lib.rs b/compiler/rustc_lint_defs/src/lib.rs
index b8f5345ffb884..038e5055a7b15 100644
--- a/compiler/rustc_lint_defs/src/lib.rs
+++ b/compiler/rustc_lint_defs/src/lib.rs
@@ -274,7 +274,7 @@ impl<HCX> ToStableHashKey<HCX> for LintId {
 }
 
 // Duplicated from rustc_session::config::ExternDepSpec to avoid cyclic dependency
-#[derive(PartialEq, Debug)]
+#[derive(PartialEq)]
 pub enum ExternDepSpec {
     Json(Json),
     Raw(String),
@@ -282,7 +282,7 @@ pub enum ExternDepSpec {
 
 // This could be a closure, but then implementing derive trait
 // becomes hacky (and it gets allocated).
-#[derive(PartialEq, Debug)]
+#[derive(PartialEq)]
 pub enum BuiltinLintDiagnostics {
     Normal,
     BareTraitObject(Span, /* is_global */ bool),
@@ -305,6 +305,7 @@ pub enum BuiltinLintDiagnostics {
     ReservedPrefix(Span),
     TrailingMacro(bool, Ident),
     BreakWithLabelAndLoop(Span),
+    NamedAsmLabel(String),
 }
 
 /// Lints that are buffered up early on in the `Session` before the
diff --git a/src/test/ui/asm/named_asm_labels.rs b/src/test/ui/asm/named_asm_labels.rs
new file mode 100644
index 0000000000000..ba277b7aad66f
--- /dev/null
+++ b/src/test/ui/asm/named_asm_labels.rs
@@ -0,0 +1,95 @@
+#![feature(asm, global_asm)]
+
+fn main() {
+    unsafe {
+        // Basic usage
+        asm!("bar: nop"); //~ ERROR do not use named labels
+
+        // No following asm
+        asm!("abcd:"); //~ ERROR do not use named labels
+
+        // Multiple labels on one line
+        asm!("foo: bar1: nop");
+        //~^ ERROR do not use named labels
+        //~| ERROR do not use named labels
+
+        // Multiple lines
+        asm!("foo1: nop", "nop"); //~ ERROR do not use named labels
+        asm!("foo2: foo3: nop", "nop");
+        //~^ ERROR do not use named labels
+        //~| ERROR do not use named labels
+        asm!("nop", "foo4: nop"); //~ ERROR do not use named labels
+        asm!("foo5: nop", "foo6: nop");
+        //~^ ERROR do not use named labels
+        //~| ERROR do not use named labels
+
+        // Statement separator
+        asm!("foo7: nop; foo8: nop");
+        //~^ ERROR do not use named labels
+        //~| ERROR do not use named labels
+        asm!("foo9: nop; nop"); //~ ERROR do not use named labels
+        asm!("nop; foo10: nop"); //~ ERROR do not use named labels
+
+        // Escaped newline
+        asm!("bar2: nop\n bar3: nop");
+        //~^ ERROR do not use named labels
+        //~| ERROR do not use named labels
+        asm!("bar4: nop\n nop"); //~ ERROR do not use named labels
+        asm!("nop\n bar5: nop"); //~ ERROR do not use named labels
+        asm!("nop\n bar6: bar7: nop");
+        //~^ ERROR do not use named labels
+        //~| ERROR do not use named labels
+
+        // Raw strings
+        asm!(
+            r"
+            blah2: nop
+            blah3: nop
+            "
+        );
+        //~^^^^ ERROR do not use named labels
+        //~^^^^ ERROR do not use named labels
+        asm!(
+            r###"
+            nop
+            nop ; blah4: nop
+            "###
+        );
+        //~^^^ ERROR do not use named labels
+
+        // Non-labels
+        // should not trigger lint, but may be invalid asm
+        asm!("ab cd: nop");
+
+        // Only `blah:` should trigger
+        asm!("1bar: blah: nop"); //~ ERROR do not use named labels
+
+        // Only `blah1:` should trigger
+        asm!("blah1: 2bar: nop"); //~ ERROR do not use named labels
+
+        // Duplicate labels
+        asm!("def: def: nop"); //~ ERROR do not use named labels
+        asm!("def: nop\ndef: nop"); //~ ERROR do not use named labels
+        asm!("def: nop; def: nop"); //~ ERROR do not use named labels
+
+        // Trying to break parsing
+        asm!(":");
+        asm!("\n:\n");
+        asm!("::::");
+
+        // 0x3A is a ':'
+        asm!("fooo\u{003A} nop"); //~ ERROR do not use named labels
+        asm!("foooo\x3A nop"); //~ ERROR do not use named labels
+
+        // 0x0A is a newline
+        asm!("fooooo:\u{000A} nop"); //~ ERROR do not use named labels
+        asm!("foooooo:\x0A nop"); //~ ERROR do not use named labels
+
+        // Intentionally breaking span finding
+        // equivalent to "ABC: nop"
+        asm!("\x41\x42\x43\x3A\x20\x6E\x6F\x70"); //~ ERROR do not use named labels
+    }
+}
+
+// Don't trigger on global asm
+global_asm!("aaaaaaaa: nop");
diff --git a/src/test/ui/asm/named_asm_labels.stderr b/src/test/ui/asm/named_asm_labels.stderr
new file mode 100644
index 0000000000000..62e4eef1992d6
--- /dev/null
+++ b/src/test/ui/asm/named_asm_labels.stderr
@@ -0,0 +1,300 @@
+error: do not use named labels in inline assembly
+  --> $DIR/named_asm_labels.rs:6:15
+   |
+LL |         asm!("bar: nop");
+   |               ^^^
+   |
+   = note: `#[deny(named_asm_labels)]` on by default
+   = help: Only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
+
+error: do not use named labels in inline assembly
+  --> $DIR/named_asm_labels.rs:9:15
+   |
+LL |         asm!("abcd:");
+   |               ^^^^
+   |
+   = help: Only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
+
+error: do not use named labels in inline assembly
+  --> $DIR/named_asm_labels.rs:12:15
+   |
+LL |         asm!("foo: bar1: nop");
+   |               ^^^
+   |
+   = help: Only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
+
+error: do not use named labels in inline assembly
+  --> $DIR/named_asm_labels.rs:12:20
+   |
+LL |         asm!("foo: bar1: nop");
+   |                    ^^^^
+   |
+   = help: Only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
+
+error: do not use named labels in inline assembly
+  --> $DIR/named_asm_labels.rs:17:15
+   |
+LL |         asm!("foo1: nop", "nop");
+   |               ^^^^
+   |
+   = help: Only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
+
+error: do not use named labels in inline assembly
+  --> $DIR/named_asm_labels.rs:18:15
+   |
+LL |         asm!("foo2: foo3: nop", "nop");
+   |               ^^^^
+   |
+   = help: Only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
+
+error: do not use named labels in inline assembly
+  --> $DIR/named_asm_labels.rs:18:21
+   |
+LL |         asm!("foo2: foo3: nop", "nop");
+   |                     ^^^^
+   |
+   = help: Only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
+
+error: do not use named labels in inline assembly
+  --> $DIR/named_asm_labels.rs:21:22
+   |
+LL |         asm!("nop", "foo4: nop");
+   |                      ^^^^
+   |
+   = help: Only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
+
+error: do not use named labels in inline assembly
+  --> $DIR/named_asm_labels.rs:22:15
+   |
+LL |         asm!("foo5: nop", "foo6: nop");
+   |               ^^^^
+   |
+   = help: Only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
+
+error: do not use named labels in inline assembly
+  --> $DIR/named_asm_labels.rs:22:28
+   |
+LL |         asm!("foo5: nop", "foo6: nop");
+   |                            ^^^^
+   |
+   = help: Only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
+
+error: do not use named labels in inline assembly
+  --> $DIR/named_asm_labels.rs:27:15
+   |
+LL |         asm!("foo7: nop; foo8: nop");
+   |               ^^^^
+   |
+   = help: Only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
+
+error: do not use named labels in inline assembly
+  --> $DIR/named_asm_labels.rs:27:26
+   |
+LL |         asm!("foo7: nop; foo8: nop");
+   |                          ^^^^
+   |
+   = help: Only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
+
+error: do not use named labels in inline assembly
+  --> $DIR/named_asm_labels.rs:30:15
+   |
+LL |         asm!("foo9: nop; nop");
+   |               ^^^^
+   |
+   = help: Only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
+
+error: do not use named labels in inline assembly
+  --> $DIR/named_asm_labels.rs:31:20
+   |
+LL |         asm!("nop; foo10: nop");
+   |                    ^^^^^
+   |
+   = help: Only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
+
+error: do not use named labels in inline assembly
+  --> $DIR/named_asm_labels.rs:34:15
+   |
+LL |         asm!("bar2: nop\n bar3: nop");
+   |               ^^^^
+   |
+   = help: Only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
+
+error: do not use named labels in inline assembly
+  --> $DIR/named_asm_labels.rs:34:27
+   |
+LL |         asm!("bar2: nop\n bar3: nop");
+   |                           ^^^^
+   |
+   = help: Only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
+
+error: do not use named labels in inline assembly
+  --> $DIR/named_asm_labels.rs:37:15
+   |
+LL |         asm!("bar4: nop\n nop");
+   |               ^^^^
+   |
+   = help: Only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
+
+error: do not use named labels in inline assembly
+  --> $DIR/named_asm_labels.rs:38:21
+   |
+LL |         asm!("nop\n bar5: nop");
+   |                     ^^^^
+   |
+   = help: Only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
+
+error: do not use named labels in inline assembly
+  --> $DIR/named_asm_labels.rs:39:21
+   |
+LL |         asm!("nop\n bar6: bar7: nop");
+   |                     ^^^^
+   |
+   = help: Only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
+
+error: do not use named labels in inline assembly
+  --> $DIR/named_asm_labels.rs:39:27
+   |
+LL |         asm!("nop\n bar6: bar7: nop");
+   |                           ^^^^
+   |
+   = help: Only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
+
+error: do not use named labels in inline assembly
+  --> $DIR/named_asm_labels.rs:46:13
+   |
+LL |             blah2: nop
+   |             ^^^^^
+   |
+   = help: Only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
+
+error: do not use named labels in inline assembly
+  --> $DIR/named_asm_labels.rs:47:13
+   |
+LL |             blah3: nop
+   |             ^^^^^
+   |
+   = help: Only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
+
+error: do not use named labels in inline assembly
+  --> $DIR/named_asm_labels.rs:55:19
+   |
+LL |             nop ; blah4: nop
+   |                   ^^^^^
+   |
+   = help: Only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
+
+error: do not use named labels in inline assembly
+  --> $DIR/named_asm_labels.rs:65:21
+   |
+LL |         asm!("1bar: blah: nop");
+   |                     ^^^^
+   |
+   = help: Only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
+
+error: do not use named labels in inline assembly
+  --> $DIR/named_asm_labels.rs:68:15
+   |
+LL |         asm!("blah1: 2bar: nop");
+   |               ^^^^^
+   |
+   = help: Only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
+
+error: do not use named labels in inline assembly
+  --> $DIR/named_asm_labels.rs:71:15
+   |
+LL |         asm!("def: def: nop");
+   |               ^^^
+   |
+   = help: Only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
+
+error: do not use named labels in inline assembly
+  --> $DIR/named_asm_labels.rs:72:15
+   |
+LL |         asm!("def: nop\ndef: nop");
+   |               ^^^
+   |
+   = help: Only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
+
+error: do not use named labels in inline assembly
+  --> $DIR/named_asm_labels.rs:73:15
+   |
+LL |         asm!("def: nop; def: nop");
+   |               ^^^
+   |
+   = help: Only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
+
+error: do not use named labels in inline assembly
+  --> $DIR/named_asm_labels.rs:81:15
+   |
+LL |         asm!("fooo\u{003A} nop");
+   |               ^^^^^^^^^^^^^^^^
+   |
+   = help: Only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
+
+error: do not use named labels in inline assembly
+  --> $DIR/named_asm_labels.rs:82:15
+   |
+LL |         asm!("foooo\x3A nop");
+   |               ^^^^^^^^^^^^^
+   |
+   = help: Only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
+
+error: do not use named labels in inline assembly
+  --> $DIR/named_asm_labels.rs:85:15
+   |
+LL |         asm!("fooooo:\u{000A} nop");
+   |               ^^^^^^
+   |
+   = help: Only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
+
+error: do not use named labels in inline assembly
+  --> $DIR/named_asm_labels.rs:86:15
+   |
+LL |         asm!("foooooo:\x0A nop");
+   |               ^^^^^^^
+   |
+   = help: Only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
+
+error: do not use named labels in inline assembly
+  --> $DIR/named_asm_labels.rs:90:14
+   |
+LL |         asm!("\x41\x42\x43\x3A\x20\x6E\x6F\x70");
+   |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = help: Only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
+
+error: aborting due to 33 previous errors
+

From 1e1f2194b69d27b77d7ee5a56c388e431d9e8bab Mon Sep 17 00:00:00 2001
From: asquared31415 <34665709+asquared31415@users.noreply.github.com>
Date: Wed, 21 Jul 2021 16:10:22 -0400
Subject: [PATCH 2/8] Comment tweaks

---
 compiler/rustc_builtin_macros/src/asm.rs | 1 +
 compiler/rustc_lint_defs/src/builtin.rs  | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/compiler/rustc_builtin_macros/src/asm.rs b/compiler/rustc_builtin_macros/src/asm.rs
index 9a82561db5e65..1dbb3b45b4e4e 100644
--- a/compiler/rustc_builtin_macros/src/asm.rs
+++ b/compiler/rustc_builtin_macros/src/asm.rs
@@ -473,6 +473,7 @@ fn expand_preparsed_asm(
             }
         }
 
+        // Lint against the use of named labels in inline `asm!` but not `global_asm!`
         if is_local_asm {
             let find_label_span = |needle: &str| -> Option<Span> {
                 if let Some(snippet) = &template_snippet {
diff --git a/compiler/rustc_lint_defs/src/builtin.rs b/compiler/rustc_lint_defs/src/builtin.rs
index 88288e1a6a63f..641ae93fdb355 100644
--- a/compiler/rustc_lint_defs/src/builtin.rs
+++ b/compiler/rustc_lint_defs/src/builtin.rs
@@ -2488,7 +2488,7 @@ declare_lint! {
     ///
     /// ### Explanation
     ///
-    /// LLVM's assembler is allowed to duplicate inline assembly blocks for any
+    /// LLVM is allowed to duplicate inline assembly blocks for any
     /// reason, for example when it is in a function that gets inlined. Because
     /// of this, GNU assembler [local labels] *must* be used instead of labels
     /// with a name. Using named labels might cause assembler or linker errors.

From 1f8f8631b0d41fefb855999ddf0fcaf6757bf11b Mon Sep 17 00:00:00 2001
From: asquared31415 <34665709+asquared31415@users.noreply.github.com>
Date: Wed, 21 Jul 2021 16:10:45 -0400
Subject: [PATCH 3/8] Revert accidental removal of attributes

---
 compiler/rustc_lint_defs/src/lib.rs | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/compiler/rustc_lint_defs/src/lib.rs b/compiler/rustc_lint_defs/src/lib.rs
index 038e5055a7b15..f89d531b5ef5c 100644
--- a/compiler/rustc_lint_defs/src/lib.rs
+++ b/compiler/rustc_lint_defs/src/lib.rs
@@ -274,7 +274,7 @@ impl<HCX> ToStableHashKey<HCX> for LintId {
 }
 
 // Duplicated from rustc_session::config::ExternDepSpec to avoid cyclic dependency
-#[derive(PartialEq)]
+#[derive(PartialEq, Debug)]
 pub enum ExternDepSpec {
     Json(Json),
     Raw(String),
@@ -282,7 +282,7 @@ pub enum ExternDepSpec {
 
 // This could be a closure, but then implementing derive trait
 // becomes hacky (and it gets allocated).
-#[derive(PartialEq)]
+#[derive(PartialEq, Debug)]
 pub enum BuiltinLintDiagnostics {
     Normal,
     BareTraitObject(Span, /* is_global */ bool),

From 6f45f62ded05f659eb436edd25c3151684b6e0f0 Mon Sep 17 00:00:00 2001
From: asquared31415 <34665709+asquared31415@users.noreply.github.com>
Date: Wed, 21 Jul 2021 17:47:37 -0400
Subject: [PATCH 4/8] Proper characters in labels, ignore comments

---
 compiler/rustc_builtin_macros/src/asm.rs | 15 ++++++----
 src/test/ui/asm/named_asm_labels.rs      | 20 +++++++++++--
 src/test/ui/asm/named_asm_labels.stderr  | 36 ++++++++++++------------
 3 files changed, 46 insertions(+), 25 deletions(-)

diff --git a/compiler/rustc_builtin_macros/src/asm.rs b/compiler/rustc_builtin_macros/src/asm.rs
index 1dbb3b45b4e4e..79f3554fdc8d5 100644
--- a/compiler/rustc_builtin_macros/src/asm.rs
+++ b/compiler/rustc_builtin_macros/src/asm.rs
@@ -495,16 +495,21 @@ fn expand_preparsed_asm(
             // A semicolon might not actually be specified as a separator for all targets, but it seems like LLVM accepts it always
             let statements = template_str.split(|c| matches!(c, '\n' | ';'));
             for statement in statements {
+                // If there's a comment, trim it from the statement
+                let statement = statement.find("//").map_or(statement, |idx| &statement[..idx]);
                 let mut start_idx = 0;
                 for (idx, _) in statement.match_indices(':') {
                     let possible_label = statement[start_idx..idx].trim();
                     let mut chars = possible_label.chars();
                     if let Some(c) = chars.next() {
-                        // A label starts with an alphabetic character and continues with alphanumeric characters
-                        if c.is_alphabetic() {
-                            if chars.all(char::is_alphanumeric) {
-                                found_labels.push(possible_label);
-                            }
+                        // A label starts with an alphabetic character or . or _ and continues with alphanumeric characters, _, or $
+                        if (c.is_alphabetic() || matches!(c, '.' | '_'))
+                            && chars.all(|c| c.is_alphanumeric() || matches!(c, '_' | '$'))
+                        {
+                            found_labels.push(possible_label);
+                        } else {
+                            // If we encounter a non-label, there cannot be any further labels, so stop checking
+                            break;
                         }
                     }
 
diff --git a/src/test/ui/asm/named_asm_labels.rs b/src/test/ui/asm/named_asm_labels.rs
index ba277b7aad66f..feabafdefb77a 100644
--- a/src/test/ui/asm/named_asm_labels.rs
+++ b/src/test/ui/asm/named_asm_labels.rs
@@ -61,8 +61,9 @@ fn main() {
         // should not trigger lint, but may be invalid asm
         asm!("ab cd: nop");
 
-        // Only `blah:` should trigger
-        asm!("1bar: blah: nop"); //~ ERROR do not use named labels
+        // `blah:` does not trigger because labels need to be at the start
+        // of the statement, and there was already a non-label
+        asm!("1bar: blah: nop");
 
         // Only `blah1:` should trigger
         asm!("blah1: 2bar: nop"); //~ ERROR do not use named labels
@@ -88,6 +89,21 @@ fn main() {
         // Intentionally breaking span finding
         // equivalent to "ABC: nop"
         asm!("\x41\x42\x43\x3A\x20\x6E\x6F\x70"); //~ ERROR do not use named labels
+
+        // Non-label colons - should pass
+        // (most of these are stolen from other places)
+        asm!("{:l}", in(reg) 0i64);
+        asm!("{:e}", in(reg) 0f32);
+        asm!("mov rax, qword ptr fs:[0]");
+
+        // Comments
+        asm!(
+            r"
+            ab: nop // ab: does foo
+            // cd: nop
+            "
+        );
+        //~^^^^ ERROR do not use named labels
     }
 }
 
diff --git a/src/test/ui/asm/named_asm_labels.stderr b/src/test/ui/asm/named_asm_labels.stderr
index 62e4eef1992d6..b3f9b93dc9d9c 100644
--- a/src/test/ui/asm/named_asm_labels.stderr
+++ b/src/test/ui/asm/named_asm_labels.stderr
@@ -207,16 +207,7 @@ LL |             nop ; blah4: nop
    = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:65:21
-   |
-LL |         asm!("1bar: blah: nop");
-   |                     ^^^^
-   |
-   = help: Only GAS local labels of the form `N:` where N is a number may be used in inline asm
-   = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
-
-error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:68:15
+  --> $DIR/named_asm_labels.rs:69:15
    |
 LL |         asm!("blah1: 2bar: nop");
    |               ^^^^^
@@ -225,7 +216,7 @@ LL |         asm!("blah1: 2bar: nop");
    = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:71:15
+  --> $DIR/named_asm_labels.rs:72:15
    |
 LL |         asm!("def: def: nop");
    |               ^^^
@@ -234,7 +225,7 @@ LL |         asm!("def: def: nop");
    = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:72:15
+  --> $DIR/named_asm_labels.rs:73:15
    |
 LL |         asm!("def: nop\ndef: nop");
    |               ^^^
@@ -243,7 +234,7 @@ LL |         asm!("def: nop\ndef: nop");
    = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:73:15
+  --> $DIR/named_asm_labels.rs:74:15
    |
 LL |         asm!("def: nop; def: nop");
    |               ^^^
@@ -252,7 +243,7 @@ LL |         asm!("def: nop; def: nop");
    = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:81:15
+  --> $DIR/named_asm_labels.rs:82:15
    |
 LL |         asm!("fooo\u{003A} nop");
    |               ^^^^^^^^^^^^^^^^
@@ -261,7 +252,7 @@ LL |         asm!("fooo\u{003A} nop");
    = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:82:15
+  --> $DIR/named_asm_labels.rs:83:15
    |
 LL |         asm!("foooo\x3A nop");
    |               ^^^^^^^^^^^^^
@@ -270,7 +261,7 @@ LL |         asm!("foooo\x3A nop");
    = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:85:15
+  --> $DIR/named_asm_labels.rs:86:15
    |
 LL |         asm!("fooooo:\u{000A} nop");
    |               ^^^^^^
@@ -279,7 +270,7 @@ LL |         asm!("fooooo:\u{000A} nop");
    = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:86:15
+  --> $DIR/named_asm_labels.rs:87:15
    |
 LL |         asm!("foooooo:\x0A nop");
    |               ^^^^^^^
@@ -288,7 +279,7 @@ LL |         asm!("foooooo:\x0A nop");
    = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:90:14
+  --> $DIR/named_asm_labels.rs:91:14
    |
 LL |         asm!("\x41\x42\x43\x3A\x20\x6E\x6F\x70");
    |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -296,5 +287,14 @@ LL |         asm!("\x41\x42\x43\x3A\x20\x6E\x6F\x70");
    = help: Only GAS local labels of the form `N:` where N is a number may be used in inline asm
    = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
+error: do not use named labels in inline assembly
+  --> $DIR/named_asm_labels.rs:102:13
+   |
+LL |             ab: nop // ab: does foo
+   |             ^^
+   |
+   = help: Only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
+
 error: aborting due to 33 previous errors
 

From 8e7bbc9e9da091f4e7d9f846f0f264420b8a6f0e Mon Sep 17 00:00:00 2001
From: asquared31415 <34665709+asquared31415@users.noreply.github.com>
Date: Wed, 21 Jul 2021 18:01:05 -0400
Subject: [PATCH 5/8] Handle leading colons properly

---
 compiler/rustc_builtin_macros/src/asm.rs |  3 ++
 src/test/ui/asm/named_asm_labels.rs      | 10 ++++
 src/test/ui/asm/named_asm_labels.stderr  | 66 ++++++++++++------------
 3 files changed, 46 insertions(+), 33 deletions(-)

diff --git a/compiler/rustc_builtin_macros/src/asm.rs b/compiler/rustc_builtin_macros/src/asm.rs
index 79f3554fdc8d5..35dcd08951baa 100644
--- a/compiler/rustc_builtin_macros/src/asm.rs
+++ b/compiler/rustc_builtin_macros/src/asm.rs
@@ -511,6 +511,9 @@ fn expand_preparsed_asm(
                             // If we encounter a non-label, there cannot be any further labels, so stop checking
                             break;
                         }
+                    } else {
+                        // Empty string means a leading ':' in this section, which is not a label
+                        break;
                     }
 
                     start_idx = idx + 1;
diff --git a/src/test/ui/asm/named_asm_labels.rs b/src/test/ui/asm/named_asm_labels.rs
index feabafdefb77a..db7d9a17b051a 100644
--- a/src/test/ui/asm/named_asm_labels.rs
+++ b/src/test/ui/asm/named_asm_labels.rs
@@ -1,5 +1,10 @@
+// only-x86_64
+
 #![feature(asm, global_asm)]
 
+#[no_mangle]
+pub static FOO: usize = 42;
+
 fn main() {
     unsafe {
         // Basic usage
@@ -104,6 +109,11 @@ fn main() {
             "
         );
         //~^^^^ ERROR do not use named labels
+
+        // Tests usage of colons in non-label positions
+        asm!(":lo12:FOO"); // this is apparently valid aarch64
+        // is there an example that is valid x86 for this test?
+        asm!(":bbb nop");
     }
 }
 
diff --git a/src/test/ui/asm/named_asm_labels.stderr b/src/test/ui/asm/named_asm_labels.stderr
index b3f9b93dc9d9c..42641db603cf0 100644
--- a/src/test/ui/asm/named_asm_labels.stderr
+++ b/src/test/ui/asm/named_asm_labels.stderr
@@ -1,5 +1,5 @@
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:6:15
+  --> $DIR/named_asm_labels.rs:11:15
    |
 LL |         asm!("bar: nop");
    |               ^^^
@@ -9,7 +9,7 @@ LL |         asm!("bar: nop");
    = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:9:15
+  --> $DIR/named_asm_labels.rs:14:15
    |
 LL |         asm!("abcd:");
    |               ^^^^
@@ -18,7 +18,7 @@ LL |         asm!("abcd:");
    = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:12:15
+  --> $DIR/named_asm_labels.rs:17:15
    |
 LL |         asm!("foo: bar1: nop");
    |               ^^^
@@ -27,7 +27,7 @@ LL |         asm!("foo: bar1: nop");
    = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:12:20
+  --> $DIR/named_asm_labels.rs:17:20
    |
 LL |         asm!("foo: bar1: nop");
    |                    ^^^^
@@ -36,7 +36,7 @@ LL |         asm!("foo: bar1: nop");
    = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:17:15
+  --> $DIR/named_asm_labels.rs:22:15
    |
 LL |         asm!("foo1: nop", "nop");
    |               ^^^^
@@ -45,7 +45,7 @@ LL |         asm!("foo1: nop", "nop");
    = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:18:15
+  --> $DIR/named_asm_labels.rs:23:15
    |
 LL |         asm!("foo2: foo3: nop", "nop");
    |               ^^^^
@@ -54,7 +54,7 @@ LL |         asm!("foo2: foo3: nop", "nop");
    = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:18:21
+  --> $DIR/named_asm_labels.rs:23:21
    |
 LL |         asm!("foo2: foo3: nop", "nop");
    |                     ^^^^
@@ -63,7 +63,7 @@ LL |         asm!("foo2: foo3: nop", "nop");
    = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:21:22
+  --> $DIR/named_asm_labels.rs:26:22
    |
 LL |         asm!("nop", "foo4: nop");
    |                      ^^^^
@@ -72,7 +72,7 @@ LL |         asm!("nop", "foo4: nop");
    = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:22:15
+  --> $DIR/named_asm_labels.rs:27:15
    |
 LL |         asm!("foo5: nop", "foo6: nop");
    |               ^^^^
@@ -81,7 +81,7 @@ LL |         asm!("foo5: nop", "foo6: nop");
    = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:22:28
+  --> $DIR/named_asm_labels.rs:27:28
    |
 LL |         asm!("foo5: nop", "foo6: nop");
    |                            ^^^^
@@ -90,7 +90,7 @@ LL |         asm!("foo5: nop", "foo6: nop");
    = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:27:15
+  --> $DIR/named_asm_labels.rs:32:15
    |
 LL |         asm!("foo7: nop; foo8: nop");
    |               ^^^^
@@ -99,7 +99,7 @@ LL |         asm!("foo7: nop; foo8: nop");
    = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:27:26
+  --> $DIR/named_asm_labels.rs:32:26
    |
 LL |         asm!("foo7: nop; foo8: nop");
    |                          ^^^^
@@ -108,7 +108,7 @@ LL |         asm!("foo7: nop; foo8: nop");
    = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:30:15
+  --> $DIR/named_asm_labels.rs:35:15
    |
 LL |         asm!("foo9: nop; nop");
    |               ^^^^
@@ -117,7 +117,7 @@ LL |         asm!("foo9: nop; nop");
    = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:31:20
+  --> $DIR/named_asm_labels.rs:36:20
    |
 LL |         asm!("nop; foo10: nop");
    |                    ^^^^^
@@ -126,7 +126,7 @@ LL |         asm!("nop; foo10: nop");
    = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:34:15
+  --> $DIR/named_asm_labels.rs:39:15
    |
 LL |         asm!("bar2: nop\n bar3: nop");
    |               ^^^^
@@ -135,7 +135,7 @@ LL |         asm!("bar2: nop\n bar3: nop");
    = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:34:27
+  --> $DIR/named_asm_labels.rs:39:27
    |
 LL |         asm!("bar2: nop\n bar3: nop");
    |                           ^^^^
@@ -144,7 +144,7 @@ LL |         asm!("bar2: nop\n bar3: nop");
    = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:37:15
+  --> $DIR/named_asm_labels.rs:42:15
    |
 LL |         asm!("bar4: nop\n nop");
    |               ^^^^
@@ -153,7 +153,7 @@ LL |         asm!("bar4: nop\n nop");
    = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:38:21
+  --> $DIR/named_asm_labels.rs:43:21
    |
 LL |         asm!("nop\n bar5: nop");
    |                     ^^^^
@@ -162,7 +162,7 @@ LL |         asm!("nop\n bar5: nop");
    = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:39:21
+  --> $DIR/named_asm_labels.rs:44:21
    |
 LL |         asm!("nop\n bar6: bar7: nop");
    |                     ^^^^
@@ -171,7 +171,7 @@ LL |         asm!("nop\n bar6: bar7: nop");
    = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:39:27
+  --> $DIR/named_asm_labels.rs:44:27
    |
 LL |         asm!("nop\n bar6: bar7: nop");
    |                           ^^^^
@@ -180,7 +180,7 @@ LL |         asm!("nop\n bar6: bar7: nop");
    = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:46:13
+  --> $DIR/named_asm_labels.rs:51:13
    |
 LL |             blah2: nop
    |             ^^^^^
@@ -189,7 +189,7 @@ LL |             blah2: nop
    = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:47:13
+  --> $DIR/named_asm_labels.rs:52:13
    |
 LL |             blah3: nop
    |             ^^^^^
@@ -198,7 +198,7 @@ LL |             blah3: nop
    = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:55:19
+  --> $DIR/named_asm_labels.rs:60:19
    |
 LL |             nop ; blah4: nop
    |                   ^^^^^
@@ -207,7 +207,7 @@ LL |             nop ; blah4: nop
    = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:69:15
+  --> $DIR/named_asm_labels.rs:74:15
    |
 LL |         asm!("blah1: 2bar: nop");
    |               ^^^^^
@@ -216,7 +216,7 @@ LL |         asm!("blah1: 2bar: nop");
    = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:72:15
+  --> $DIR/named_asm_labels.rs:77:15
    |
 LL |         asm!("def: def: nop");
    |               ^^^
@@ -225,7 +225,7 @@ LL |         asm!("def: def: nop");
    = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:73:15
+  --> $DIR/named_asm_labels.rs:78:15
    |
 LL |         asm!("def: nop\ndef: nop");
    |               ^^^
@@ -234,7 +234,7 @@ LL |         asm!("def: nop\ndef: nop");
    = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:74:15
+  --> $DIR/named_asm_labels.rs:79:15
    |
 LL |         asm!("def: nop; def: nop");
    |               ^^^
@@ -243,7 +243,7 @@ LL |         asm!("def: nop; def: nop");
    = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:82:15
+  --> $DIR/named_asm_labels.rs:87:15
    |
 LL |         asm!("fooo\u{003A} nop");
    |               ^^^^^^^^^^^^^^^^
@@ -252,7 +252,7 @@ LL |         asm!("fooo\u{003A} nop");
    = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:83:15
+  --> $DIR/named_asm_labels.rs:88:15
    |
 LL |         asm!("foooo\x3A nop");
    |               ^^^^^^^^^^^^^
@@ -261,7 +261,7 @@ LL |         asm!("foooo\x3A nop");
    = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:86:15
+  --> $DIR/named_asm_labels.rs:91:15
    |
 LL |         asm!("fooooo:\u{000A} nop");
    |               ^^^^^^
@@ -270,7 +270,7 @@ LL |         asm!("fooooo:\u{000A} nop");
    = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:87:15
+  --> $DIR/named_asm_labels.rs:92:15
    |
 LL |         asm!("foooooo:\x0A nop");
    |               ^^^^^^^
@@ -279,7 +279,7 @@ LL |         asm!("foooooo:\x0A nop");
    = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:91:14
+  --> $DIR/named_asm_labels.rs:96:14
    |
 LL |         asm!("\x41\x42\x43\x3A\x20\x6E\x6F\x70");
    |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -288,7 +288,7 @@ LL |         asm!("\x41\x42\x43\x3A\x20\x6E\x6F\x70");
    = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:102:13
+  --> $DIR/named_asm_labels.rs:107:13
    |
 LL |             ab: nop // ab: does foo
    |             ^^

From 1ae19b69e820a4497a15a8c70a2e57bea3785405 Mon Sep 17 00:00:00 2001
From: asquared31415 <34665709+asquared31415@users.noreply.github.com>
Date: Thu, 22 Jul 2021 19:26:16 -0400
Subject: [PATCH 6/8] Fix lint capitalization and ignoring, test with
 include_str

---
 compiler/rustc_builtin_macros/src/asm.rs      |   6 +-
 compiler/rustc_lint/src/context.rs            |   2 +-
 compiler/rustc_lint_defs/src/builtin.rs       |   1 +
 src/test/codegen/asm-sanitize-llvm.rs         |   1 +
 ...amed_asm_labels.rs => named-asm-labels.rs} |  14 ++
 src/test/ui/asm/named-asm-labels.s            |   5 +
 ..._labels.stderr => named-asm-labels.stderr} | 223 ++++++++++--------
 7 files changed, 148 insertions(+), 104 deletions(-)
 rename src/test/ui/asm/{named_asm_labels.rs => named-asm-labels.rs} (90%)
 create mode 100644 src/test/ui/asm/named-asm-labels.s
 rename src/test/ui/asm/{named_asm_labels.stderr => named-asm-labels.stderr} (56%)

diff --git a/compiler/rustc_builtin_macros/src/asm.rs b/compiler/rustc_builtin_macros/src/asm.rs
index 35dcd08951baa..a1119916dc1fe 100644
--- a/compiler/rustc_builtin_macros/src/asm.rs
+++ b/compiler/rustc_builtin_macros/src/asm.rs
@@ -530,17 +530,17 @@ fn expand_preparsed_asm(
                             span,
                             ecx.current_expansion.lint_node_id,
                             "do not use named labels in inline assembly",
-                            BuiltinLintDiagnostics::NamedAsmLabel("Only GAS local labels of the form `N:` where N is a number may be used in inline asm".to_string()),
+                            BuiltinLintDiagnostics::NamedAsmLabel("only GAS local labels of the form `N:` where N is a number may be used in inline asm".to_string()),
                         );
                     }
                 } else {
                     // If there were labels but we couldn't find a span, combine the warnings and use the template span
                     ecx.parse_sess().buffer_lint_with_diagnostic(
                         lint::builtin::NAMED_ASM_LABELS,
-                        template_span,
+                        template_sp,
                         ecx.current_expansion.lint_node_id,
                         "do not use named labels in inline assembly",
-                        BuiltinLintDiagnostics::NamedAsmLabel("Only GAS local labels of the form `N:` where N is a number may be used in inline asm".to_string()),
+                        BuiltinLintDiagnostics::NamedAsmLabel("only GAS local labels of the form `N:` where N is a number may be used in inline asm".to_string()),
                     );
                 }
             }
diff --git a/compiler/rustc_lint/src/context.rs b/compiler/rustc_lint/src/context.rs
index 60d9e8e0e71f9..47c6e904cd7e5 100644
--- a/compiler/rustc_lint/src/context.rs
+++ b/compiler/rustc_lint/src/context.rs
@@ -760,7 +760,7 @@ pub trait LintContext: Sized {
                 }
                 BuiltinLintDiagnostics::NamedAsmLabel(help) => {
                     db.help(&help);
-                    db.note("See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information");
+                    db.note("see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information");
                 }
             }
             // Rewrap `db`, and pass control to the user.
diff --git a/compiler/rustc_lint_defs/src/builtin.rs b/compiler/rustc_lint_defs/src/builtin.rs
index 641ae93fdb355..df17ec576e86b 100644
--- a/compiler/rustc_lint_defs/src/builtin.rs
+++ b/compiler/rustc_lint_defs/src/builtin.rs
@@ -2990,6 +2990,7 @@ declare_lint_pass! {
         INLINE_NO_SANITIZE,
         BAD_ASM_STYLE,
         ASM_SUB_REGISTER,
+        NAMED_ASM_LABELS,
         UNSAFE_OP_IN_UNSAFE_FN,
         INCOMPLETE_INCLUDE,
         CENUM_IMPL_DROP_CAST,
diff --git a/src/test/codegen/asm-sanitize-llvm.rs b/src/test/codegen/asm-sanitize-llvm.rs
index 135177016bf9a..6dcacd08cacdd 100644
--- a/src/test/codegen/asm-sanitize-llvm.rs
+++ b/src/test/codegen/asm-sanitize-llvm.rs
@@ -7,6 +7,7 @@
 #![no_core]
 #![feature(no_core, lang_items, rustc_attrs)]
 #![crate_type = "rlib"]
+#![allow(named_asm_labels)]
 
 #[rustc_builtin_macro]
 macro_rules! asm {
diff --git a/src/test/ui/asm/named_asm_labels.rs b/src/test/ui/asm/named-asm-labels.rs
similarity index 90%
rename from src/test/ui/asm/named_asm_labels.rs
rename to src/test/ui/asm/named-asm-labels.rs
index db7d9a17b051a..2a2d6e5cc781f 100644
--- a/src/test/ui/asm/named_asm_labels.rs
+++ b/src/test/ui/asm/named-asm-labels.rs
@@ -114,6 +114,20 @@ fn main() {
         asm!(":lo12:FOO"); // this is apparently valid aarch64
         // is there an example that is valid x86 for this test?
         asm!(":bbb nop");
+
+        // Test include_str in asm
+        asm!(include_str!("named-asm-labels.s")); //~ ERROR do not use named labels
+
+        // Test allowing or warning on the lint instead
+        #[allow(named_asm_labels)]
+        {
+            asm!("allowed: nop"); // Should not emit anything
+        }
+
+        #[warn(named_asm_labels)]
+        {
+            asm!("warned: nop"); //~ WARNING do not use named labels
+        }
     }
 }
 
diff --git a/src/test/ui/asm/named-asm-labels.s b/src/test/ui/asm/named-asm-labels.s
new file mode 100644
index 0000000000000..071356d75a0c3
--- /dev/null
+++ b/src/test/ui/asm/named-asm-labels.s
@@ -0,0 +1,5 @@
+lab1: nop
+// do more things
+lab2: nop // does bar
+// a: b
+lab3: nop; lab4: nop
diff --git a/src/test/ui/asm/named_asm_labels.stderr b/src/test/ui/asm/named-asm-labels.stderr
similarity index 56%
rename from src/test/ui/asm/named_asm_labels.stderr
rename to src/test/ui/asm/named-asm-labels.stderr
index 42641db603cf0..2e1258d127d3e 100644
--- a/src/test/ui/asm/named_asm_labels.stderr
+++ b/src/test/ui/asm/named-asm-labels.stderr
@@ -1,300 +1,323 @@
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:11:15
+  --> $DIR/named-asm-labels.rs:11:15
    |
 LL |         asm!("bar: nop");
    |               ^^^
    |
    = note: `#[deny(named_asm_labels)]` on by default
-   = help: Only GAS local labels of the form `N:` where N is a number may be used in inline asm
-   = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
+   = help: only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:14:15
+  --> $DIR/named-asm-labels.rs:14:15
    |
 LL |         asm!("abcd:");
    |               ^^^^
    |
-   = help: Only GAS local labels of the form `N:` where N is a number may be used in inline asm
-   = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
+   = help: only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:17:15
+  --> $DIR/named-asm-labels.rs:17:15
    |
 LL |         asm!("foo: bar1: nop");
    |               ^^^
    |
-   = help: Only GAS local labels of the form `N:` where N is a number may be used in inline asm
-   = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
+   = help: only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:17:20
+  --> $DIR/named-asm-labels.rs:17:20
    |
 LL |         asm!("foo: bar1: nop");
    |                    ^^^^
    |
-   = help: Only GAS local labels of the form `N:` where N is a number may be used in inline asm
-   = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
+   = help: only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:22:15
+  --> $DIR/named-asm-labels.rs:22:15
    |
 LL |         asm!("foo1: nop", "nop");
    |               ^^^^
    |
-   = help: Only GAS local labels of the form `N:` where N is a number may be used in inline asm
-   = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
+   = help: only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:23:15
+  --> $DIR/named-asm-labels.rs:23:15
    |
 LL |         asm!("foo2: foo3: nop", "nop");
    |               ^^^^
    |
-   = help: Only GAS local labels of the form `N:` where N is a number may be used in inline asm
-   = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
+   = help: only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:23:21
+  --> $DIR/named-asm-labels.rs:23:21
    |
 LL |         asm!("foo2: foo3: nop", "nop");
    |                     ^^^^
    |
-   = help: Only GAS local labels of the form `N:` where N is a number may be used in inline asm
-   = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
+   = help: only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:26:22
+  --> $DIR/named-asm-labels.rs:26:22
    |
 LL |         asm!("nop", "foo4: nop");
    |                      ^^^^
    |
-   = help: Only GAS local labels of the form `N:` where N is a number may be used in inline asm
-   = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
+   = help: only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:27:15
+  --> $DIR/named-asm-labels.rs:27:15
    |
 LL |         asm!("foo5: nop", "foo6: nop");
    |               ^^^^
    |
-   = help: Only GAS local labels of the form `N:` where N is a number may be used in inline asm
-   = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
+   = help: only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:27:28
+  --> $DIR/named-asm-labels.rs:27:28
    |
 LL |         asm!("foo5: nop", "foo6: nop");
    |                            ^^^^
    |
-   = help: Only GAS local labels of the form `N:` where N is a number may be used in inline asm
-   = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
+   = help: only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:32:15
+  --> $DIR/named-asm-labels.rs:32:15
    |
 LL |         asm!("foo7: nop; foo8: nop");
    |               ^^^^
    |
-   = help: Only GAS local labels of the form `N:` where N is a number may be used in inline asm
-   = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
+   = help: only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:32:26
+  --> $DIR/named-asm-labels.rs:32:26
    |
 LL |         asm!("foo7: nop; foo8: nop");
    |                          ^^^^
    |
-   = help: Only GAS local labels of the form `N:` where N is a number may be used in inline asm
-   = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
+   = help: only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:35:15
+  --> $DIR/named-asm-labels.rs:35:15
    |
 LL |         asm!("foo9: nop; nop");
    |               ^^^^
    |
-   = help: Only GAS local labels of the form `N:` where N is a number may be used in inline asm
-   = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
+   = help: only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:36:20
+  --> $DIR/named-asm-labels.rs:36:20
    |
 LL |         asm!("nop; foo10: nop");
    |                    ^^^^^
    |
-   = help: Only GAS local labels of the form `N:` where N is a number may be used in inline asm
-   = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
+   = help: only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:39:15
+  --> $DIR/named-asm-labels.rs:39:15
    |
 LL |         asm!("bar2: nop\n bar3: nop");
    |               ^^^^
    |
-   = help: Only GAS local labels of the form `N:` where N is a number may be used in inline asm
-   = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
+   = help: only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:39:27
+  --> $DIR/named-asm-labels.rs:39:27
    |
 LL |         asm!("bar2: nop\n bar3: nop");
    |                           ^^^^
    |
-   = help: Only GAS local labels of the form `N:` where N is a number may be used in inline asm
-   = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
+   = help: only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:42:15
+  --> $DIR/named-asm-labels.rs:42:15
    |
 LL |         asm!("bar4: nop\n nop");
    |               ^^^^
    |
-   = help: Only GAS local labels of the form `N:` where N is a number may be used in inline asm
-   = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
+   = help: only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:43:21
+  --> $DIR/named-asm-labels.rs:43:21
    |
 LL |         asm!("nop\n bar5: nop");
    |                     ^^^^
    |
-   = help: Only GAS local labels of the form `N:` where N is a number may be used in inline asm
-   = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
+   = help: only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:44:21
+  --> $DIR/named-asm-labels.rs:44:21
    |
 LL |         asm!("nop\n bar6: bar7: nop");
    |                     ^^^^
    |
-   = help: Only GAS local labels of the form `N:` where N is a number may be used in inline asm
-   = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
+   = help: only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:44:27
+  --> $DIR/named-asm-labels.rs:44:27
    |
 LL |         asm!("nop\n bar6: bar7: nop");
    |                           ^^^^
    |
-   = help: Only GAS local labels of the form `N:` where N is a number may be used in inline asm
-   = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
+   = help: only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:51:13
+  --> $DIR/named-asm-labels.rs:51:13
    |
 LL |             blah2: nop
    |             ^^^^^
    |
-   = help: Only GAS local labels of the form `N:` where N is a number may be used in inline asm
-   = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
+   = help: only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:52:13
+  --> $DIR/named-asm-labels.rs:52:13
    |
 LL |             blah3: nop
    |             ^^^^^
    |
-   = help: Only GAS local labels of the form `N:` where N is a number may be used in inline asm
-   = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
+   = help: only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:60:19
+  --> $DIR/named-asm-labels.rs:60:19
    |
 LL |             nop ; blah4: nop
    |                   ^^^^^
    |
-   = help: Only GAS local labels of the form `N:` where N is a number may be used in inline asm
-   = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
+   = help: only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:74:15
+  --> $DIR/named-asm-labels.rs:74:15
    |
 LL |         asm!("blah1: 2bar: nop");
    |               ^^^^^
    |
-   = help: Only GAS local labels of the form `N:` where N is a number may be used in inline asm
-   = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
+   = help: only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:77:15
+  --> $DIR/named-asm-labels.rs:77:15
    |
 LL |         asm!("def: def: nop");
    |               ^^^
    |
-   = help: Only GAS local labels of the form `N:` where N is a number may be used in inline asm
-   = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
+   = help: only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:78:15
+  --> $DIR/named-asm-labels.rs:78:15
    |
 LL |         asm!("def: nop\ndef: nop");
    |               ^^^
    |
-   = help: Only GAS local labels of the form `N:` where N is a number may be used in inline asm
-   = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
+   = help: only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:79:15
+  --> $DIR/named-asm-labels.rs:79:15
    |
 LL |         asm!("def: nop; def: nop");
    |               ^^^
    |
-   = help: Only GAS local labels of the form `N:` where N is a number may be used in inline asm
-   = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
+   = help: only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:87:15
+  --> $DIR/named-asm-labels.rs:87:15
    |
 LL |         asm!("fooo\u{003A} nop");
    |               ^^^^^^^^^^^^^^^^
    |
-   = help: Only GAS local labels of the form `N:` where N is a number may be used in inline asm
-   = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
+   = help: only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:88:15
+  --> $DIR/named-asm-labels.rs:88:15
    |
 LL |         asm!("foooo\x3A nop");
    |               ^^^^^^^^^^^^^
    |
-   = help: Only GAS local labels of the form `N:` where N is a number may be used in inline asm
-   = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
+   = help: only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:91:15
+  --> $DIR/named-asm-labels.rs:91:15
    |
 LL |         asm!("fooooo:\u{000A} nop");
    |               ^^^^^^
    |
-   = help: Only GAS local labels of the form `N:` where N is a number may be used in inline asm
-   = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
+   = help: only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:92:15
+  --> $DIR/named-asm-labels.rs:92:15
    |
 LL |         asm!("foooooo:\x0A nop");
    |               ^^^^^^^
    |
-   = help: Only GAS local labels of the form `N:` where N is a number may be used in inline asm
-   = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
+   = help: only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:96:14
+  --> $DIR/named-asm-labels.rs:96:14
    |
 LL |         asm!("\x41\x42\x43\x3A\x20\x6E\x6F\x70");
    |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
-   = help: Only GAS local labels of the form `N:` where N is a number may be used in inline asm
-   = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
+   = help: only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: do not use named labels in inline assembly
-  --> $DIR/named_asm_labels.rs:107:13
+  --> $DIR/named-asm-labels.rs:107:13
    |
 LL |             ab: nop // ab: does foo
    |             ^^
    |
-   = help: Only GAS local labels of the form `N:` where N is a number may be used in inline asm
-   = note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
+   = help: only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
-error: aborting due to 33 previous errors
+error: do not use named labels in inline assembly
+  --> $DIR/named-asm-labels.rs:119:14
+   |
+LL |         asm!(include_str!("named-asm-labels.s"));
+   |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = help: only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
+
+warning: do not use named labels in inline assembly
+  --> $DIR/named-asm-labels.rs:129:19
+   |
+LL |             asm!("warned: nop");
+   |                   ^^^^^^
+   |
+note: the lint level is defined here
+  --> $DIR/named-asm-labels.rs:127:16
+   |
+LL |         #[warn(named_asm_labels)]
+   |                ^^^^^^^^^^^^^^^^
+   = help: only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
+
+error: aborting due to 34 previous errors; 1 warning emitted
 

From ae8a1bafc2d29ec17197ae319606026e2c00882c Mon Sep 17 00:00:00 2001
From: asquared31415 <34665709+asquared31415@users.noreply.github.com>
Date: Thu, 29 Jul 2021 18:56:31 -0400
Subject: [PATCH 7/8] Update error message

---
 compiler/rustc_builtin_macros/src/asm.rs |   8 +-
 src/test/ui/asm/named-asm-labels.rs      |  70 ++++++------
 src/test/ui/asm/named-asm-labels.stderr  | 140 +++++++++++------------
 3 files changed, 109 insertions(+), 109 deletions(-)

diff --git a/compiler/rustc_builtin_macros/src/asm.rs b/compiler/rustc_builtin_macros/src/asm.rs
index a1119916dc1fe..b3987ff79d977 100644
--- a/compiler/rustc_builtin_macros/src/asm.rs
+++ b/compiler/rustc_builtin_macros/src/asm.rs
@@ -529,8 +529,8 @@ fn expand_preparsed_asm(
                             lint::builtin::NAMED_ASM_LABELS,
                             span,
                             ecx.current_expansion.lint_node_id,
-                            "do not use named labels in inline assembly",
-                            BuiltinLintDiagnostics::NamedAsmLabel("only GAS local labels of the form `N:` where N is a number may be used in inline asm".to_string()),
+                            "avoid using named labels in inline assembly",
+                            BuiltinLintDiagnostics::NamedAsmLabel("only local labels of the form `<number>:` should be used in inline asm".to_string()),
                         );
                     }
                 } else {
@@ -539,8 +539,8 @@ fn expand_preparsed_asm(
                         lint::builtin::NAMED_ASM_LABELS,
                         template_sp,
                         ecx.current_expansion.lint_node_id,
-                        "do not use named labels in inline assembly",
-                        BuiltinLintDiagnostics::NamedAsmLabel("only GAS local labels of the form `N:` where N is a number may be used in inline asm".to_string()),
+                        "avoid using named labels in inline assembly",
+                        BuiltinLintDiagnostics::NamedAsmLabel("only local labels of the form `<number>:` should be used in inline asm".to_string()),
                     );
                 }
             }
diff --git a/src/test/ui/asm/named-asm-labels.rs b/src/test/ui/asm/named-asm-labels.rs
index 2a2d6e5cc781f..d0bce9a4bad30 100644
--- a/src/test/ui/asm/named-asm-labels.rs
+++ b/src/test/ui/asm/named-asm-labels.rs
@@ -8,42 +8,42 @@ pub static FOO: usize = 42;
 fn main() {
     unsafe {
         // Basic usage
-        asm!("bar: nop"); //~ ERROR do not use named labels
+        asm!("bar: nop"); //~ ERROR avoid using named labels
 
         // No following asm
-        asm!("abcd:"); //~ ERROR do not use named labels
+        asm!("abcd:"); //~ ERROR avoid using named labels
 
         // Multiple labels on one line
         asm!("foo: bar1: nop");
-        //~^ ERROR do not use named labels
-        //~| ERROR do not use named labels
+        //~^ ERROR avoid using named labels
+        //~| ERROR avoid using named labels
 
         // Multiple lines
-        asm!("foo1: nop", "nop"); //~ ERROR do not use named labels
+        asm!("foo1: nop", "nop"); //~ ERROR avoid using named labels
         asm!("foo2: foo3: nop", "nop");
-        //~^ ERROR do not use named labels
-        //~| ERROR do not use named labels
-        asm!("nop", "foo4: nop"); //~ ERROR do not use named labels
+        //~^ ERROR avoid using named labels
+        //~| ERROR avoid using named labels
+        asm!("nop", "foo4: nop"); //~ ERROR avoid using named labels
         asm!("foo5: nop", "foo6: nop");
-        //~^ ERROR do not use named labels
-        //~| ERROR do not use named labels
+        //~^ ERROR avoid using named labels
+        //~| ERROR avoid using named labels
 
         // Statement separator
         asm!("foo7: nop; foo8: nop");
-        //~^ ERROR do not use named labels
-        //~| ERROR do not use named labels
-        asm!("foo9: nop; nop"); //~ ERROR do not use named labels
-        asm!("nop; foo10: nop"); //~ ERROR do not use named labels
+        //~^ ERROR avoid using named labels
+        //~| ERROR avoid using named labels
+        asm!("foo9: nop; nop"); //~ ERROR avoid using named labels
+        asm!("nop; foo10: nop"); //~ ERROR avoid using named labels
 
         // Escaped newline
         asm!("bar2: nop\n bar3: nop");
-        //~^ ERROR do not use named labels
-        //~| ERROR do not use named labels
-        asm!("bar4: nop\n nop"); //~ ERROR do not use named labels
-        asm!("nop\n bar5: nop"); //~ ERROR do not use named labels
+        //~^ ERROR avoid using named labels
+        //~| ERROR avoid using named labels
+        asm!("bar4: nop\n nop"); //~ ERROR avoid using named labels
+        asm!("nop\n bar5: nop"); //~ ERROR avoid using named labels
         asm!("nop\n bar6: bar7: nop");
-        //~^ ERROR do not use named labels
-        //~| ERROR do not use named labels
+        //~^ ERROR avoid using named labels
+        //~| ERROR avoid using named labels
 
         // Raw strings
         asm!(
@@ -52,15 +52,15 @@ fn main() {
             blah3: nop
             "
         );
-        //~^^^^ ERROR do not use named labels
-        //~^^^^ ERROR do not use named labels
+        //~^^^^ ERROR avoid using named labels
+        //~^^^^ ERROR avoid using named labels
         asm!(
             r###"
             nop
             nop ; blah4: nop
             "###
         );
-        //~^^^ ERROR do not use named labels
+        //~^^^ ERROR avoid using named labels
 
         // Non-labels
         // should not trigger lint, but may be invalid asm
@@ -71,12 +71,12 @@ fn main() {
         asm!("1bar: blah: nop");
 
         // Only `blah1:` should trigger
-        asm!("blah1: 2bar: nop"); //~ ERROR do not use named labels
+        asm!("blah1: 2bar: nop"); //~ ERROR avoid using named labels
 
         // Duplicate labels
-        asm!("def: def: nop"); //~ ERROR do not use named labels
-        asm!("def: nop\ndef: nop"); //~ ERROR do not use named labels
-        asm!("def: nop; def: nop"); //~ ERROR do not use named labels
+        asm!("def: def: nop"); //~ ERROR avoid using named labels
+        asm!("def: nop\ndef: nop"); //~ ERROR avoid using named labels
+        asm!("def: nop; def: nop"); //~ ERROR avoid using named labels
 
         // Trying to break parsing
         asm!(":");
@@ -84,16 +84,16 @@ fn main() {
         asm!("::::");
 
         // 0x3A is a ':'
-        asm!("fooo\u{003A} nop"); //~ ERROR do not use named labels
-        asm!("foooo\x3A nop"); //~ ERROR do not use named labels
+        asm!("fooo\u{003A} nop"); //~ ERROR avoid using named labels
+        asm!("foooo\x3A nop"); //~ ERROR avoid using named labels
 
         // 0x0A is a newline
-        asm!("fooooo:\u{000A} nop"); //~ ERROR do not use named labels
-        asm!("foooooo:\x0A nop"); //~ ERROR do not use named labels
+        asm!("fooooo:\u{000A} nop"); //~ ERROR avoid using named labels
+        asm!("foooooo:\x0A nop"); //~ ERROR avoid using named labels
 
         // Intentionally breaking span finding
         // equivalent to "ABC: nop"
-        asm!("\x41\x42\x43\x3A\x20\x6E\x6F\x70"); //~ ERROR do not use named labels
+        asm!("\x41\x42\x43\x3A\x20\x6E\x6F\x70"); //~ ERROR avoid using named labels
 
         // Non-label colons - should pass
         // (most of these are stolen from other places)
@@ -108,7 +108,7 @@ fn main() {
             // cd: nop
             "
         );
-        //~^^^^ ERROR do not use named labels
+        //~^^^^ ERROR avoid using named labels
 
         // Tests usage of colons in non-label positions
         asm!(":lo12:FOO"); // this is apparently valid aarch64
@@ -116,7 +116,7 @@ fn main() {
         asm!(":bbb nop");
 
         // Test include_str in asm
-        asm!(include_str!("named-asm-labels.s")); //~ ERROR do not use named labels
+        asm!(include_str!("named-asm-labels.s")); //~ ERROR avoid using named labels
 
         // Test allowing or warning on the lint instead
         #[allow(named_asm_labels)]
@@ -126,7 +126,7 @@ fn main() {
 
         #[warn(named_asm_labels)]
         {
-            asm!("warned: nop"); //~ WARNING do not use named labels
+            asm!("warned: nop"); //~ WARNING avoid using named labels
         }
     }
 }
diff --git a/src/test/ui/asm/named-asm-labels.stderr b/src/test/ui/asm/named-asm-labels.stderr
index 2e1258d127d3e..db7f624a020f8 100644
--- a/src/test/ui/asm/named-asm-labels.stderr
+++ b/src/test/ui/asm/named-asm-labels.stderr
@@ -1,311 +1,311 @@
-error: do not use named labels in inline assembly
+error: avoid using named labels in inline assembly
   --> $DIR/named-asm-labels.rs:11:15
    |
 LL |         asm!("bar: nop");
    |               ^^^
    |
    = note: `#[deny(named_asm_labels)]` on by default
-   = help: only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = help: only local labels of the form `<number>:` should be used in inline asm
    = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
-error: do not use named labels in inline assembly
+error: avoid using named labels in inline assembly
   --> $DIR/named-asm-labels.rs:14:15
    |
 LL |         asm!("abcd:");
    |               ^^^^
    |
-   = help: only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = help: only local labels of the form `<number>:` should be used in inline asm
    = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
-error: do not use named labels in inline assembly
+error: avoid using named labels in inline assembly
   --> $DIR/named-asm-labels.rs:17:15
    |
 LL |         asm!("foo: bar1: nop");
    |               ^^^
    |
-   = help: only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = help: only local labels of the form `<number>:` should be used in inline asm
    = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
-error: do not use named labels in inline assembly
+error: avoid using named labels in inline assembly
   --> $DIR/named-asm-labels.rs:17:20
    |
 LL |         asm!("foo: bar1: nop");
    |                    ^^^^
    |
-   = help: only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = help: only local labels of the form `<number>:` should be used in inline asm
    = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
-error: do not use named labels in inline assembly
+error: avoid using named labels in inline assembly
   --> $DIR/named-asm-labels.rs:22:15
    |
 LL |         asm!("foo1: nop", "nop");
    |               ^^^^
    |
-   = help: only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = help: only local labels of the form `<number>:` should be used in inline asm
    = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
-error: do not use named labels in inline assembly
+error: avoid using named labels in inline assembly
   --> $DIR/named-asm-labels.rs:23:15
    |
 LL |         asm!("foo2: foo3: nop", "nop");
    |               ^^^^
    |
-   = help: only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = help: only local labels of the form `<number>:` should be used in inline asm
    = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
-error: do not use named labels in inline assembly
+error: avoid using named labels in inline assembly
   --> $DIR/named-asm-labels.rs:23:21
    |
 LL |         asm!("foo2: foo3: nop", "nop");
    |                     ^^^^
    |
-   = help: only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = help: only local labels of the form `<number>:` should be used in inline asm
    = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
-error: do not use named labels in inline assembly
+error: avoid using named labels in inline assembly
   --> $DIR/named-asm-labels.rs:26:22
    |
 LL |         asm!("nop", "foo4: nop");
    |                      ^^^^
    |
-   = help: only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = help: only local labels of the form `<number>:` should be used in inline asm
    = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
-error: do not use named labels in inline assembly
+error: avoid using named labels in inline assembly
   --> $DIR/named-asm-labels.rs:27:15
    |
 LL |         asm!("foo5: nop", "foo6: nop");
    |               ^^^^
    |
-   = help: only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = help: only local labels of the form `<number>:` should be used in inline asm
    = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
-error: do not use named labels in inline assembly
+error: avoid using named labels in inline assembly
   --> $DIR/named-asm-labels.rs:27:28
    |
 LL |         asm!("foo5: nop", "foo6: nop");
    |                            ^^^^
    |
-   = help: only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = help: only local labels of the form `<number>:` should be used in inline asm
    = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
-error: do not use named labels in inline assembly
+error: avoid using named labels in inline assembly
   --> $DIR/named-asm-labels.rs:32:15
    |
 LL |         asm!("foo7: nop; foo8: nop");
    |               ^^^^
    |
-   = help: only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = help: only local labels of the form `<number>:` should be used in inline asm
    = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
-error: do not use named labels in inline assembly
+error: avoid using named labels in inline assembly
   --> $DIR/named-asm-labels.rs:32:26
    |
 LL |         asm!("foo7: nop; foo8: nop");
    |                          ^^^^
    |
-   = help: only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = help: only local labels of the form `<number>:` should be used in inline asm
    = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
-error: do not use named labels in inline assembly
+error: avoid using named labels in inline assembly
   --> $DIR/named-asm-labels.rs:35:15
    |
 LL |         asm!("foo9: nop; nop");
    |               ^^^^
    |
-   = help: only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = help: only local labels of the form `<number>:` should be used in inline asm
    = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
-error: do not use named labels in inline assembly
+error: avoid using named labels in inline assembly
   --> $DIR/named-asm-labels.rs:36:20
    |
 LL |         asm!("nop; foo10: nop");
    |                    ^^^^^
    |
-   = help: only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = help: only local labels of the form `<number>:` should be used in inline asm
    = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
-error: do not use named labels in inline assembly
+error: avoid using named labels in inline assembly
   --> $DIR/named-asm-labels.rs:39:15
    |
 LL |         asm!("bar2: nop\n bar3: nop");
    |               ^^^^
    |
-   = help: only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = help: only local labels of the form `<number>:` should be used in inline asm
    = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
-error: do not use named labels in inline assembly
+error: avoid using named labels in inline assembly
   --> $DIR/named-asm-labels.rs:39:27
    |
 LL |         asm!("bar2: nop\n bar3: nop");
    |                           ^^^^
    |
-   = help: only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = help: only local labels of the form `<number>:` should be used in inline asm
    = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
-error: do not use named labels in inline assembly
+error: avoid using named labels in inline assembly
   --> $DIR/named-asm-labels.rs:42:15
    |
 LL |         asm!("bar4: nop\n nop");
    |               ^^^^
    |
-   = help: only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = help: only local labels of the form `<number>:` should be used in inline asm
    = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
-error: do not use named labels in inline assembly
+error: avoid using named labels in inline assembly
   --> $DIR/named-asm-labels.rs:43:21
    |
 LL |         asm!("nop\n bar5: nop");
    |                     ^^^^
    |
-   = help: only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = help: only local labels of the form `<number>:` should be used in inline asm
    = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
-error: do not use named labels in inline assembly
+error: avoid using named labels in inline assembly
   --> $DIR/named-asm-labels.rs:44:21
    |
 LL |         asm!("nop\n bar6: bar7: nop");
    |                     ^^^^
    |
-   = help: only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = help: only local labels of the form `<number>:` should be used in inline asm
    = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
-error: do not use named labels in inline assembly
+error: avoid using named labels in inline assembly
   --> $DIR/named-asm-labels.rs:44:27
    |
 LL |         asm!("nop\n bar6: bar7: nop");
    |                           ^^^^
    |
-   = help: only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = help: only local labels of the form `<number>:` should be used in inline asm
    = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
-error: do not use named labels in inline assembly
+error: avoid using named labels in inline assembly
   --> $DIR/named-asm-labels.rs:51:13
    |
 LL |             blah2: nop
    |             ^^^^^
    |
-   = help: only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = help: only local labels of the form `<number>:` should be used in inline asm
    = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
-error: do not use named labels in inline assembly
+error: avoid using named labels in inline assembly
   --> $DIR/named-asm-labels.rs:52:13
    |
 LL |             blah3: nop
    |             ^^^^^
    |
-   = help: only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = help: only local labels of the form `<number>:` should be used in inline asm
    = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
-error: do not use named labels in inline assembly
+error: avoid using named labels in inline assembly
   --> $DIR/named-asm-labels.rs:60:19
    |
 LL |             nop ; blah4: nop
    |                   ^^^^^
    |
-   = help: only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = help: only local labels of the form `<number>:` should be used in inline asm
    = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
-error: do not use named labels in inline assembly
+error: avoid using named labels in inline assembly
   --> $DIR/named-asm-labels.rs:74:15
    |
 LL |         asm!("blah1: 2bar: nop");
    |               ^^^^^
    |
-   = help: only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = help: only local labels of the form `<number>:` should be used in inline asm
    = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
-error: do not use named labels in inline assembly
+error: avoid using named labels in inline assembly
   --> $DIR/named-asm-labels.rs:77:15
    |
 LL |         asm!("def: def: nop");
    |               ^^^
    |
-   = help: only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = help: only local labels of the form `<number>:` should be used in inline asm
    = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
-error: do not use named labels in inline assembly
+error: avoid using named labels in inline assembly
   --> $DIR/named-asm-labels.rs:78:15
    |
 LL |         asm!("def: nop\ndef: nop");
    |               ^^^
    |
-   = help: only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = help: only local labels of the form `<number>:` should be used in inline asm
    = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
-error: do not use named labels in inline assembly
+error: avoid using named labels in inline assembly
   --> $DIR/named-asm-labels.rs:79:15
    |
 LL |         asm!("def: nop; def: nop");
    |               ^^^
    |
-   = help: only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = help: only local labels of the form `<number>:` should be used in inline asm
    = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
-error: do not use named labels in inline assembly
+error: avoid using named labels in inline assembly
   --> $DIR/named-asm-labels.rs:87:15
    |
 LL |         asm!("fooo\u{003A} nop");
    |               ^^^^^^^^^^^^^^^^
    |
-   = help: only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = help: only local labels of the form `<number>:` should be used in inline asm
    = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
-error: do not use named labels in inline assembly
+error: avoid using named labels in inline assembly
   --> $DIR/named-asm-labels.rs:88:15
    |
 LL |         asm!("foooo\x3A nop");
    |               ^^^^^^^^^^^^^
    |
-   = help: only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = help: only local labels of the form `<number>:` should be used in inline asm
    = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
-error: do not use named labels in inline assembly
+error: avoid using named labels in inline assembly
   --> $DIR/named-asm-labels.rs:91:15
    |
 LL |         asm!("fooooo:\u{000A} nop");
    |               ^^^^^^
    |
-   = help: only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = help: only local labels of the form `<number>:` should be used in inline asm
    = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
-error: do not use named labels in inline assembly
+error: avoid using named labels in inline assembly
   --> $DIR/named-asm-labels.rs:92:15
    |
 LL |         asm!("foooooo:\x0A nop");
    |               ^^^^^^^
    |
-   = help: only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = help: only local labels of the form `<number>:` should be used in inline asm
    = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
-error: do not use named labels in inline assembly
+error: avoid using named labels in inline assembly
   --> $DIR/named-asm-labels.rs:96:14
    |
 LL |         asm!("\x41\x42\x43\x3A\x20\x6E\x6F\x70");
    |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
-   = help: only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = help: only local labels of the form `<number>:` should be used in inline asm
    = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
-error: do not use named labels in inline assembly
+error: avoid using named labels in inline assembly
   --> $DIR/named-asm-labels.rs:107:13
    |
 LL |             ab: nop // ab: does foo
    |             ^^
    |
-   = help: only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = help: only local labels of the form `<number>:` should be used in inline asm
    = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
-error: do not use named labels in inline assembly
+error: avoid using named labels in inline assembly
   --> $DIR/named-asm-labels.rs:119:14
    |
 LL |         asm!(include_str!("named-asm-labels.s"));
    |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
-   = help: only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = help: only local labels of the form `<number>:` should be used in inline asm
    = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
-warning: do not use named labels in inline assembly
+warning: avoid using named labels in inline assembly
   --> $DIR/named-asm-labels.rs:129:19
    |
 LL |             asm!("warned: nop");
@@ -316,7 +316,7 @@ note: the lint level is defined here
    |
 LL |         #[warn(named_asm_labels)]
    |                ^^^^^^^^^^^^^^^^
-   = help: only GAS local labels of the form `N:` where N is a number may be used in inline asm
+   = help: only local labels of the form `<number>:` should be used in inline asm
    = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: aborting due to 34 previous errors; 1 warning emitted

From 51e414ff454e35a38d9a47269cd2216a9d4c68da Mon Sep 17 00:00:00 2001
From: asquared31415 <34665709+asquared31415@users.noreply.github.com>
Date: Wed, 4 Aug 2021 17:28:30 -0400
Subject: [PATCH 8/8] Combine spans into one error, deduplicate code

---
 compiler/rustc_builtin_macros/src/asm.rs |  35 +++----
 src/test/ui/asm/named-asm-labels.rs      |   7 +-
 src/test/ui/asm/named-asm-labels.stderr  | 118 +++++++----------------
 3 files changed, 48 insertions(+), 112 deletions(-)

diff --git a/compiler/rustc_builtin_macros/src/asm.rs b/compiler/rustc_builtin_macros/src/asm.rs
index b3987ff79d977..018a2ce6c2eab 100644
--- a/compiler/rustc_builtin_macros/src/asm.rs
+++ b/compiler/rustc_builtin_macros/src/asm.rs
@@ -10,7 +10,7 @@ use rustc_parse_format as parse;
 use rustc_session::lint::{self, BuiltinLintDiagnostics};
 use rustc_span::symbol::Ident;
 use rustc_span::symbol::{kw, sym, Symbol};
-use rustc_span::{InnerSpan, Span};
+use rustc_span::{InnerSpan, MultiSpan, Span};
 use rustc_target::asm::InlineAsmArch;
 use smallvec::smallvec;
 
@@ -523,26 +523,19 @@ fn expand_preparsed_asm(
             if found_labels.len() > 0 {
                 let spans =
                     found_labels.into_iter().filter_map(find_label_span).collect::<Vec<Span>>();
-                if spans.len() > 0 {
-                    for span in spans.into_iter() {
-                        ecx.parse_sess().buffer_lint_with_diagnostic(
-                            lint::builtin::NAMED_ASM_LABELS,
-                            span,
-                            ecx.current_expansion.lint_node_id,
-                            "avoid using named labels in inline assembly",
-                            BuiltinLintDiagnostics::NamedAsmLabel("only local labels of the form `<number>:` should be used in inline asm".to_string()),
-                        );
-                    }
-                } else {
-                    // If there were labels but we couldn't find a span, combine the warnings and use the template span
-                    ecx.parse_sess().buffer_lint_with_diagnostic(
-                        lint::builtin::NAMED_ASM_LABELS,
-                        template_sp,
-                        ecx.current_expansion.lint_node_id,
-                        "avoid using named labels in inline assembly",
-                        BuiltinLintDiagnostics::NamedAsmLabel("only local labels of the form `<number>:` should be used in inline asm".to_string()),
-                    );
-                }
+                // If there were labels but we couldn't find a span, combine the warnings and use the template span
+                let target_spans: MultiSpan =
+                    if spans.len() > 0 { spans.into() } else { template_sp.into() };
+                ecx.parse_sess().buffer_lint_with_diagnostic(
+                    lint::builtin::NAMED_ASM_LABELS,
+                    target_spans,
+                    ecx.current_expansion.lint_node_id,
+                    "avoid using named labels in inline assembly",
+                    BuiltinLintDiagnostics::NamedAsmLabel(
+                        "only local labels of the form `<number>:` should be used in inline asm"
+                            .to_string(),
+                    ),
+                );
             }
         }
 
diff --git a/src/test/ui/asm/named-asm-labels.rs b/src/test/ui/asm/named-asm-labels.rs
index d0bce9a4bad30..803501b40b68e 100644
--- a/src/test/ui/asm/named-asm-labels.rs
+++ b/src/test/ui/asm/named-asm-labels.rs
@@ -16,13 +16,11 @@ fn main() {
         // Multiple labels on one line
         asm!("foo: bar1: nop");
         //~^ ERROR avoid using named labels
-        //~| ERROR avoid using named labels
 
         // Multiple lines
         asm!("foo1: nop", "nop"); //~ ERROR avoid using named labels
         asm!("foo2: foo3: nop", "nop");
         //~^ ERROR avoid using named labels
-        //~| ERROR avoid using named labels
         asm!("nop", "foo4: nop"); //~ ERROR avoid using named labels
         asm!("foo5: nop", "foo6: nop");
         //~^ ERROR avoid using named labels
@@ -31,19 +29,16 @@ fn main() {
         // Statement separator
         asm!("foo7: nop; foo8: nop");
         //~^ ERROR avoid using named labels
-        //~| ERROR avoid using named labels
         asm!("foo9: nop; nop"); //~ ERROR avoid using named labels
         asm!("nop; foo10: nop"); //~ ERROR avoid using named labels
 
         // Escaped newline
         asm!("bar2: nop\n bar3: nop");
         //~^ ERROR avoid using named labels
-        //~| ERROR avoid using named labels
         asm!("bar4: nop\n nop"); //~ ERROR avoid using named labels
         asm!("nop\n bar5: nop"); //~ ERROR avoid using named labels
         asm!("nop\n bar6: bar7: nop");
         //~^ ERROR avoid using named labels
-        //~| ERROR avoid using named labels
 
         // Raw strings
         asm!(
@@ -53,7 +48,7 @@ fn main() {
             "
         );
         //~^^^^ ERROR avoid using named labels
-        //~^^^^ ERROR avoid using named labels
+
         asm!(
             r###"
             nop
diff --git a/src/test/ui/asm/named-asm-labels.stderr b/src/test/ui/asm/named-asm-labels.stderr
index db7f624a020f8..3c4a4db75e02d 100644
--- a/src/test/ui/asm/named-asm-labels.stderr
+++ b/src/test/ui/asm/named-asm-labels.stderr
@@ -21,22 +21,13 @@ error: avoid using named labels in inline assembly
   --> $DIR/named-asm-labels.rs:17:15
    |
 LL |         asm!("foo: bar1: nop");
-   |               ^^^
-   |
-   = help: only local labels of the form `<number>:` should be used in inline asm
-   = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
-
-error: avoid using named labels in inline assembly
-  --> $DIR/named-asm-labels.rs:17:20
-   |
-LL |         asm!("foo: bar1: nop");
-   |                    ^^^^
+   |               ^^^  ^^^^
    |
    = help: only local labels of the form `<number>:` should be used in inline asm
    = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: avoid using named labels in inline assembly
-  --> $DIR/named-asm-labels.rs:22:15
+  --> $DIR/named-asm-labels.rs:21:15
    |
 LL |         asm!("foo1: nop", "nop");
    |               ^^^^
@@ -45,25 +36,16 @@ LL |         asm!("foo1: nop", "nop");
    = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: avoid using named labels in inline assembly
-  --> $DIR/named-asm-labels.rs:23:15
-   |
-LL |         asm!("foo2: foo3: nop", "nop");
-   |               ^^^^
-   |
-   = help: only local labels of the form `<number>:` should be used in inline asm
-   = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
-
-error: avoid using named labels in inline assembly
-  --> $DIR/named-asm-labels.rs:23:21
+  --> $DIR/named-asm-labels.rs:22:15
    |
 LL |         asm!("foo2: foo3: nop", "nop");
-   |                     ^^^^
+   |               ^^^^  ^^^^
    |
    = help: only local labels of the form `<number>:` should be used in inline asm
    = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: avoid using named labels in inline assembly
-  --> $DIR/named-asm-labels.rs:26:22
+  --> $DIR/named-asm-labels.rs:24:22
    |
 LL |         asm!("nop", "foo4: nop");
    |                      ^^^^
@@ -72,7 +54,7 @@ LL |         asm!("nop", "foo4: nop");
    = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: avoid using named labels in inline assembly
-  --> $DIR/named-asm-labels.rs:27:15
+  --> $DIR/named-asm-labels.rs:25:15
    |
 LL |         asm!("foo5: nop", "foo6: nop");
    |               ^^^^
@@ -81,7 +63,7 @@ LL |         asm!("foo5: nop", "foo6: nop");
    = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: avoid using named labels in inline assembly
-  --> $DIR/named-asm-labels.rs:27:28
+  --> $DIR/named-asm-labels.rs:25:28
    |
 LL |         asm!("foo5: nop", "foo6: nop");
    |                            ^^^^
@@ -90,25 +72,16 @@ LL |         asm!("foo5: nop", "foo6: nop");
    = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: avoid using named labels in inline assembly
-  --> $DIR/named-asm-labels.rs:32:15
-   |
-LL |         asm!("foo7: nop; foo8: nop");
-   |               ^^^^
-   |
-   = help: only local labels of the form `<number>:` should be used in inline asm
-   = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
-
-error: avoid using named labels in inline assembly
-  --> $DIR/named-asm-labels.rs:32:26
+  --> $DIR/named-asm-labels.rs:30:15
    |
 LL |         asm!("foo7: nop; foo8: nop");
-   |                          ^^^^
+   |               ^^^^       ^^^^
    |
    = help: only local labels of the form `<number>:` should be used in inline asm
    = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: avoid using named labels in inline assembly
-  --> $DIR/named-asm-labels.rs:35:15
+  --> $DIR/named-asm-labels.rs:32:15
    |
 LL |         asm!("foo9: nop; nop");
    |               ^^^^
@@ -117,7 +90,7 @@ LL |         asm!("foo9: nop; nop");
    = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: avoid using named labels in inline assembly
-  --> $DIR/named-asm-labels.rs:36:20
+  --> $DIR/named-asm-labels.rs:33:20
    |
 LL |         asm!("nop; foo10: nop");
    |                    ^^^^^
@@ -126,25 +99,16 @@ LL |         asm!("nop; foo10: nop");
    = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: avoid using named labels in inline assembly
-  --> $DIR/named-asm-labels.rs:39:15
-   |
-LL |         asm!("bar2: nop\n bar3: nop");
-   |               ^^^^
-   |
-   = help: only local labels of the form `<number>:` should be used in inline asm
-   = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
-
-error: avoid using named labels in inline assembly
-  --> $DIR/named-asm-labels.rs:39:27
+  --> $DIR/named-asm-labels.rs:36:15
    |
 LL |         asm!("bar2: nop\n bar3: nop");
-   |                           ^^^^
+   |               ^^^^        ^^^^
    |
    = help: only local labels of the form `<number>:` should be used in inline asm
    = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: avoid using named labels in inline assembly
-  --> $DIR/named-asm-labels.rs:42:15
+  --> $DIR/named-asm-labels.rs:38:15
    |
 LL |         asm!("bar4: nop\n nop");
    |               ^^^^
@@ -153,7 +117,7 @@ LL |         asm!("bar4: nop\n nop");
    = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: avoid using named labels in inline assembly
-  --> $DIR/named-asm-labels.rs:43:21
+  --> $DIR/named-asm-labels.rs:39:21
    |
 LL |         asm!("nop\n bar5: nop");
    |                     ^^^^
@@ -162,35 +126,19 @@ LL |         asm!("nop\n bar5: nop");
    = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: avoid using named labels in inline assembly
-  --> $DIR/named-asm-labels.rs:44:21
+  --> $DIR/named-asm-labels.rs:40:21
    |
 LL |         asm!("nop\n bar6: bar7: nop");
-   |                     ^^^^
+   |                     ^^^^  ^^^^
    |
    = help: only local labels of the form `<number>:` should be used in inline asm
    = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: avoid using named labels in inline assembly
-  --> $DIR/named-asm-labels.rs:44:27
-   |
-LL |         asm!("nop\n bar6: bar7: nop");
-   |                           ^^^^
-   |
-   = help: only local labels of the form `<number>:` should be used in inline asm
-   = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
-
-error: avoid using named labels in inline assembly
-  --> $DIR/named-asm-labels.rs:51:13
+  --> $DIR/named-asm-labels.rs:46:13
    |
 LL |             blah2: nop
    |             ^^^^^
-   |
-   = help: only local labels of the form `<number>:` should be used in inline asm
-   = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
-
-error: avoid using named labels in inline assembly
-  --> $DIR/named-asm-labels.rs:52:13
-   |
 LL |             blah3: nop
    |             ^^^^^
    |
@@ -198,7 +146,7 @@ LL |             blah3: nop
    = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: avoid using named labels in inline assembly
-  --> $DIR/named-asm-labels.rs:60:19
+  --> $DIR/named-asm-labels.rs:55:19
    |
 LL |             nop ; blah4: nop
    |                   ^^^^^
@@ -207,7 +155,7 @@ LL |             nop ; blah4: nop
    = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: avoid using named labels in inline assembly
-  --> $DIR/named-asm-labels.rs:74:15
+  --> $DIR/named-asm-labels.rs:69:15
    |
 LL |         asm!("blah1: 2bar: nop");
    |               ^^^^^
@@ -216,7 +164,7 @@ LL |         asm!("blah1: 2bar: nop");
    = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: avoid using named labels in inline assembly
-  --> $DIR/named-asm-labels.rs:77:15
+  --> $DIR/named-asm-labels.rs:72:15
    |
 LL |         asm!("def: def: nop");
    |               ^^^
@@ -225,7 +173,7 @@ LL |         asm!("def: def: nop");
    = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: avoid using named labels in inline assembly
-  --> $DIR/named-asm-labels.rs:78:15
+  --> $DIR/named-asm-labels.rs:73:15
    |
 LL |         asm!("def: nop\ndef: nop");
    |               ^^^
@@ -234,7 +182,7 @@ LL |         asm!("def: nop\ndef: nop");
    = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: avoid using named labels in inline assembly
-  --> $DIR/named-asm-labels.rs:79:15
+  --> $DIR/named-asm-labels.rs:74:15
    |
 LL |         asm!("def: nop; def: nop");
    |               ^^^
@@ -243,7 +191,7 @@ LL |         asm!("def: nop; def: nop");
    = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: avoid using named labels in inline assembly
-  --> $DIR/named-asm-labels.rs:87:15
+  --> $DIR/named-asm-labels.rs:82:15
    |
 LL |         asm!("fooo\u{003A} nop");
    |               ^^^^^^^^^^^^^^^^
@@ -252,7 +200,7 @@ LL |         asm!("fooo\u{003A} nop");
    = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: avoid using named labels in inline assembly
-  --> $DIR/named-asm-labels.rs:88:15
+  --> $DIR/named-asm-labels.rs:83:15
    |
 LL |         asm!("foooo\x3A nop");
    |               ^^^^^^^^^^^^^
@@ -261,7 +209,7 @@ LL |         asm!("foooo\x3A nop");
    = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: avoid using named labels in inline assembly
-  --> $DIR/named-asm-labels.rs:91:15
+  --> $DIR/named-asm-labels.rs:86:15
    |
 LL |         asm!("fooooo:\u{000A} nop");
    |               ^^^^^^
@@ -270,7 +218,7 @@ LL |         asm!("fooooo:\u{000A} nop");
    = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: avoid using named labels in inline assembly
-  --> $DIR/named-asm-labels.rs:92:15
+  --> $DIR/named-asm-labels.rs:87:15
    |
 LL |         asm!("foooooo:\x0A nop");
    |               ^^^^^^^
@@ -279,7 +227,7 @@ LL |         asm!("foooooo:\x0A nop");
    = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: avoid using named labels in inline assembly
-  --> $DIR/named-asm-labels.rs:96:14
+  --> $DIR/named-asm-labels.rs:91:14
    |
 LL |         asm!("\x41\x42\x43\x3A\x20\x6E\x6F\x70");
    |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -288,7 +236,7 @@ LL |         asm!("\x41\x42\x43\x3A\x20\x6E\x6F\x70");
    = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: avoid using named labels in inline assembly
-  --> $DIR/named-asm-labels.rs:107:13
+  --> $DIR/named-asm-labels.rs:102:13
    |
 LL |             ab: nop // ab: does foo
    |             ^^
@@ -297,7 +245,7 @@ LL |             ab: nop // ab: does foo
    = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 error: avoid using named labels in inline assembly
-  --> $DIR/named-asm-labels.rs:119:14
+  --> $DIR/named-asm-labels.rs:114:14
    |
 LL |         asm!(include_str!("named-asm-labels.s"));
    |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -306,18 +254,18 @@ LL |         asm!(include_str!("named-asm-labels.s"));
    = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
 warning: avoid using named labels in inline assembly
-  --> $DIR/named-asm-labels.rs:129:19
+  --> $DIR/named-asm-labels.rs:124:19
    |
 LL |             asm!("warned: nop");
    |                   ^^^^^^
    |
 note: the lint level is defined here
-  --> $DIR/named-asm-labels.rs:127:16
+  --> $DIR/named-asm-labels.rs:122:16
    |
 LL |         #[warn(named_asm_labels)]
    |                ^^^^^^^^^^^^^^^^
    = help: only local labels of the form `<number>:` should be used in inline asm
    = note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
 
-error: aborting due to 34 previous errors; 1 warning emitted
+error: aborting due to 28 previous errors; 1 warning emitted