Skip to content

Commit f7508f8

Browse files
committed
Improve internal docs for MatchPair
1 parent ce86b2a commit f7508f8

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

compiler/rustc_mir_build/src/build/matches/match_pair.rs

+9
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ use crate::build::matches::{FlatPat, MatchPair, TestCase};
77
use crate::build::Builder;
88

99
impl<'a, 'tcx> Builder<'a, 'tcx> {
10+
/// Builds and returns [`MatchPair`] trees, one for each pattern in
11+
/// `subpatterns`, representing the fields of a [`PatKind::Variant`] or
12+
/// [`PatKind::Leaf`].
13+
///
14+
/// Used internally by [`MatchPair::new`].
1015
fn field_match_pairs<'pat>(
1116
&mut self,
1217
place: PlaceBuilder<'tcx>,
@@ -22,6 +27,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
2227
.collect()
2328
}
2429

30+
/// Builds [`MatchPair`] trees for the prefix/middle/suffix parts of an
31+
/// array pattern or slice pattern, and adds those trees to `match_pairs`.
32+
///
33+
/// Used internally by [`MatchPair::new`].
2534
fn prefix_slice_suffix<'pat>(
2635
&mut self,
2736
match_pairs: &mut Vec<MatchPair<'pat, 'tcx>>,

compiler/rustc_mir_build/src/build/matches/mod.rs

+15-5
Original file line numberDiff line numberDiff line change
@@ -1196,17 +1196,27 @@ impl<'pat, 'tcx> TestCase<'pat, 'tcx> {
11961196
}
11971197
}
11981198

1199+
/// Node in a tree of "match pairs", where each pair consists of a place to be
1200+
/// tested, and a test to perform on that place.
1201+
///
1202+
/// Each node also has a list of subpairs (possibly empty) that must also match,
1203+
/// and a reference to the THIR pattern it represents.
11991204
#[derive(Debug, Clone)]
12001205
pub(crate) struct MatchPair<'pat, 'tcx> {
12011206
/// This place...
1202-
// This can be `None` if it referred to a non-captured place in a closure.
1203-
// Invariant: place.is_none() => test_case is Irrefutable
1204-
// In other words this must be `Some(_)` after simplification.
1207+
///
1208+
/// ---
1209+
/// This can be `None` if it referred to a non-captured place in a closure.
1210+
///
1211+
/// Invariant: Can only be `None` when `test_case` is `Irrefutable`.
1212+
/// Therefore this must be `Some(_)` after simplification.
12051213
place: Option<Place<'tcx>>,
12061214

12071215
/// ... must pass this test...
1208-
// Invariant: after creation and simplification in `Candidate::new()`, this must not be
1209-
// `Irrefutable`.
1216+
///
1217+
/// ---
1218+
/// Invariant: after creation and simplification in [`FlatPat::new`],
1219+
/// this must not be [`TestCase::Irrefutable`].
12101220
test_case: TestCase<'pat, 'tcx>,
12111221

12121222
/// ... and these subpairs must match.

0 commit comments

Comments
 (0)