Skip to content

Commit e8414f1

Browse files
committed
add some links to code
1 parent 81a6b8e commit e8414f1

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

patterns.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Constants in patterns
22

3-
Constants that pass the [structural equality check](https://github.com/rust-lang/rust/issues/74446) can be used in patterns:
3+
Constants that pass the [structural equality check][struct-eq] can be used in patterns:
44
```rust
55
const FOO: i32 = 13;
66

@@ -13,9 +13,12 @@ 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` to compare the subject of the `match` with the constant,
16+
A const-pattern is compiled by [calling `PartialEq::eq`][compile-partial-eq] to compare the subject of the `match` with the constant,
1717
except for TODO where the constant is treated as if it was inlined as a pattern (and the usual `match` tree is constructed).
1818

19+
[struct-eq]: https://github.com/rust-lang/rust/blob/2c28244cf0fc9868f55070e55b8f332d196eaf3f/src/librustc_mir_build/hair/pattern/const_to_pat.rs#L121
20+
[compile-partial-eq]: https://github.com/rust-lang/rust/blob/2c28244cf0fc9868f55070e55b8f332d196eaf3f/src/librustc_mir_build/build/matches/test.rs#L355
21+
1922
## Soundness concerns
2023

2124
Most of the time there are no extra soundness concerns due to const-patterns; except for surprising behavior nothing can go wrong when the structural equality check gives a wrong answer.

0 commit comments

Comments
 (0)