Skip to content

Commit 48e023a

Browse files
dianneNadrieril
andauthored
Add comments explaining inherited references
This adds explanation of inherited references and how they relate to the default binding mode. Co-authored-by: Nadrieril <[email protected]>
1 parent 562c522 commit 48e023a

File tree

1 file changed

+5
-1
lines changed
  • compiler/rustc_hir_typeck/src

1 file changed

+5
-1
lines changed

compiler/rustc_hir_typeck/src/pat.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,10 @@ impl MutblCap {
215215
}
216216

217217
/// Variations on RFC 3627's Rule 4: when do reference patterns match against inherited references?
218+
///
219+
/// "Inherited reference" designates the `&`/`&mut` types that arise from using match ergonomics, i.e.
220+
/// from matching a reference type with a non-reference pattern. E.g. when `Some(x)` matches on
221+
/// `&mut Option<&T>`, `x` gets type `&mut &T` and the outer `&mut` is considered "inherited".
218222
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
219223
enum InheritedRefMatchRule {
220224
/// Reference patterns try to consume the inherited reference first.
@@ -223,7 +227,7 @@ enum InheritedRefMatchRule {
223227
/// Reference patterns consume inherited references if matching against a non-reference type.
224228
/// This assumes reference patterns can always match against an inherited reference.
225229
EatInner,
226-
/// Reference patterns consume both layers of reference.
230+
/// Reference patterns consume both layers of reference, i.e. reset the binding mode when consuming a reference type.
227231
/// Currently, this assumes the stable Rust behavior of not allowing reference patterns to eat
228232
/// an inherited reference alone. This will need an additional field or variant to represent the
229233
/// planned edition <= 2021 behavior of experimental match ergonomics, which does allow that.

0 commit comments

Comments
 (0)