You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: text/0000-constants-in-patterns.md
+2-3Lines changed: 2 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -276,12 +276,11 @@ None at this time.
276
276
+ Should `StructuralPartialEq` be an unsafe trait?
277
277
That trait has a clear semantic meaning, so making it `unsafe` to be able to rely on it for soundness is appealing.
278
278
In particular, we could then be *sure* that pattern matching always has the same semantics as `==`.
279
-
However, that would mean `forbid(unsafe_code)` crates could not `derive(PartialEq)` any more, which is clearly not acceptable.
280
-
As a consequence of `StructuralPartialEq` being safe, it is actually possible to write patterns that behave different from the `PartialEq` that is explicitly defined and intentionally exposed on that type,
279
+
With the trait being safe, it is actually possible to write patterns that behave different from the `PartialEq` that is explicitly defined and intentionally exposed on that type,
281
280
but only if one of the involved crates implements `StructuralPartialEq` incorrectly.
282
281
This can lead to semver issues and logic bugs, but that is all allowed for safe traits.
283
282
However, this also means unsafe code cannot rely on `==` and pattern matching having the same behavior.
284
-
One could consider doing some special magic to`derive(PartialEq)`to remain compatible with `forbid(unsafe_code)`, but that still seems suboptimal.
283
+
To make the trait unsafe, the logic for`derive(PartialEq)`should use `#[allow_internal_unsafe]` to still pass `forbid(unsafe_code)`.
285
284
+ What should the `StructuralPartialEq` trait be called?
286
285
The current name can be considered confusing because the trait reflects a shallow property, while the value-based check performed when a constant is used in a pattern is defined recursively.
287
286
+ Trait bounds `T: StructuralPartialEq` seem like a strange concept. Should we really allow them?
0 commit comments