Skip to content

Commit 16880b2

Browse files
committed
delay error for unsupported options
1 parent 0a2c8b2 commit 16880b2

File tree

3 files changed

+30
-49
lines changed

3 files changed

+30
-49
lines changed

compiler/rustc_builtin_macros/src/asm.rs

+7-12
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,13 @@ fn validate_raw_asm_args<'a>(
347347

348348
for (symbol, option, span, full_span) in new_options {
349349
if !asm_macro.is_supported_option(option) {
350-
// Currently handled during parsing.
350+
// Tool-only output.
351+
dcx.emit_err(errors::AsmUnsupportedOption {
352+
span,
353+
symbol,
354+
full_span,
355+
macro_name: asm_macro.macro_name(),
356+
});
351357
} else if args.options.contains(option) {
352358
// Tool-only output.
353359
dcx.emit_err(errors::AsmOptAlreadyprovided { span, symbol, full_span });
@@ -492,17 +498,6 @@ fn parse_options<'a>(
492498
let full_span =
493499
if p.token == token::Comma { span.to(p.token.span) } else { span };
494500

495-
// NOTE: should this be handled during validation instead?
496-
if !asm_macro.is_supported_option(option) {
497-
// Tool-only output.
498-
p.dcx().emit_err(errors::AsmUnsupportedOption {
499-
span,
500-
symbol: exp.kw,
501-
full_span,
502-
macro_name: asm_macro.macro_name(),
503-
});
504-
}
505-
506501
options.push((exp.kw, option, span, full_span));
507502
break 'blk;
508503
}

tests/ui/asm/parse-error.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,9 @@ global_asm!("", options(FOO));
113113
global_asm!("", options(FOO,));
114114
//~^ ERROR expected one of `)`, `att_syntax`, or `raw`, found `FOO`
115115
global_asm!("", options(nomem FOO));
116-
//~^ ERROR the `nomem` option cannot be used with `global_asm!`
117-
//~| ERROR expected one of `)` or `,`, found `FOO`
116+
//~^ ERROR expected one of `)` or `,`, found `FOO`
118117
global_asm!("", options(nomem, FOO));
119-
//~^ ERROR the `nomem` option cannot be used with `global_asm!`
120-
//~| ERROR expected one of `)`, `att_syntax`, or `raw`, found `FOO`
118+
//~^ ERROR expected one of `)`, `att_syntax`, or `raw`, found `FOO`
121119
global_asm!("{}", options(), const FOO);
122120
global_asm!("", clobber_abi(FOO));
123121
//~^ ERROR expected string literal

tests/ui/asm/parse-error.stderr

+21-33
Original file line numberDiff line numberDiff line change
@@ -270,148 +270,136 @@ error: expected one of `)`, `att_syntax`, or `raw`, found `FOO`
270270
LL | global_asm!("", options(FOO,));
271271
| ^^^ expected one of `)`, `att_syntax`, or `raw`
272272

273-
error: the `nomem` option cannot be used with `global_asm!`
274-
--> $DIR/parse-error.rs:115:25
275-
|
276-
LL | global_asm!("", options(nomem FOO));
277-
| ^^^^^ the `nomem` option is not meaningful for global-scoped inline assembly
278-
279273
error: expected one of `)` or `,`, found `FOO`
280274
--> $DIR/parse-error.rs:115:31
281275
|
282276
LL | global_asm!("", options(nomem FOO));
283277
| ^^^ expected one of `)` or `,`
284278

285-
error: the `nomem` option cannot be used with `global_asm!`
286-
--> $DIR/parse-error.rs:118:25
287-
|
288-
LL | global_asm!("", options(nomem, FOO));
289-
| ^^^^^ the `nomem` option is not meaningful for global-scoped inline assembly
290-
291279
error: expected one of `)`, `att_syntax`, or `raw`, found `FOO`
292-
--> $DIR/parse-error.rs:118:32
280+
--> $DIR/parse-error.rs:117:32
293281
|
294282
LL | global_asm!("", options(nomem, FOO));
295283
| ^^^ expected one of `)`, `att_syntax`, or `raw`
296284

297285
error: expected string literal
298-
--> $DIR/parse-error.rs:122:29
286+
--> $DIR/parse-error.rs:120:29
299287
|
300288
LL | global_asm!("", clobber_abi(FOO));
301289
| ^^^ not a string literal
302290

303291
error: expected one of `)` or `,`, found `FOO`
304-
--> $DIR/parse-error.rs:124:33
292+
--> $DIR/parse-error.rs:122:33
305293
|
306294
LL | global_asm!("", clobber_abi("C" FOO));
307295
| ^^^ expected one of `)` or `,`
308296

309297
error: expected string literal
310-
--> $DIR/parse-error.rs:126:34
298+
--> $DIR/parse-error.rs:124:34
311299
|
312300
LL | global_asm!("", clobber_abi("C", FOO));
313301
| ^^^ not a string literal
314302

315303
error: `clobber_abi` cannot be used with `global_asm!`
316-
--> $DIR/parse-error.rs:128:19
304+
--> $DIR/parse-error.rs:126:19
317305
|
318306
LL | global_asm!("{}", clobber_abi("C"), const FOO);
319307
| ^^^^^^^^^^^^^^^^
320308

321309
error: `clobber_abi` cannot be used with `global_asm!`
322-
--> $DIR/parse-error.rs:130:28
310+
--> $DIR/parse-error.rs:128:28
323311
|
324312
LL | global_asm!("", options(), clobber_abi("C"));
325313
| ^^^^^^^^^^^^^^^^
326314

327315
error: `clobber_abi` cannot be used with `global_asm!`
328-
--> $DIR/parse-error.rs:132:30
316+
--> $DIR/parse-error.rs:130:30
329317
|
330318
LL | global_asm!("{}", options(), clobber_abi("C"), const FOO);
331319
| ^^^^^^^^^^^^^^^^
332320

333321
error: `clobber_abi` cannot be used with `global_asm!`
334-
--> $DIR/parse-error.rs:134:17
322+
--> $DIR/parse-error.rs:132:17
335323
|
336324
LL | global_asm!("", clobber_abi("C"), clobber_abi("C"));
337325
| ^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^
338326

339327
error: duplicate argument named `a`
340-
--> $DIR/parse-error.rs:136:35
328+
--> $DIR/parse-error.rs:134:35
341329
|
342330
LL | global_asm!("{a}", a = const FOO, a = const BAR);
343331
| ------------- ^^^^^^^^^^^^^ duplicate argument
344332
| |
345333
| previously here
346334

347335
error: argument never used
348-
--> $DIR/parse-error.rs:136:35
336+
--> $DIR/parse-error.rs:134:35
349337
|
350338
LL | global_asm!("{a}", a = const FOO, a = const BAR);
351339
| ^^^^^^^^^^^^^ argument never used
352340
|
353341
= help: if this argument is intentionally unused, consider using it in an asm comment: `"/* {1} */"`
354342

355343
error: expected one of `clobber_abi`, `const`, `options`, or `sym`, found `""`
356-
--> $DIR/parse-error.rs:139:28
344+
--> $DIR/parse-error.rs:137:28
357345
|
358346
LL | global_asm!("", options(), "");
359347
| ^^ expected one of `clobber_abi`, `const`, `options`, or `sym`
360348

361349
error: expected one of `clobber_abi`, `const`, `options`, or `sym`, found `"{}"`
362-
--> $DIR/parse-error.rs:141:30
350+
--> $DIR/parse-error.rs:139:30
363351
|
364352
LL | global_asm!("{}", const FOO, "{}", const FOO);
365353
| ^^^^ expected one of `clobber_abi`, `const`, `options`, or `sym`
366354

367355
error: asm template must be a string literal
368-
--> $DIR/parse-error.rs:143:13
356+
--> $DIR/parse-error.rs:141:13
369357
|
370358
LL | global_asm!(format!("{{{}}}", 0), const FOO);
371359
| ^^^^^^^^^^^^^^^^^^^^
372360
|
373361
= note: this error originates in the macro `format` (in Nightly builds, run with -Z macro-backtrace for more info)
374362

375363
error: asm template must be a string literal
376-
--> $DIR/parse-error.rs:145:20
364+
--> $DIR/parse-error.rs:143:20
377365
|
378366
LL | global_asm!("{1}", format!("{{{}}}", 0), const FOO, const BAR);
379367
| ^^^^^^^^^^^^^^^^^^^^
380368
|
381369
= note: this error originates in the macro `format` (in Nightly builds, run with -Z macro-backtrace for more info)
382370

383371
error: the `in` operand cannot be used with `global_asm!`
384-
--> $DIR/parse-error.rs:148:19
372+
--> $DIR/parse-error.rs:146:19
385373
|
386374
LL | global_asm!("{}", in(reg));
387375
| ^^ the `in` operand is not meaningful for global-scoped inline assembly, remove it
388376

389377
error: the `out` operand cannot be used with `global_asm!`
390-
--> $DIR/parse-error.rs:150:19
378+
--> $DIR/parse-error.rs:148:19
391379
|
392380
LL | global_asm!("{}", out(reg));
393381
| ^^^ the `out` operand is not meaningful for global-scoped inline assembly, remove it
394382

395383
error: the `lateout` operand cannot be used with `global_asm!`
396-
--> $DIR/parse-error.rs:152:19
384+
--> $DIR/parse-error.rs:150:19
397385
|
398386
LL | global_asm!("{}", lateout(reg));
399387
| ^^^^^^^ the `lateout` operand is not meaningful for global-scoped inline assembly, remove it
400388

401389
error: the `inout` operand cannot be used with `global_asm!`
402-
--> $DIR/parse-error.rs:154:19
390+
--> $DIR/parse-error.rs:152:19
403391
|
404392
LL | global_asm!("{}", inout(reg));
405393
| ^^^^^ the `inout` operand is not meaningful for global-scoped inline assembly, remove it
406394

407395
error: the `inlateout` operand cannot be used with `global_asm!`
408-
--> $DIR/parse-error.rs:156:19
396+
--> $DIR/parse-error.rs:154:19
409397
|
410398
LL | global_asm!("{}", inlateout(reg));
411399
| ^^^^^^^^^ the `inlateout` operand is not meaningful for global-scoped inline assembly, remove it
412400

413401
error: the `label` operand cannot be used with `global_asm!`
414-
--> $DIR/parse-error.rs:158:19
402+
--> $DIR/parse-error.rs:156:19
415403
|
416404
LL | global_asm!("{}", label(reg));
417405
| ^^^^^ the `label` operand is not meaningful for global-scoped inline assembly, remove it
@@ -476,6 +464,6 @@ LL - let mut bar = 0;
476464
LL + const bar: /* Type */ = 0;
477465
|
478466

479-
error: aborting due to 72 previous errors
467+
error: aborting due to 70 previous errors
480468

481469
For more information about this error, try `rustc --explain E0435`.

0 commit comments

Comments
 (0)