]> git.lizzy.rs Git - rust.git/commitdiff
Move comments for fake reads where the causes are defined
authorRemy Rakic <remy.rakic@gmail.com>
Fri, 14 Sep 2018 19:54:45 +0000 (21:54 +0200)
committerRemy Rakic <remy.rakic@gmail.com>
Tue, 18 Sep 2018 12:36:37 +0000 (14:36 +0200)
src/librustc/mir/mod.rs
src/librustc_mir/build/matches/mod.rs

index 8e9c1ad23c8643eb31391600140969491b6ce567..57aa2186927a91671e02abf985ddb2371029c5f2 100644 (file)
@@ -1667,7 +1667,25 @@ pub enum StatementKind<'tcx> {
 /// The `FakeReadCause` describes the type of pattern why a `FakeRead` statement exists.
 #[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug)]
 pub enum FakeReadCause {
+    /// Inject a fake read of the borrowed input at the start of each arm's
+    /// pattern testing code.
+    ///
+    /// This should ensure that you cannot change the variant for an enum
+    /// while you are in the midst of matching on it.
     ForMatch,
+
+    /// Officially, the semantics of
+    ///
+    /// `let pattern = <expr>;`
+    ///
+    /// is that `<expr>` is evaluated into a temporary and then this temporary is
+    /// into the pattern.
+    ///
+    /// However, if we see the simple pattern `let var = <expr>`, we optimize this to
+    /// evaluate `<expr>` directly into the variable `var`. This is mostly unobservable,
+    /// but in some cases it can affect the borrow checker, as in #53695.
+    /// Therefore, we insert a "fake read" here to ensure that we get
+    /// appropriate errors.
     ForLet,
 }
 
index 49c1308329f3c13d70cd2a6ba9931bd6f0bd4b46..c30dcdafdb40284ea2470600436e8e86aad92d5d 100644 (file)
@@ -145,19 +145,16 @@ pub fn match_expr(
                     if let (true, Some(borrow_temp)) =
                         (tcx.emit_read_for_match(), borrowed_input_temp.clone())
                     {
-                        // inject a fake read of the borrowed input at
-                        // the start of each arm's pattern testing
-                        // code.
-                        //
-                        // This should ensure that you cannot change
-                        // the variant for an enum while you are in
-                        // the midst of matching on it.
+                        // Inject a fake read, see comments on `FakeReadCause::ForMatch`.
                         let pattern_source_info = self.source_info(pattern.span);
                         self.cfg.push(
                             *pre_binding_block,
                             Statement {
                                 source_info: pattern_source_info,
-                                kind: StatementKind::FakeRead(FakeReadCause::ForMatch, borrow_temp.clone()),
+                                kind: StatementKind::FakeRead(
+                                    FakeReadCause::ForMatch,
+                                    borrow_temp.clone(),
+                                ),
                             },
                         );
                     }
@@ -266,19 +263,7 @@ pub fn expr_into_pattern(
                 unpack!(block = self.into(&place, block, initializer));
 
 
-                // Officially, the semantics of
-                //
-                // `let pattern = <expr>;`
-                //
-                // is that `<expr>` is evaluated into a temporary and then this temporary is
-                // into the pattern.
-                //
-                // However, if we see the simple pattern `let var = <expr>`, we optimize this to
-                // evaluate `<expr>` directly into the variable `var`. This is mostly unobservable,
-                // but in some cases it can affect the borrow checker, as in #53695.
-                // Therefore, we insert a "fake read" here to ensure that we get
-                // appropriate errors.
-                //
+                // Inject a fake read, see comments on `FakeReadCause::ForLet`.
                 let source_info = self.source_info(irrefutable_pat.span);
                 self.cfg.push(
                     block,
@@ -329,9 +314,7 @@ pub fn expr_into_pattern(
                     },
                 );
 
-                // Similarly to the `let var = <expr>` case, we insert a "fake read" here to
-                // ensure that we get appropriate errors when this usually unobservable
-                // optimization affects the borrow checker.
+                // Inject a fake read, see comments on `FakeReadCause::ForLet`.
                 self.cfg.push(
                     block,
                     Statement {