Skip to content

Commit 0263772

Browse files
committed
elaborate/clarify the comments on InheritedRefMatchRule's variants
1 parent bfa0e1e commit 0263772

File tree

1 file changed

+9
-8
lines changed
  • compiler/rustc_hir_typeck/src

1 file changed

+9
-8
lines changed

Diff for: compiler/rustc_hir_typeck/src/pat.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -221,16 +221,17 @@ impl MutblCap {
221221
/// `&mut Option<&T>`, `x` gets type `&mut &T` and the outer `&mut` is considered "inherited".
222222
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
223223
enum InheritedRefMatchRule {
224-
/// Reference patterns try to consume the inherited reference first.
225-
/// This assumes reference patterns can always match against an inherited reference.
224+
/// Reference patterns consume only the inherited reference if possible, regardless of whether
225+
/// the underlying type being matched against is a reference type. If there is no inherited
226+
/// reference, a reference will be consumed from the underlying type.
226227
EatOuter,
227-
/// Reference patterns consume inherited references if matching against a non-reference type.
228-
/// This assumes reference patterns can always match against an inherited reference.
228+
/// Reference patterns consume only a reference from the underlying type if possible. If the
229+
/// underlying type is not a reference type, the inherited reference will be consumed.
229230
EatInner,
230-
/// Reference patterns consume both layers of reference, i.e. reset the binding mode when consuming a reference type.
231-
/// Currently, this assumes the stable Rust behavior of not allowing reference patterns to eat
232-
/// an inherited reference alone. This will need an additional field or variant to represent the
233-
/// planned edition <= 2021 behavior of experimental match ergonomics, which does allow that.
231+
/// When the underlying type is a reference type, reference patterns consume both layers of
232+
/// reference, i.e. they both reset the binding mode and consume the reference type. Reference
233+
/// patterns are not permitted when there is no underlying reference type, i.e. they can't eat
234+
/// only an inherited reference. This is the current stable Rust behavior.
234235
EatBoth,
235236
}
236237

0 commit comments

Comments
 (0)