Skip to content

Commit ff7fabe

Browse files
committed
const closures
1 parent d50c8ef commit ff7fabe

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

text/0000-const-trait-impls.md

+10
Original file line numberDiff line numberDiff line change
@@ -836,3 +836,13 @@ Just like `const fn foo(x: impl ~const Trait) { x.method() }` and `const fn foo(
836836

837837
There is nothing design-wise blocking function pointers and calling them, they mainly require implementation work and extending the
838838
compiler's internal type system representation of a function signature to include constness.
839+
840+
## `const` closures
841+
842+
Closures need explicit opt-in to be callable in const contexts.
843+
You can already use closures in const contexts today to e.g. declare consts of function pointer type.
844+
So what we additionally need is some syntax like `const || {}` to declare a closure that implements
845+
`const Fn()`. See also [this tracking issue](https://github.com/rust-lang/project-const-traits/issues/10)
846+
While it may seem tempting to just automatically implement `const Fn()` (or `~const Fn()`) where applicable,
847+
it's not clear that this can be done, and there are definite situations where it can't be done.
848+
As further experimentation is needed here, const closures are not part of this RFC.

0 commit comments

Comments
 (0)