Skip to content

Commit aa85120

Browse files
committed
Fix spans for asm diagnostics
Line spans were incorrect if the first line of an asm statement was an empty string.
1 parent 50b0025 commit aa85120

File tree

5 files changed

+42
-4
lines changed

5 files changed

+42
-4
lines changed

compiler/rustc_builtin_macros/src/asm.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -534,8 +534,8 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, args: AsmArgs) -> Option<ast::Inl
534534

535535
let mut template_strs = Vec::with_capacity(args.templates.len());
536536

537-
for template_expr in args.templates.into_iter() {
538-
if !template.is_empty() {
537+
for (i, template_expr) in args.templates.into_iter().enumerate() {
538+
if i != 0 {
539539
template.push(ast::InlineAsmTemplatePiece::String("\n".to_string()));
540540
}
541541

src/test/ui/asm/aarch64/srcloc.rs

+7
Original file line numberDiff line numberDiff line change
@@ -118,5 +118,12 @@ fn main() {
118118
//~^^^^^^^^^^ ERROR: unrecognized instruction mnemonic
119119
//~^^^^^^^ ERROR: unrecognized instruction mnemonic
120120
//~^^^^^^^^ ERROR: unrecognized instruction mnemonic
121+
122+
asm!(
123+
"",
124+
"\n",
125+
"invalid_instruction"
126+
);
127+
//~^^ ERROR: invalid instruction mnemonic 'invalid_instruction'
121128
}
122129
}

src/test/ui/asm/aarch64/srcloc.stderr

+13-1
Original file line numberDiff line numberDiff line change
@@ -274,5 +274,17 @@ note: instantiated into assembly here
274274
LL | invalid_instruction4
275275
| ^
276276

277-
error: aborting due to 23 previous errors
277+
error: unrecognized instruction mnemonic
278+
--> $DIR/srcloc.rs:125:14
279+
|
280+
LL | "invalid_instruction"
281+
| ^
282+
|
283+
note: instantiated into assembly here
284+
--> <inline asm>:4:1
285+
|
286+
LL | invalid_instruction
287+
| ^
288+
289+
error: aborting due to 24 previous errors
278290

src/test/ui/asm/x86_64/srcloc.rs

+7
Original file line numberDiff line numberDiff line change
@@ -120,5 +120,12 @@ fn main() {
120120
//~^^^^^^^^^^ ERROR: invalid instruction mnemonic 'invalid_instruction2'
121121
//~^^^^^^^ ERROR: invalid instruction mnemonic 'invalid_instruction3'
122122
//~^^^^^^^^ ERROR: invalid instruction mnemonic 'invalid_instruction4'
123+
124+
asm!(
125+
"",
126+
"\n",
127+
"invalid_instruction"
128+
);
129+
//~^^ ERROR: invalid instruction mnemonic 'invalid_instruction'
123130
}
124131
}

src/test/ui/asm/x86_64/srcloc.stderr

+13-1
Original file line numberDiff line numberDiff line change
@@ -286,5 +286,17 @@ note: instantiated into assembly here
286286
LL | invalid_instruction4
287287
| ^^^^^^^^^^^^^^^^^^^^
288288

289-
error: aborting due to 23 previous errors; 1 warning emitted
289+
error: invalid instruction mnemonic 'invalid_instruction'
290+
--> $DIR/srcloc.rs:127:14
291+
|
292+
LL | "invalid_instruction"
293+
| ^
294+
|
295+
note: instantiated into assembly here
296+
--> <inline asm>:5:1
297+
|
298+
LL | invalid_instruction
299+
| ^^^^^^^^^^^^^^^^^^^
300+
301+
error: aborting due to 24 previous errors; 1 warning emitted
290302

0 commit comments

Comments
 (0)