Stuart Cook 1eeb8e8b15
Rollup merge of #122661 - estebank:assert-macro-span, r=petrochenkov
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`
```

Now `assert!(val)` desugars to:

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

Fix #122159.
2025-08-15 16:16:29 +10:00
..
2025-07-21 12:49:45 +03:00
2025-07-08 14:36:43 +00:00
2025-07-13 13:50:01 +00:00
2025-07-21 09:11:21 +00:00
2025-07-21 09:11:21 +00:00
2025-08-05 19:34:46 +05:00
2025-06-13 09:20:48 +02:00
2025-06-13 09:20:48 +02:00