Skip to content

Commit 812b1de

Browse files
committed
ref_pat_eat_one_layer_2024: add context and examples to the unstable book
1 parent f04bbc6 commit 812b1de

File tree

2 files changed

+47
-6
lines changed

2 files changed

+47
-6
lines changed

Diff for: src/doc/unstable-book/src/language-features/ref-pat-eat-one-layer-2024-structural.md

+23-3
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,32 @@ The tracking issue for this feature is: [#123076]
99
This feature is incomplete and not yet intended for general use.
1010

1111
This implements experimental, Edition-dependent match ergonomics under consideration for inclusion
12-
in Rust.
13-
For more information, see the corresponding typing rules for [Editions 2021 and earlier] and for
14-
[Editions 2024 and later].
12+
in Rust, allowing `&` patterns in more places. For example:
13+
```rust,edition2024
14+
#![feature(ref_pat_eat_one_layer_2024_structural)]
15+
#![allow(incomplete_features)]
16+
#
17+
# // Tests type equality in a way that avoids coercing `&&T` or `&mut T` to `&T`.
18+
# trait Eq<T> {}
19+
# impl<T> Eq<T> for T {}
20+
# fn has_type<T>(_: impl Eq<T>) {}
21+
22+
// `&` can match against a `ref` binding mode instead of a reference type:
23+
let (x, &y) = &(0, 1);
24+
has_type::<&u8>(x);
25+
has_type::<u8>(y);
26+
27+
// `&` can match against `&mut` references:
28+
let &z = &mut 2;
29+
has_type::<u8>(z);
30+
```
31+
32+
For specifics, see the corresponding typing rules for [Editions 2021 and earlier] and for
33+
[Editions 2024 and later]. For more information on binding modes, see [The Rust Reference].
1534

1635
For alternative experimental match ergonomics, see the feature
1736
[`ref_pat_eat_one_layer_2024`](./ref-pat-eat-one-layer-2024.md).
1837

1938
[Editions 2021 and earlier]: https://nadrieril.github.io/typing-rust-patterns/?compare=false&opts1=AQEBAQIBAQEBAAAAAAAAAAAAAAAAAAA%3D&mode=rules&do_cmp=false
2039
[Editions 2024 and later]: https://nadrieril.github.io/typing-rust-patterns/?compare=false&opts1=AQEBAgEBAQEBAgIAAAAAAAAAAAAAAAA%3D&mode=rules&do_cmp=false
40+
[The Rust Reference]: https://doc.rust-lang.org/reference/patterns.html#binding-modes

Diff for: src/doc/unstable-book/src/language-features/ref-pat-eat-one-layer-2024.md

+24-3
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,33 @@ The tracking issue for this feature is: [#123076]
99
This feature is incomplete and not yet intended for general use.
1010

1111
This implements experimental, Edition-dependent match ergonomics under consideration for inclusion
12-
in Rust.
13-
For more information, see the corresponding typing rules for [Editions 2021 and earlier] and for
14-
[Editions 2024 and later].
12+
in Rust, allowing `&` patterns in more places. For example:
13+
14+
```rust,edition2024
15+
#![feature(ref_pat_eat_one_layer_2024)]
16+
#![allow(incomplete_features)]
17+
#
18+
# // Tests type equality in a way that avoids coercing `&&T` or `&mut T` to `&T`.
19+
# trait Eq<T> {}
20+
# impl<T> Eq<T> for T {}
21+
# fn has_type<T>(_: impl Eq<T>) {}
22+
23+
// `&` can match against a `ref` binding mode instead of a reference type:
24+
let (x, &y) = &(0, 1);
25+
has_type::<&u8>(x);
26+
has_type::<u8>(y);
27+
28+
// `&` can match against `&mut` references:
29+
let &z = &mut 2;
30+
has_type::<u8>(z);
31+
```
32+
33+
For specifics, see the corresponding typing rules for [Editions 2021 and earlier] and for
34+
[Editions 2024 and later]. For more information on binding modes, see [The Rust Reference].
1535

1636
For alternative experimental match ergonomics, see the feature
1737
[`ref_pat_eat_one_layer_2024_structural`](./ref-pat-eat-one-layer-2024-structural.md).
1838

1939
[Editions 2021 and earlier]: https://nadrieril.github.io/typing-rust-patterns/?compare=false&opts1=AQEBAQIBAQABAAAAAQEBAAEBAAABAAA%3D&mode=rules&do_cmp=false
2040
[Editions 2024 and later]: https://nadrieril.github.io/typing-rust-patterns/?compare=false&opts1=AQEBAAABAQABAgIAAQEBAAEBAAABAAA%3D&mode=rules&do_cmp=false
41+
[The Rust Reference]: https://doc.rust-lang.org/reference/patterns.html#binding-modes

0 commit comments

Comments
 (0)