about summary refs log tree commit diff
path: root/compiler/rustc_pattern_analysis/src/pat.rs
diff options
context:
space:
mode:
authorNadrieril <nadrieril+git@gmail.com>2024-02-29 23:34:52 +0100
committerNadrieril <nadrieril+git@gmail.com>2024-03-11 04:37:21 +0100
commitc1e68860d0a66ddf261f7e512eaaa4ba4144b28a (patch)
treef71ccb6098cdfe0d96298af2827617846979f269 /compiler/rustc_pattern_analysis/src/pat.rs
parentcd81f5b27ee00b49d413db50b5e6af871cebcf23 (diff)
downloadrust-c1e68860d0a66ddf261f7e512eaaa4ba4144b28a.tar.gz
rust-c1e68860d0a66ddf261f7e512eaaa4ba4144b28a.zip
Store pattern arity in `DeconstructedPat`
Right now this is just `self.fields.len()` but that'll change in the
next commit. `arity` will be useful for the `Debug` impl.
Diffstat (limited to 'compiler/rustc_pattern_analysis/src/pat.rs')
-rw-r--r--compiler/rustc_pattern_analysis/src/pat.rs16
1 files changed, 14 insertions, 2 deletions
diff --git a/compiler/rustc_pattern_analysis/src/pat.rs b/compiler/rustc_pattern_analysis/src/pat.rs
index decbfa5c0cf..cd4f057c84c 100644
--- a/compiler/rustc_pattern_analysis/src/pat.rs
+++ b/compiler/rustc_pattern_analysis/src/pat.rs
@@ -26,6 +26,10 @@ impl PatId {
 pub struct DeconstructedPat<Cx: TypeCx> {
     ctor: Constructor<Cx>,
     fields: Vec<DeconstructedPat<Cx>>,
+    /// The number of fields in this pattern. E.g. if the pattern is `SomeStruct { field12: true, ..
+    /// }` this would be the total number of fields of the struct.
+    /// This is also the same as `self.ctor.arity(self.ty)`.
+    arity: usize,
     ty: Cx::Ty,
     /// Extra data to store in a pattern. `None` if the pattern is a wildcard that does not
     /// correspond to a user-supplied pattern.
@@ -36,16 +40,24 @@ pub struct DeconstructedPat<Cx: TypeCx> {
 
 impl<Cx: TypeCx> DeconstructedPat<Cx> {
     pub fn wildcard(ty: Cx::Ty) -> Self {
-        DeconstructedPat { ctor: Wildcard, fields: Vec::new(), ty, data: None, uid: PatId::new() }
+        DeconstructedPat {
+            ctor: Wildcard,
+            fields: Vec::new(),
+            arity: 0,
+            ty,
+            data: None,
+            uid: PatId::new(),
+        }
     }
 
     pub fn new(
         ctor: Constructor<Cx>,
         fields: Vec<DeconstructedPat<Cx>>,
+        arity: usize,
         ty: Cx::Ty,
         data: Cx::PatData,
     ) -> Self {
-        DeconstructedPat { ctor, fields, ty, data: Some(data), uid: PatId::new() }
+        DeconstructedPat { ctor, fields, arity, ty, data: Some(data), uid: PatId::new() }
     }
 
     pub(crate) fn is_or_pat(&self) -> bool {