Skip to content

Add regression tests for seemingly fixed issues #144910

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 @@
//@ run-pass
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why run-pass?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original example code in the issue doesn't compile due to a missing [const] bound. I simply thought that it would be helpful to verify that it runs correctly once that’s fixed 😅
Would it make more sense to mark this with //@ check-pass instead?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did the ICE require codegen? If so build-pass is good, otherwise check-pass. But now this PR is in a rollup that may land soon, so let’s not modify this here.

Copy link
Member Author

@ShoyuVanilla ShoyuVanilla Aug 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since ICE happened before codegen, check-pass would be enough then. I'll fix this in another PR with other minor test fixes. Thanks for pointing this out!

Copy link
Member

@lqd lqd Aug 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok great, r me on the new PR then.


#![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