Skip to content

Commit 23bab23

Browse files
committed
clarification; explicitly mention value-dependence already exists on stable
1 parent 74a1d9b commit 23bab23

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

text/0000-constants-in-patterns.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ That RFC is incomplete in several ways:
2828
[rfc-1445]: https://rust-lang.github.io/rfcs/1445-restrict-constants-in-patterns.html
2929

3030
RFC 1445 had the goal of leaving it open whether we want constants in patterns to be treated like sugar for primitive patterns or for `PartialEq`-based equality tests.
31-
This new RFC takes the stance it does based on the following main design goals:
31+
This new RFC takes the stance it does the former based on the following main design goals:
3232

3333
- Refactoring a pattern that has no binders, wildcards, or ranges into a constant should never change behavior.
3434
This aligns with the oft-repeated intuition that a constant works "as if" its value was just copy-pasted everywhere the constant is used.
@@ -97,6 +97,9 @@ enum MyEnum { GoodVariant(i32), NonStructuralVariant(NonStructuralEq) }
9797
const C: MyEnum = MyEnum::GoodVariant(0);
9898
```
9999

100+
This means the eligibility of a constant for a pattern depends on its value, not just on its type.
101+
That is already the case on stable Rust for many years and relied upon by widely-used crates such as [`http`](https://github.com/rust-lang/rust/issues/62411#issuecomment-510604193).
102+
100103
Overall we say that the *value* of the constant must have recursive structural equality,
101104
which is the case when all the types that actually appear recursively in the type (ignoring "other" enum variants) have structural equality.
102105

0 commit comments

Comments
 (0)