Skip to content

Commit bd37599

Browse files
RalfJungoli-obk
andauthored
Explain how patterns are compiled
Co-authored-by: Oliver Scherer <[email protected]>
1 parent c67ebb5 commit bd37599

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

patterns.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ fn is_foo(x: i32) -> bool {
1313
```
1414
However, that check has some loopholes, so e.g. `&T` can be used in a pattern no matter the `T`.
1515

16-
A const-pattern is compiled by [calling `PartialEq::eq`][compile-partial-eq] to compare the subject of the `match` with the constant,
17-
except for TODO where the constant is treated as if it was inlined as a pattern (and the usual `match` tree is constructed).
16+
Any reference type const-pattern is compiled by [calling `PartialEq::eq`][compile-partial-eq] to compare the subject of the `match` with the constant. Const-patterns with other types (enum, struct, tuple, array) are treated as if the constant was inlined as a pattern (and the usual `match` tree is constructed).
1817

1918
[struct-eq]: https://github.com/rust-lang/rust/blob/2c28244cf0fc9868f55070e55b8f332d196eaf3f/src/librustc_mir_build/hair/pattern/const_to_pat.rs#L121
2019
[compile-partial-eq]: https://github.com/rust-lang/rust/blob/2c28244cf0fc9868f55070e55b8f332d196eaf3f/src/librustc_mir_build/build/matches/test.rs#L355

0 commit comments

Comments
 (0)