Skip to content

Commit a96d700

Browse files
committed
Clarifications suggested by varkor
1 parent 8956c1e commit a96d700

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

src/librustc_mir/hair/pattern/_match.rs

+17-15
Original file line numberDiff line numberDiff line change
@@ -720,23 +720,25 @@ impl<'tcx> Constructor<'tcx> {
720720
/// must have as many elements as this constructor's arity.
721721
///
722722
/// Examples:
723-
/// self: Single
724-
/// ty: tuple of 3 elements
725-
/// pats: [10, 20, _] => (10, 20, _)
723+
/// `self`: `Constructor::Single`
724+
/// `ty`: `(u32, u32, u32)`
725+
/// `pats`: `[10, 20, _]`
726+
/// returns `(10, 20, _)`
726727
///
727-
/// self: Option::Some
728-
/// ty: Option<bool>
729-
/// pats: [false] => Some(false)
728+
/// `self`: `Constructor::Variant(Option::Some)`
729+
/// `ty`: `Option<bool>`
730+
/// `pats`: `[false]`
731+
/// returns `Some(false)`
730732
fn apply<'a>(
731733
&self,
732734
cx: &MatchCheckCtxt<'a, 'tcx>,
733735
ty: Ty<'tcx>,
734736
pats: impl IntoIterator<Item = Pat<'tcx>>,
735737
) -> Pat<'tcx> {
736-
let mut pats = pats.into_iter();
738+
let mut subpatterns = pats.into_iter();
737739
let pat = match ty.kind {
738740
ty::Adt(..) | ty::Tuple(..) => {
739-
let pats = pats
741+
let subpatterns = subpatterns
740742
.enumerate()
741743
.map(|(i, p)| FieldPat { field: Field::new(i), pattern: p })
742744
.collect();
@@ -747,20 +749,20 @@ impl<'tcx> Constructor<'tcx> {
747749
adt_def: adt,
748750
substs,
749751
variant_index: self.variant_index_for_adt(cx, adt),
750-
subpatterns: pats,
752+
subpatterns,
751753
}
752754
} else {
753-
PatKind::Leaf { subpatterns: pats }
755+
PatKind::Leaf { subpatterns }
754756
}
755757
} else {
756-
PatKind::Leaf { subpatterns: pats }
758+
PatKind::Leaf { subpatterns }
757759
}
758760
}
759761

760-
ty::Ref(..) => PatKind::Deref { subpattern: pats.nth(0).unwrap() },
762+
ty::Ref(..) => PatKind::Deref { subpattern: subpatterns.nth(0).unwrap() },
761763

762764
ty::Slice(_) | ty::Array(..) => {
763-
PatKind::Slice { prefix: pats.collect(), slice: None, suffix: vec![] }
765+
PatKind::Slice { prefix: subpatterns.collect(), slice: None, suffix: vec![] }
764766
}
765767

766768
_ => match *self {
@@ -779,8 +781,8 @@ impl<'tcx> Constructor<'tcx> {
779781

780782
/// Like `apply`, but where all the subpatterns are wildcards `_`.
781783
fn apply_wildcards<'a>(&self, cx: &MatchCheckCtxt<'a, 'tcx>, ty: Ty<'tcx>) -> Pat<'tcx> {
782-
let pats = self.wildcard_subpatterns(cx, ty).rev();
783-
self.apply(cx, ty, pats)
784+
let subpatterns = self.wildcard_subpatterns(cx, ty).rev();
785+
self.apply(cx, ty, subpatterns)
784786
}
785787
}
786788

0 commit comments

Comments
 (0)