Skip to content
/ rust Public
forked from rust-lang/rust

Commit 2b2f28d

Browse files
committed
Add regression test
1 parent ca9a134 commit 2b2f28d

2 files changed

Lines changed: 48 additions & 0 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#![feature(const_closures, const_destruct, const_trait_impl)]
2+
3+
use std::marker::Destruct;
4+
use std::num::NonZero;
5+
6+
const trait T {
7+
fn a(&mut self, f: impl [const] Fn() + [const] Destruct);
8+
fn b(&mut self);
9+
}
10+
11+
struct S;
12+
13+
impl const T for S {
14+
fn a(&mut self, f: impl [const] Fn() + [const] Destruct) {
15+
f()
16+
}
17+
18+
fn b(&mut self) {
19+
self.a(const || {});
20+
//~^ ERROR: cannot use `const` closures outside of const contexts
21+
//~| ERROR: [const] Fn()` is not satisfied
22+
}
23+
}
24+
25+
fn main() {}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
error: cannot use `const` closures outside of const contexts
2+
--> $DIR/const-closure-in-trait-impl.rs:19:16
3+
|
4+
LL | self.a(const || {});
5+
| ^^^^^
6+
7+
error[E0277]: the trait bound `{closure@$DIR/const-closure-in-trait-impl.rs:19:16: 19:24}: [const] Fn()` is not satisfied
8+
--> $DIR/const-closure-in-trait-impl.rs:19:16
9+
|
10+
LL | self.a(const || {});
11+
| - ^^^^^^^^^^^
12+
| |
13+
| required by a bound introduced by this call
14+
|
15+
note: required by a bound in `T::a`
16+
--> $DIR/const-closure-in-trait-impl.rs:7:29
17+
|
18+
LL | fn a(&mut self, f: impl [const] Fn() + [const] Destruct);
19+
| ^^^^^^^^^^^^ required by this bound in `T::a`
20+
21+
error: aborting due to 2 previous errors
22+
23+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)