about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorJieyou Xu <jieyouxu@outlook.com>2025-09-11 09:06:56 +0800
committerJieyou Xu <jieyouxu@outlook.com>2025-09-11 09:09:31 +0800
commitfc58d8f5cce592998d0ba43b25e445eb6b96c827 (patch)
tree2a1c6557d6dff1e16ad3eccc8bcd856f6614f399 /tests
parentf4665ab8368ad2e8a86d4390ae35c28bdd9561bb (diff)
downloadrust-fc58d8f5cce592998d0ba43b25e445eb6b96c827.tar.gz
rust-fc58d8f5cce592998d0ba43b25e445eb6b96c827.zip
Add regression test for assert desugaring change
Using the MCVE reported in RUST-145770.
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/macros/assert-desugaring-145770.rs22
-rw-r--r--tests/ui/macros/assert-desugaring-145770.stderr14
2 files changed, 36 insertions, 0 deletions
diff --git a/tests/ui/macros/assert-desugaring-145770.rs b/tests/ui/macros/assert-desugaring-145770.rs
new file mode 100644
index 00000000000..9eb850f0380
--- /dev/null
+++ b/tests/ui/macros/assert-desugaring-145770.rs
@@ -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
+}
diff --git a/tests/ui/macros/assert-desugaring-145770.stderr b/tests/ui/macros/assert-desugaring-145770.stderr
new file mode 100644
index 00000000000..875ea8f7c32
--- /dev/null
+++ b/tests/ui/macros/assert-desugaring-145770.stderr
@@ -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`.