Add regression test

This commit is contained in:
Oli Scherer
2026-04-25 09:47:07 +02:00
parent ca9a134e09
commit 2b2f28d0ea
2 changed files with 48 additions and 0 deletions
@@ -0,0 +1,25 @@
#![feature(const_closures, const_destruct, const_trait_impl)]
use std::marker::Destruct;
use std::num::NonZero;
const trait T {
fn a(&mut self, f: impl [const] Fn() + [const] Destruct);
fn b(&mut self);
}
struct S;
impl const T for S {
fn a(&mut self, f: impl [const] Fn() + [const] Destruct) {
f()
}
fn b(&mut self) {
self.a(const || {});
//~^ ERROR: cannot use `const` closures outside of const contexts
//~| ERROR: [const] Fn()` is not satisfied
}
}
fn main() {}
@@ -0,0 +1,23 @@
error: cannot use `const` closures outside of const contexts
--> $DIR/const-closure-in-trait-impl.rs:19:16
|
LL | self.a(const || {});
| ^^^^^
error[E0277]: the trait bound `{closure@$DIR/const-closure-in-trait-impl.rs:19:16: 19:24}: [const] Fn()` is not satisfied
--> $DIR/const-closure-in-trait-impl.rs:19:16
|
LL | self.a(const || {});
| - ^^^^^^^^^^^
| |
| required by a bound introduced by this call
|
note: required by a bound in `T::a`
--> $DIR/const-closure-in-trait-impl.rs:7:29
|
LL | fn a(&mut self, f: impl [const] Fn() + [const] Destruct);
| ^^^^^^^^^^^^ required by this bound in `T::a`
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0277`.