Add regression tests for seemingly fixed issues

This commit is contained in:
Shoyu Vanilla 2025-08-05 00:29:13 +09:00
parent e1b9081e69
commit 3e764d030a
4 changed files with 73 additions and 0 deletions

View file

@ -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]);
}

View file

@ -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`.

View file

@ -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]);
}

View file

@ -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() {}