Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syntax errors in assembly included from another file produce confusing output #91307

Open
ketsuban opened this issue Nov 28, 2021 · 0 comments
Open
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@ketsuban
Copy link
Contributor

The following is a sufficiently supported pattern in Rust to get a mention in the unstable book.

#![feature(global_asm)]
global_asm!(include_str!("something_neato.s"));

However, if the included assembly contains a syntax error (such as the ARM instruction push {r2, r3, r12, lr} - the solution* is to double the curly brackets to prevent the compiler from interpreting them as a template string) the error you get is somewhat confusing since it blames a seemingly arbitrary point potentially in a completely different source file from the actual error.

error: invalid asm template string: expected `'}'`, found `','`
  --> src\bit_utils.rs:36:18
   |
36 |   let mask = (((1_u64 << (H - L + 1)) - 1) << L) as u16;
   |               -  ^ expected `}` in asm template string
   |               |
   |               because of this opening brace
   |
  ::: src\lib.rs:6:13
   |
6  | global_asm!(include_str!("rt0.S"));
   |             --------------------- in this macro invocation
   |
   = note: if you intended to print `{`, you can escape it using `{{`

The correct error here would presumably look something like this.

error: invalid asm template string: expected `'}'`, found `','`
  --> src\rt0.S:98:12
   |
98 |   push  {r2, r3, r12, lr}
   |         -  ^ expected `}` in asm template string
   |         |
   |         because of this opening brace
   |
  ::: src\lib.rs:6:13
   |
6  | global_asm!(include_str!("rt0.S"));
   |             --------------------- in this macro invocation
   |
   = note: if you intended to print `{`, you can escape it using `{{`

This may be related to #81751 - I'm not familiar enough with compiler internals to say, so I erred on the side of posting a new issue.

*or at least a solution - another would be to special-case this pattern as unable to use template strings

@ketsuban ketsuban added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

1 participant