about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorAriel Ben-Yehuda <ariel.byd@gmail.com>2017-05-15 17:13:12 +0300
committerAriel Ben-Yehuda <ariel.byd@gmail.com>2017-05-28 10:43:24 +0300
commit3bcd6fa5712520061fcc2504e1f0aae62c09e514 (patch)
treea106c166d8dc8c4209aa9db529a23ab12d109099 /src
parent68b7475dc04d4429d4bfb4837a902090915b6584 (diff)
downloadrust-3bcd6fa5712520061fcc2504e1f0aae62c09e514.tar.gz
rust-3bcd6fa5712520061fcc2504e1f0aae62c09e514.zip
use Eq instead of Lt in loop
Diffstat (limited to 'src')
-rw-r--r--src/librustc_mir/util/elaborate_drops.rs8
-rw-r--r--src/test/run-pass/issue-41888.rs43
2 files changed, 47 insertions, 4 deletions
diff --git a/src/librustc_mir/util/elaborate_drops.rs b/src/librustc_mir/util/elaborate_drops.rs
index 3ec27db60c2..c1d8d087eac 100644
--- a/src/librustc_mir/util/elaborate_drops.rs
+++ b/src/librustc_mir/util/elaborate_drops.rs
@@ -556,8 +556,8 @@ impl<'l, 'b, 'tcx, D> DropCtxt<'l, 'b, 'tcx, D>
     /// create a loop that drops an array:
     ///
     /// loop-block:
-    ///    can_go = index < len
-    ///    if can_go then drop-block else succ
+    ///    can_go = index == len
+    ///    if can_go then succ else drop-block
     /// drop-block:
     ///    ptr = &mut LV[index]
     ///    index = index + 1
@@ -604,13 +604,13 @@ impl<'l, 'b, 'tcx, D> DropCtxt<'l, 'b, 'tcx, D>
         let loop_block = self.elaborator.patch().new_block(BasicBlockData {
             statements: vec![
                 Statement { source_info: self.source_info, kind: StatementKind::Assign(
-                    can_go.clone(), Rvalue::BinaryOp(BinOp::Lt, use_(index), use_(length))
+                    can_go.clone(), Rvalue::BinaryOp(BinOp::Eq, use_(index), use_(length))
                 )},
             ],
             is_cleanup: unwind.is_cleanup(),
             terminator: Some(Terminator {
                 source_info: self.source_info,
-                kind: TerminatorKind::if_(tcx, use_(can_go), drop_block, succ)
+                kind: TerminatorKind::if_(tcx, use_(can_go), succ, drop_block)
             })
         });
 
diff --git a/src/test/run-pass/issue-41888.rs b/src/test/run-pass/issue-41888.rs
new file mode 100644
index 00000000000..e145cde039d
--- /dev/null
+++ b/src/test/run-pass/issue-41888.rs
@@ -0,0 +1,43 @@
+// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+fn main() { let _ = g(Some(E::F(K))); }
+
+type R = Result<(), ()>;
+struct K;
+
+enum E {
+    F(K), // must not be built-in type
+    #[allow(dead_code)]
+    G(Box<E>, Box<E>),
+}
+
+fn translate(x: R) -> R { x }
+
+fn g(mut status: Option<E>) -> R {
+    loop {
+        match status {
+            Some(infix_or_postfix) => match infix_or_postfix {
+                E::F(_op) => { // <- must be captured by value
+                    match Ok(()) {
+                        Err(err) => return Err(err),
+                        Ok(_) => {},
+                    };
+                }
+                _ => (),
+            },
+            _ => match translate(Err(())) {
+                Err(err) => return Err(err),
+                Ok(_) => {},
+            }
+        }
+        status = None;
+    }
+}