about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>2018-02-06 09:52:56 +0100
committerOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>2018-03-08 08:34:16 +0100
commit1f9d846a5882dbdc4c599fa33e6256d2e37841a6 (patch)
tree592dc37fdae6d276074c28fa0f465fb473448516
parentb985399831b26e253e49e2e32fed1f657c8ca525 (diff)
downloadrust-1f9d846a5882dbdc4c599fa33e6256d2e37841a6.tar.gz
rust-1f9d846a5882dbdc4c599fa33e6256d2e37841a6.zip
Add some documentation to pattern/const conversions
-rw-r--r--src/librustc_mir/hair/pattern/mod.rs14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/librustc_mir/hair/pattern/mod.rs b/src/librustc_mir/hair/pattern/mod.rs
index d5dde0164fb..072b28850f0 100644
--- a/src/librustc_mir/hair/pattern/mod.rs
+++ b/src/librustc_mir/hair/pattern/mod.rs
@@ -667,6 +667,9 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
         }
     }
 
+    /// Takes a HIR Path. If the path is a constant, evaluates it and feeds
+    /// it to `const_to_pat`. Any other path (like enum variants without fields)
+    /// is converted to the corresponding pattern via `lower_variant_or_leaf`
     fn lower_path(&mut self,
                   qpath: &hir::QPath,
                   id: hir::HirId,
@@ -722,6 +725,10 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
         }
     }
 
+    /// Converts literals, paths and negation of literals to patterns.
+    /// The special case for negation exists to allow things like -128i8
+    /// which would overflow if we tried to evaluate 128i8 and then negate
+    /// afterwards.
     fn lower_lit(&mut self, expr: &'tcx hir::Expr) -> PatternKind<'tcx> {
         match expr.node {
             hir::ExprLit(ref lit) => {
@@ -767,6 +774,9 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
         }
     }
 
+    /// Converts an evaluated constant to a pattern (if possible).
+    /// This means aggregate values (like structs and enums) are converted
+    /// to a pattern that matches the value (as if you'd compare via eq).
     fn const_to_pat(
         &self,
         instance: ty::Instance<'tcx>,
@@ -844,14 +854,14 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
                     },
                     ConstVal::Unevaluated(..) =>
                         span_bug!(span, "{:#?} is not a valid enum constant", cv),
-                    }
+                }
             },
             ty::TyAdt(adt_def, _) => {
                 let struct_var = adt_def.non_enum_variant();
                 PatternKind::Leaf {
                     subpatterns: adt_subpatterns(struct_var.fields.len(), None),
-                        }
                 }
+            }
             ty::TyTuple(fields, _) => {
                 PatternKind::Leaf {
                     subpatterns: adt_subpatterns(fields.len(), None),