about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2024-12-26 01:30:29 +0000
committerEsteban Küber <esteban@kuber.com.ar>2025-01-11 01:10:29 +0000
commit05c39438e295389e30a580a5376bbed83b1ddfa1 (patch)
tree3d33a0f134138ddd60b0e141d96bf6f52f0a307d /tests
parent760b6f8de4e10fed2a9a6aade810073296b1d5e9 (diff)
downloadrust-05c39438e295389e30a580a5376bbed83b1ddfa1.tar.gz
rust-05c39438e295389e30a580a5376bbed83b1ddfa1.zip
Account for `for<'a>` types when checking for non-structural type in constant as pattern
When we encounter a constant in a pattern, we check if it is non-structural. If so, we check if the type implements `PartialEq`, but for types with escaping bound vars the check would be incorrect as is, so we break early. This is ok because these types would be filtered anyways.

Fix #134764.
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/consts/const_in_pattern/non_structural_with_escaping_bounds.rs15
-rw-r--r--tests/ui/consts/const_in_pattern/non_structural_with_escaping_bounds.stderr15
2 files changed, 30 insertions, 0 deletions
diff --git a/tests/ui/consts/const_in_pattern/non_structural_with_escaping_bounds.rs b/tests/ui/consts/const_in_pattern/non_structural_with_escaping_bounds.rs
new file mode 100644
index 00000000000..e5d095fd617
--- /dev/null
+++ b/tests/ui/consts/const_in_pattern/non_structural_with_escaping_bounds.rs
@@ -0,0 +1,15 @@
+#![feature(structural_match)]
+impl<T: ?Sized> std::marker::StructuralPartialEq for O<T> { }
+
+enum O<T: ?Sized> {
+    Some(*const T),
+    None,
+}
+
+const C: O<dyn for<'a> Fn(Box<dyn Fn(&'a u8)>)> = O::None;
+
+fn main() {
+    match O::None {
+        C => (), //~ ERROR constant of non-structural type
+    }
+}
diff --git a/tests/ui/consts/const_in_pattern/non_structural_with_escaping_bounds.stderr b/tests/ui/consts/const_in_pattern/non_structural_with_escaping_bounds.stderr
new file mode 100644
index 00000000000..47378569084
--- /dev/null
+++ b/tests/ui/consts/const_in_pattern/non_structural_with_escaping_bounds.stderr
@@ -0,0 +1,15 @@
+error: constant of non-structural type `O<dyn for<'a> Fn(Box<dyn Fn(&'a u8)>)>` in a pattern
+  --> $DIR/non_structural_with_escaping_bounds.rs:13:9
+   |
+LL | const C: O<dyn for<'a> Fn(Box<dyn Fn(&'a u8)>)> = O::None;
+   | ----------------------------------------------- constant defined here
+...
+LL |         C => (),
+   |         ^ constant of non-structural type
+   |
+   = note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralPartialEq.html for details
+   = note: `std::alloc::Global` must be annotated with `#[derive(PartialEq)]` to be usable in patterns
+   = note: `std::alloc::Global` must be annotated with `#[derive(PartialEq)]` to be usable in patterns
+
+error: aborting due to 1 previous error
+