about summary refs log tree commit diff
diff options
context:
space:
mode:
authorShoyu Vanilla <modulo641@gmail.com>2025-08-05 00:29:13 +0900
committerShoyu Vanilla <modulo641@gmail.com>2025-08-05 22:29:49 +0900
commit3e764d030a2a62066532c940e3509e7e031d71bf (patch)
tree08adef6f15b61a85c0d6aea6f236380ac90fe04d
parente1b9081e699065badfc1a9419ec9566e5c8615c4 (diff)
downloadrust-3e764d030a2a62066532c940e3509e7e031d71bf.tar.gz
rust-3e764d030a2a62066532c940e3509e7e031d71bf.zip
Add regression tests for seemingly fixed issues
-rw-r--r--tests/ui/traits/const-traits/const-closure-issue-125866-error.rs24
-rw-r--r--tests/ui/traits/const-traits/const-closure-issue-125866-error.stderr11
-rw-r--r--tests/ui/traits/const-traits/const-closure-issue-125866-pass.rs25
-rw-r--r--tests/ui/traits/const-traits/const-fn-trait-bound-issue-104314.rs13
4 files changed, 73 insertions, 0 deletions
diff --git a/tests/ui/traits/const-traits/const-closure-issue-125866-error.rs b/tests/ui/traits/const-traits/const-closure-issue-125866-error.rs
new file mode 100644
index 00000000000..7a44920bb72
--- /dev/null
+++ b/tests/ui/traits/const-traits/const-closure-issue-125866-error.rs
@@ -0,0 +1,24 @@
+#![allow(incomplete_features)]
+#![feature(const_closures, const_trait_impl)]
+
+const fn create_array<const N: usize>(mut f: impl FnMut(usize) -> u32 + Copy) -> [u32; N] {
+    let mut array = [0; N];
+    let mut i = 0;
+    loop {
+        array[i] = f(i);
+        //~^ ERROR the trait bound `impl FnMut(usize) -> u32 + Copy: [const] FnMut(usize)` is not satisfied [E0277]
+        i += 1;
+        if i == N {
+            break;
+        }
+    }
+    array
+}
+
+fn main() {
+    let x = create_array(const |i| 2 * i as u32);
+    assert_eq!(x, [0, 2, 4, 6, 8]);
+
+    let y = create_array(const |i| 2 * i as u32 + 1);
+    assert_eq!(y, [1, 3, 5, 7, 9]);
+}
diff --git a/tests/ui/traits/const-traits/const-closure-issue-125866-error.stderr b/tests/ui/traits/const-traits/const-closure-issue-125866-error.stderr
new file mode 100644
index 00000000000..1eadd1d8426
--- /dev/null
+++ b/tests/ui/traits/const-traits/const-closure-issue-125866-error.stderr
@@ -0,0 +1,11 @@
+error[E0277]: the trait bound `impl FnMut(usize) -> u32 + Copy: [const] FnMut(usize)` is not satisfied
+  --> $DIR/const-closure-issue-125866-error.rs:8:22
+   |
+LL |         array[i] = f(i);
+   |                    - ^
+   |                    |
+   |                    required by a bound introduced by this call
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/tests/ui/traits/const-traits/const-closure-issue-125866-pass.rs b/tests/ui/traits/const-traits/const-closure-issue-125866-pass.rs
new file mode 100644
index 00000000000..af7375172e6
--- /dev/null
+++ b/tests/ui/traits/const-traits/const-closure-issue-125866-pass.rs
@@ -0,0 +1,25 @@
+//@ check-pass
+
+#![allow(incomplete_features)]
+#![feature(const_closures, const_trait_impl)]
+
+const fn create_array<const N: usize>(mut f: impl [const] FnMut(usize) -> u32 + Copy) -> [u32; N] {
+    let mut array = [0; N];
+    let mut i = 0;
+    loop {
+        array[i] = f(i);
+        i += 1;
+        if i == N {
+            break;
+        }
+    }
+    array
+}
+
+fn main() {
+    let x = create_array(const |i| 2 * i as u32);
+    assert_eq!(x, [0, 2, 4, 6, 8]);
+
+    let y = create_array(const |i| 2 * i as u32 + 1);
+    assert_eq!(y, [1, 3, 5, 7, 9]);
+}
diff --git a/tests/ui/traits/const-traits/const-fn-trait-bound-issue-104314.rs b/tests/ui/traits/const-traits/const-fn-trait-bound-issue-104314.rs
new file mode 100644
index 00000000000..09c89c9cecd
--- /dev/null
+++ b/tests/ui/traits/const-traits/const-fn-trait-bound-issue-104314.rs
@@ -0,0 +1,13 @@
+//@ check-pass
+
+#![feature(const_trait_impl, const_destruct, const_clone)]
+
+use std::marker::Destruct;
+
+const fn f<T, F: [const] Fn(&T) -> T + [const] Destruct>(_: F) {}
+
+const fn g<T: [const] Clone>() {
+    f(<T as Clone>::clone);
+}
+
+fn main() {}