Repository: rust
Issue: using too many registers in asm!() produces confusing compiler errors
Labels: A-diagnostics,A-inline-assembly,T-compiler

```
rustc 1.59.0 (9d1b2106e 2022-02-23)
```

Here's an example of a program that uses too many registers on x86-64:

```rust
use std::arch::asm;

#[cfg(target_arch = "x86_64")]
fn main() {
    unsafe {
        asm!(
            "mov {o1}, 0",
            "mov {o2}, 0",
            "mov {o3}, 0",
            "mov {o4}, 0",
            "mov {o5}, 0",
            "mov {o6}, 0",
            "mov {o7}, 0",
            "mov {o8}, 0",
            "mov {o9}, 0",
            "mov {o10}, 0",
            "mov {o11}, 0",
            "mov {o12}, 0",
            "mov {o13}, 0",
            "mov {o14}, 0",
            "mov {o15}, 0",
            "mov {o16}, 0",
            o1 = out(reg) _,
            o2 = out(reg) _,
            o3 = out(reg) _,
            o4 = out(reg) _,
            o5 = out(reg) _,
            o6 = out(reg) _,
            o7 = out(reg) _,
            o8 = out(reg) _,
            o9 = out(reg) _,
            o10 = out(reg) _,
            o11 = out(reg) _,
            o12 = out(reg) _,
            o13 = out(reg) _,
            o14 = out(reg) _,
            o15 = out(reg) _,
            o16 = out(reg) _,
        );
    }
}
```

When I run `cargo build`, sometimes I get this output, which seems like what we want here:

```
error: inline assembly requires more registers than available

error: could not compile `scratch` due to previous error
```

But if I run `cargo build` over and over again, I see different output, seemingly at random. Sometimes I get this:

```
error: inline assembly requires more registers than available

error: invalid operand in inline asm: 'mov ${0:q}, 0
       mov ${1:q}, 0
       mov ${2:q}, 0
       mov ${3:q}, 0
       mov ${4:q}, 0
       mov ${5:q}, 0
       mov ${6:q}, 0
       mov ${7:q}, 0
       mov ${8:q}, 0
       mov ${9:q}, 0
       mov ${10:q}, 0
       mov ${11:q}, 0
       mov ${12:q}, 0
       mov ${13:q}, 0
       mov ${14:q}, 0
       mov ${15:q}, 0'

error: could not compile `scratch` due to 2 previous errors
```

Sometimes I also get this:

```
error: inline assembly requires more registers than available

error: invalid operand in inline asm: 'mov ${0:q}, 0
       mov ${1:q}, 0
       mov ${2:q}, 0
       mov ${3:q}, 0
       mov ${4:q}, 0
       mov ${5:q}, 0
       mov ${6:q}, 0
       mov ${7:q}, 0
       mov ${8:q}, 0
       mov ${9:q}, 0
       mov ${10:q}, 0
       mov ${11:q}, 0
       mov ${12:q}, 0
       mov ${13:q}, 0
       mov ${14:q}, 0
       mov ${15:q}, 0'

error: unknown token in expression
  --> src/main.rs:22:14
   |
22 |             "mov {o16}, 0",
   |              ^
   |
note: instantiated into assembly here
  --> <inline asm>:17:5
   |
17 | mov , 0
   |     ^

error: could not compile `scratch` due to 3 previous errors
```

In these latter two cases, the helpful error is still there at the top, but it's obscured by long diagnostics coming after that don't seem to make a lot of sense. Some artifact of how the assembler is invoked, maybe?