]> git.lizzy.rs Git - rust.git/commitdiff
Add some comments
authorvarkor <github@varkor.com>
Sun, 12 Aug 2018 10:43:42 +0000 (11:43 +0100)
committervarkor <github@varkor.com>
Thu, 16 Aug 2018 19:09:05 +0000 (20:09 +0100)
src/librustc_mir/hair/pattern/_match.rs
src/libsyntax/feature_gate.rs

index 60a8c89995a00b5b473746ef024af79b1659d7b3..00f7da4329100c505605b5181173428c1d4bae16 100644 (file)
@@ -303,7 +303,38 @@ struct PatternContext<'tcx> {
     max_slice_length: u64,
 }
 
-/// A stack of patterns in reverse order of construction
+/// A witness of non-exhaustiveness for error reporting, represented
+/// as a list of patterns (in reverse order of construction) with
+/// wildcards inside to represent elements that can take any inhabitant
+/// of the type as a value.
+///
+/// A witness against a list of patterns should have the same types
+/// and length as the pattern matched against. Because Rust `match`
+/// is always against a single pattern, at the end the witness will
+/// have length 1, but in the middle of the algorithm, it can contain
+/// multiple patterns.
+///
+/// For example, if we are constructing a witness for the match against
+/// ```
+/// struct Pair(Option<(u32, u32)>, bool);
+///
+/// match (p: Pair) {
+///    Pair(None, _) => {}
+///    Pair(_, false) => {}
+/// }
+/// ```
+///
+/// We'll perform the following steps:
+/// 1. Start with an empty witness
+///     `Witness(vec![])`
+/// 2. Push a witness `Some(_)` against the `None`
+///     `Witness(vec![Some(_)])`
+/// 3. Push a witness `true` against the `false`
+///     `Witness(vec![Some(_), true])`
+/// 4. Apply the `Pair` constructor to the witnesses
+///     `Witness(vec![Pair(Some(_), true)])`
+///
+/// The final `Pair(Some(_), true)` is then the resulting witness.
 #[derive(Clone, Debug)]
 pub struct Witness<'tcx>(Vec<Pattern<'tcx>>);
 
@@ -987,6 +1018,10 @@ pub fn is_useful<'p, 'a: 'p, 'tcx: 'a>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
                         } else {
                             pats.into_iter().flat_map(|witness| {
                                 missing_ctors.iter().map(move |ctor| {
+                                    // Extends the witness with a "wild" version of this
+                                    // constructor, that matches everything that can be built with
+                                    // it. For example, if `ctor` is a `Constructor::Variant` for
+                                    // `Option::Some`, this pushes the witness for `Some(_)`.
                                     witness.clone().push_wild_constructor(cx, ctor, pcx.ty)
                                 })
                             }).collect()
index 6109e5ecb61c09dabcce8531619149038fd9c82c..a6908619d73d374b0e594f052e9b4a7a7f8e84cb 100644 (file)
@@ -488,7 +488,7 @@ pub fn use_extern_macros(&self) -> bool {
     (active, label_break_value, "1.28.0", Some(48594), None),
 
     // Integer match exhaustiveness checking
-    (active, exhaustive_integer_patterns, "1.28.0", Some(50907), None),
+    (active, exhaustive_integer_patterns, "1.30.0", Some(50907), None),
 
     // #[panic_implementation]
     (active, panic_implementation, "1.28.0", Some(44489), None),