Skip to content

Commit

Permalink
unresolved question around matching in const fn
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Dec 29, 2023
1 parent ff2d059 commit 6b8cc0a
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion text/0000-constants-in-patterns.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,13 @@ This RFC came out of discussions in a [t-lang design meeting](https://github.com
# Unresolved questions
[unresolved-questions]: #unresolved-questions

None at this time.
- When a constant is used as a pattern in a `const fn`, what exactly should we require?
Writing `x == C` would *not* be possible here since calling trait methods like `partial_eq` is not possible in `const fn` currently.
In the future, writing `x == C` will likely require a `const impl PartialEq`.
So by allowing `match x { C => ... }`, we are allowing uses of `C` that would not otherwise be permitted, which is exactly what the `PartialEq` check was intended to avoid.
On the other hand, all this does is to allow at compile-time what could already be done at run-time, so maybe that's okay?
Rejecting this would definitely be a breaking change; we currently don't even lint against these cases.
Also see [this issue](https://github.com/rust-lang/rust/issues/119398).

# Future possibilities
[future-possibilities]: #future-possibilities
Expand Down

0 comments on commit 6b8cc0a

Please sign in to comment.