rust/compiler/rustc_passes/src
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
..
liveness Use iter::zip in compiler/ 2021-03-26 09:32:31 -07:00
check_attr.rs Merge impl_constness and is_const_fn_raw. 2022-03-31 18:33:46 +02:00
check_const.rs Spellchecking compiler comments 2022-03-30 15:14:15 -04:00
dead.rs Improve AdtDef interning. 2022-03-11 13:31:24 +11:00
diagnostic_items.rs use format-args-capture and remove unnecessary nested if blocks in some parts of rustc_passes 2022-03-22 00:02:18 +09:00
entry.rs use format-args-capture and remove unnecessary nested if blocks in some parts of rustc_passes 2022-03-22 00:02:18 +09:00
hir_id_validator.rs Replace NestedVisitorMap with NestedFilter 2022-01-16 16:02:36 -06:00
hir_stats.rs Auto merge of #87648 - JulianKnodt:const_eq_constrain, r=oli-obk 2022-01-18 09:58:39 +00:00
intrinsicck.rs use format-args-capture and remove unnecessary nested if blocks in some parts of rustc_passes 2022-03-22 00:02:18 +09:00
lang_items.rs Clean up lang_items::extract 2022-01-09 13:41:04 -08:00
layout_test.rs Remove in_band_lifetimes for rustc_passes 2021-12-15 20:12:53 -07:00
lib.rs 5 - Make more use of let_chains 2022-02-28 15:52:36 -03:00
lib_features.rs Handle rustc_const_stable attribute in library feature collector 2022-03-31 12:34:46 -07:00
liveness.rs rustc_error: make ErrorReported impossible to construct 2022-03-16 10:35:24 -05:00
loops.rs Replace NestedVisitorMap with NestedFilter 2022-01-16 16:02:36 -06:00
naked_functions.rs Rollup merge of #95553 - jam1garner:naked-function-compile-error, r=tmiasko 2022-04-03 23:21:42 +02:00
reachable.rs 5 - Make more use of let_chains 2022-02-28 15:52:36 -03:00
region.rs Rollup merge of #95497 - nyurik:compiler-spell-comments, r=compiler-errors 2022-03-31 04:57:28 +02:00
stability.rs Addressed comments by @compiler-errors and @bjorn3 2022-03-30 17:04:46 -04:00
upvars.rs Replace NestedVisitorMap with NestedFilter 2022-01-16 16:02:36 -06:00
weak_lang_items.rs Replace NestedVisitorMap with NestedFilter 2022-01-16 16:02:36 -06:00