about summary refs log tree commit diff
diff options
context:
space:
mode:
authorZalathar <Zalathar@users.noreply.github.com>2024-07-12 12:31:39 +1000
committerZalathar <Zalathar@users.noreply.github.com>2024-07-14 15:01:02 +1000
commitf7508f881676a3e123245bcf99f9f0d21d4d6b49 (patch)
tree5d0f97fa25befd101d8ad610acaea4ddd4744bb6
parentce86b2ae962f3d6643153533d7bf722741d9e01f (diff)
downloadrust-f7508f881676a3e123245bcf99f9f0d21d4d6b49.tar.gz
rust-f7508f881676a3e123245bcf99f9f0d21d4d6b49.zip
Improve internal docs for `MatchPair`
-rw-r--r--compiler/rustc_mir_build/src/build/matches/match_pair.rs9
-rw-r--r--compiler/rustc_mir_build/src/build/matches/mod.rs20
2 files changed, 24 insertions, 5 deletions
diff --git a/compiler/rustc_mir_build/src/build/matches/match_pair.rs b/compiler/rustc_mir_build/src/build/matches/match_pair.rs
index a26b6d49aed..2f540478674 100644
--- a/compiler/rustc_mir_build/src/build/matches/match_pair.rs
+++ b/compiler/rustc_mir_build/src/build/matches/match_pair.rs
@@ -7,6 +7,11 @@ use crate::build::matches::{FlatPat, MatchPair, TestCase};
 use crate::build::Builder;
 
 impl<'a, 'tcx> Builder<'a, 'tcx> {
+    /// Builds and returns [`MatchPair`] trees, one for each pattern in
+    /// `subpatterns`, representing the fields of a [`PatKind::Variant`] or
+    /// [`PatKind::Leaf`].
+    ///
+    /// Used internally by [`MatchPair::new`].
     fn field_match_pairs<'pat>(
         &mut self,
         place: PlaceBuilder<'tcx>,
@@ -22,6 +27,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
             .collect()
     }
 
+    /// Builds [`MatchPair`] trees for the prefix/middle/suffix parts of an
+    /// array pattern or slice pattern, and adds those trees to `match_pairs`.
+    ///
+    /// Used internally by [`MatchPair::new`].
     fn prefix_slice_suffix<'pat>(
         &mut self,
         match_pairs: &mut Vec<MatchPair<'pat, 'tcx>>,
diff --git a/compiler/rustc_mir_build/src/build/matches/mod.rs b/compiler/rustc_mir_build/src/build/matches/mod.rs
index 7c655ecde02..98de4df3ce3 100644
--- a/compiler/rustc_mir_build/src/build/matches/mod.rs
+++ b/compiler/rustc_mir_build/src/build/matches/mod.rs
@@ -1196,17 +1196,27 @@ impl<'pat, 'tcx> TestCase<'pat, 'tcx> {
     }
 }
 
+/// Node in a tree of "match pairs", where each pair consists of a place to be
+/// tested, and a test to perform on that place.
+///
+/// Each node also has a list of subpairs (possibly empty) that must also match,
+/// and a reference to the THIR pattern it represents.
 #[derive(Debug, Clone)]
 pub(crate) struct MatchPair<'pat, 'tcx> {
     /// This place...
-    // This can be `None` if it referred to a non-captured place in a closure.
-    // Invariant: place.is_none() => test_case is Irrefutable
-    // In other words this must be `Some(_)` after simplification.
+    ///
+    /// ---
+    /// This can be `None` if it referred to a non-captured place in a closure.
+    ///
+    /// Invariant: Can only be `None` when `test_case` is `Irrefutable`.
+    /// Therefore this must be `Some(_)` after simplification.
     place: Option<Place<'tcx>>,
 
     /// ... must pass this test...
-    // Invariant: after creation and simplification in `Candidate::new()`, this must not be
-    // `Irrefutable`.
+    ///
+    /// ---
+    /// Invariant: after creation and simplification in [`FlatPat::new`],
+    /// this must not be [`TestCase::Irrefutable`].
     test_case: TestCase<'pat, 'tcx>,
 
     /// ... and these subpairs must match.