Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions tests/ui/traits/const-traits/const-closure-issue-125866-error.rs
Original file line number Diff line number Diff line change
@@ -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]);
}
Original file line number Diff line number Diff line change
@@ -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`.
25 changes: 25 additions & 0 deletions tests/ui/traits/const-traits/const-closure-issue-125866-pass.rs
Original file line number Diff line number Diff line change
@@ -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]);
}
13 changes: 13 additions & 0 deletions tests/ui/traits/const-traits/const-fn-trait-bound-issue-104314.rs
Original file line number Diff line number Diff line change
@@ -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() {}
Loading