Skip to content

Commit 8590388

Browse files
committed
mention allow_internal_unsafe in the unsafe trait possibility
1 parent 00657de commit 8590388

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

text/0000-constants-in-patterns.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,12 +276,11 @@ None at this time.
276276
+ Should `StructuralPartialEq` be an unsafe trait?
277277
That trait has a clear semantic meaning, so making it `unsafe` to be able to rely on it for soundness is appealing.
278278
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,
281280
but only if one of the involved crates implements `StructuralPartialEq` incorrectly.
282281
This can lead to semver issues and logic bugs, but that is all allowed for safe traits.
283282
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)`.
285284
+ What should the `StructuralPartialEq` trait be called?
286285
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.
287286
+ Trait bounds `T: StructuralPartialEq` seem like a strange concept. Should we really allow them?

0 commit comments

Comments
 (0)