From aa8512056b92b1e28f674ce4e00e0f64f05ade46 Mon Sep 17 00:00:00 2001 From: Amanieu d'Antras Date: Tue, 12 Jul 2022 22:54:47 +0200 Subject: [PATCH] Fix spans for asm diagnostics Line spans were incorrect if the first line of an asm statement was an empty string. --- compiler/rustc_builtin_macros/src/asm.rs | 4 ++-- src/test/ui/asm/aarch64/srcloc.rs | 7 +++++++ src/test/ui/asm/aarch64/srcloc.stderr | 14 +++++++++++++- src/test/ui/asm/x86_64/srcloc.rs | 7 +++++++ src/test/ui/asm/x86_64/srcloc.stderr | 14 +++++++++++++- 5 files changed, 42 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_builtin_macros/src/asm.rs b/compiler/rustc_builtin_macros/src/asm.rs index c95d7147176bd..47fd62d084e1a 100644 --- a/compiler/rustc_builtin_macros/src/asm.rs +++ b/compiler/rustc_builtin_macros/src/asm.rs @@ -534,8 +534,8 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, args: AsmArgs) -> Option $DIR/srcloc.rs:125:14 + | +LL | "invalid_instruction" + | ^ + | +note: instantiated into assembly here + --> :4:1 + | +LL | invalid_instruction + | ^ + +error: aborting due to 24 previous errors diff --git a/src/test/ui/asm/x86_64/srcloc.rs b/src/test/ui/asm/x86_64/srcloc.rs index 8a21d75977212..1135ad2e1c643 100644 --- a/src/test/ui/asm/x86_64/srcloc.rs +++ b/src/test/ui/asm/x86_64/srcloc.rs @@ -120,5 +120,12 @@ fn main() { //~^^^^^^^^^^ ERROR: invalid instruction mnemonic 'invalid_instruction2' //~^^^^^^^ ERROR: invalid instruction mnemonic 'invalid_instruction3' //~^^^^^^^^ ERROR: invalid instruction mnemonic 'invalid_instruction4' + + asm!( + "", + "\n", + "invalid_instruction" + ); + //~^^ ERROR: invalid instruction mnemonic 'invalid_instruction' } } diff --git a/src/test/ui/asm/x86_64/srcloc.stderr b/src/test/ui/asm/x86_64/srcloc.stderr index b62c8948289dd..8899c1b916bd0 100644 --- a/src/test/ui/asm/x86_64/srcloc.stderr +++ b/src/test/ui/asm/x86_64/srcloc.stderr @@ -286,5 +286,17 @@ note: instantiated into assembly here LL | invalid_instruction4 | ^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 23 previous errors; 1 warning emitted +error: invalid instruction mnemonic 'invalid_instruction' + --> $DIR/srcloc.rs:127:14 + | +LL | "invalid_instruction" + | ^ + | +note: instantiated into assembly here + --> :5:1 + | +LL | invalid_instruction + | ^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 24 previous errors; 1 warning emitted