rust/tests/ui/consts/control-flow
Esteban Küber c439a59dbd Change the desugaring of assert! for better error output
In the desugaring of `assert!`, we now expand to a `match` expression
instead of `if !cond {..}`.

The span of incorrect conditions will point only at the expression, and not
the whole `assert!` invocation.

```
error[E0308]: mismatched types
  --> $DIR/issue-14091.rs:2:13
   |
LL |     assert!(1,1);
   |             ^ expected `bool`, found integer
```

We no longer mention the expression needing to implement the `Not` trait.

```
error[E0308]: mismatched types
  --> $DIR/issue-14091-2.rs:15:13
   |
LL |     assert!(x, x);
   |             ^ expected `bool`, found `BytePos`
```

`assert!(val)` now desugars to:

```rust
match val {
    true => {},
    _ => $crate::panic::panic_2021!(),
}
```

Fix #122159.

We make some minor changes to some diagnostics to avoid span overlap on
type mismatch or inverted "expected"/"found" on type errors.

We remove some unnecessary parens from core, alloc and miri.

address review comments
2025-08-12 16:30:48 +00:00
..
assert.rs Use the informative error as the main const eval error message 2025-06-02 15:37:15 +00:00
assert.stderr Change the desugaring of assert! for better error output 2025-08-12 16:30:48 +00:00
basics.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
dead_branches_dont_eval.rs add test for #122301 to cover behavior that's on stable 2024-03-17 14:58:22 +01:00
drop-fail.precise.stderr Gate const drop behind const_destruct feature, and fix const_precise_live_drops post-drop-elaboration check 2024-11-22 16:54:40 +00:00
drop-fail.rs Gate const drop behind const_destruct feature, and fix const_precise_live_drops post-drop-elaboration check 2024-11-22 16:54:40 +00:00
drop-fail.stock.stderr Gate const drop behind const_destruct feature, and fix const_precise_live_drops post-drop-elaboration check 2024-11-22 16:54:40 +00:00
drop-pass.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
drop-precise.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
exhaustive-c-like-enum-match.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
feature-gate-const-if-match.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
interior-mutability.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
interior-mutability.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-46843.rs Note def descr in NonConstFunctionCall 2024-12-23 22:15:32 +00:00
issue-46843.stderr Note def descr in NonConstFunctionCall 2024-12-23 22:15:32 +00:00
issue-50577.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-50577.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
loop.rs Get rid of HIR const checker 2024-11-22 02:32:26 +00:00
loop.stderr Get rid of HIR const checker 2024-11-22 02:32:26 +00:00
short-circuit-let.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
short-circuit.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
single_variant_match_ice.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
try.rs Constify Try, From, TryFrom 2025-07-21 12:49:45 +03:00