Add regression test for assert desugaring change

Using the MCVE reported in RUST-145770.
This commit is contained in:
Jieyou Xu
2025-09-11 09:06:56 +08:00
parent f4665ab836
commit fc58d8f5cc
2 changed files with 36 additions and 0 deletions
@@ -0,0 +1,22 @@
//! Regression test for #145770.
//!
//! Changing the `assert!` desugaring from an `if !cond {}` to `match` expression is
//! backwards-incompatible, and may need to be done over an edition boundary or limit editions for
//! which the desguaring change impacts.
#[derive(Debug)]
struct F {
data: bool
}
impl std::ops::Not for F {
type Output = bool;
fn not(self) -> Self::Output { !self.data }
}
fn main() {
let f = F { data: true };
assert!(f);
//~^ ERROR mismatched types
}
@@ -0,0 +1,14 @@
error[E0308]: mismatched types
--> $DIR/assert-desugaring-145770.rs:20:11
|
LL | assert!(f);
| ^ expected `bool`, found `F`
|
help: you might have meant to use field `data` whose type is `bool`
|
LL | assert!(f.data);
| +++++
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0308`.