rust/src/test/ui/asm
Dylan DPC 19a90c7018
Rollup merge of #95553 - jam1garner:naked-function-compile-error, r=tmiasko
Don't emit non-asm contents error for naked function composed of errors

## Motivation

For naked functions an error is emitted when they are composed of anything other than a single asm!() block. However, this error triggers in a couple situations in which it adds no additional information or is actively misleading.

One example is if you do have an asm!() block but simply one with a syntax error:
```rust
#[naked]
unsafe extern "C" fn compiler_errors() {
    asm!(invalid_syntax)
}
```

This results in two errors, one for the syntax error itself and another telling you that you need an asm block in your function:

```rust
error[E0787]: naked functions must contain a single asm block
 --> src/main.rs:6:1
  |
6 | / unsafe extern "C" fn naked_compile_error() {
7 | |     asm!(blah)
8 | | }
  | |_^
```

This issue also comes up when [utilizing `compile_error!()` for improving your diagnostics](https://twitter.com/steveklabnik/status/1509538243020218372), such as raising a compiler error when compiling for an unsupported target.

## Implementation

The rules this PR implements are as follows:

1. If any non-erroneous  non-asm statement is included, an error will still occur
2. If multiple asm statements are included, an error will still occur
3. If 0 or 1 asm statements are present, as well as any non-zero number of erroneous statements, then this error will *not* be raised as it is likely either redundant or incorrect

The rule of thumb is effectively "if an error is present and its correction could change things, don't raise an error".
2022-04-03 23:21:42 +02:00
..
aarch64 Rollup merge of #91608 - workingjubilee:fold-neon-fp, r=nagisa,Amanieu 2022-03-23 03:05:28 +01:00
x86_64 Add needs-asm-support directive to tests where necessary 2022-03-21 18:48:24 +01:00
bad-arch.mirunsafeck.stderr Bless tests 2021-10-15 02:36:58 -05:00
bad-arch.rs Add tests where asm! is properly in unsafe block 2021-05-14 09:22:30 -04:00
bad-arch.thirunsafeck.stderr Bless tests 2021-10-15 02:36:58 -05:00
bad-template.aarch64_mirunsafeck.stderr Correctly mark the span of captured arguments in format_args!() 2022-02-16 07:34:06 +00:00
bad-template.aarch64_thirunsafeck.stderr Correctly mark the span of captured arguments in format_args!() 2022-02-16 07:34:06 +00:00
bad-template.rs Add features gates for experimental asm features 2021-11-07 01:23:53 +00:00
bad-template.x86_64_mirunsafeck.stderr Correctly mark the span of captured arguments in format_args!() 2022-02-16 07:34:06 +00:00
bad-template.x86_64_thirunsafeck.stderr Correctly mark the span of captured arguments in format_args!() 2022-02-16 07:34:06 +00:00
inline-syntax.arm.stderr Add needs-asm-support directive to tests where necessary 2022-03-21 18:48:24 +01:00
inline-syntax.rs Add needs-asm-support directive to tests where necessary 2022-03-21 18:48:24 +01:00
inline-syntax.x86_64.stderr Add needs-asm-support directive to tests where necessary 2022-03-21 18:48:24 +01:00
issue-72570.rs Stabilize asm! and global_asm! 2021-12-12 11:20:03 +00:00
issue-72570.stderr add test for #72960 2020-06-05 12:08:54 +02:00
issue-85247.rs Add tests 2022-02-21 18:28:22 +00:00
issue-85247.rwpi.stderr Add tests 2022-02-21 18:28:22 +00:00
issue-87802.rs Stabilize asm! and global_asm! 2021-12-12 11:20:03 +00:00
issue-87802.stderr Disable some tests for platforms without registers. 2021-09-24 17:00:57 +00:00
issue-89305.rs Stabilize asm! and global_asm! 2021-12-12 11:20:03 +00:00
issue-89305.stderr Stabilize asm! and global_asm! 2021-12-12 11:20:03 +00:00
issue-92378.rs Add needs-asm-support directive to tests where necessary 2022-03-21 18:48:24 +01:00
may_unwind.rs Stabilize asm! and global_asm! 2021-12-12 11:20:03 +00:00
naked-functions-ffi.rs Stabilize asm! and global_asm! 2021-12-12 11:20:03 +00:00
naked-functions-ffi.stderr Stabilize asm! and global_asm! 2021-12-12 11:20:03 +00:00
naked-functions-unused.aarch64.stderr Add needs-asm-support directive to tests where necessary 2022-03-21 18:48:24 +01:00
naked-functions-unused.rs Add needs-asm-support directive to tests where necessary 2022-03-21 18:48:24 +01:00
naked-functions-unused.x86_64.stderr Add needs-asm-support directive to tests where necessary 2022-03-21 18:48:24 +01:00
naked-functions.rs Add regression test for naked functions with invalid asm syntax 2022-04-01 12:24:04 -04:00
naked-functions.stderr Rollup merge of #95553 - jam1garner:naked-function-compile-error, r=tmiasko 2022-04-03 23:21:42 +02:00
naked-invalid-attr.rs Stabilize asm! and global_asm! 2021-12-12 11:20:03 +00:00
naked-invalid-attr.stderr Stabilize asm! and global_asm! 2021-12-12 11:20:03 +00:00
named-asm-labels.rs Stabilize asm! and global_asm! 2021-12-12 11:20:03 +00:00
named-asm-labels.s Fix lint capitalization and ignoring, test with include_str 2021-08-04 13:38:17 -04:00
named-asm-labels.stderr Add links to the reference and rust by example for asm! docs and lints 2022-01-19 20:00:10 +00:00
noreturn.rs Stabilize asm! and global_asm! 2021-12-12 11:20:03 +00:00
reg-conflict.rs Fix incorrect register conflict detection in asm! 2022-02-10 18:04:09 +00:00
reg-conflict.stderr Fix incorrect register conflict detection in asm! 2022-02-10 18:04:09 +00:00
type-check-1.rs Stabilize asm! and global_asm! 2021-12-12 11:20:03 +00:00
type-check-1.stderr Stabilize asm! and global_asm! 2021-12-12 11:20:03 +00:00
type-check-4.rs Stabilize asm! and global_asm! 2021-12-12 11:20:03 +00:00
type-check-4.stderr Bless tests 2021-10-15 02:36:58 -05:00