about summary refs log tree commit diff
path: root/src/test/run-pass/for-loop-while/loop-break-value.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2018-09-27 23:46:21 +0000
committerbors <bors@rust-lang.org>2018-09-27 23:46:21 +0000
commit7d52cbce6db83e4fc2d8706b4e4b9c7da76cbcf8 (patch)
treebfe627dfa7d7ea762d9a4fb1ea238539eb798934 /src/test/run-pass/for-loop-while/loop-break-value.rs
parent8876906867b2db3c7177d69dd020c40d89177f86 (diff)
parent649b20eca9a5d2860eb46f6b9e1d99753d4515b7 (diff)
Auto merge of #54530 - pnkfelix:issue-54047-migrate-ui-run-pass-back-to-run-pass, r=alexcrichton
Migrate `src/test/ui/run-pass/*` back to `src/test/run-pass/`.

Moves all the tests from `src/test/ui/run-pass/**` back to `src/test/run-pass/`.

This should have no impact on our overall testing completeness due to PR #54223

Fix #54047
Diffstat (limited to 'src/test/run-pass/for-loop-while/loop-break-value.rs')
-rw-r--r--src/test/run-pass/for-loop-while/loop-break-value.rs148
1 files changed, 148 insertions, 0 deletions
diff --git a/src/test/run-pass/for-loop-while/loop-break-value.rs b/src/test/run-pass/for-loop-while/loop-break-value.rs
new file mode 100644
index 00000000000..2038df4e2a4
--- /dev/null
+++ b/src/test/run-pass/for-loop-while/loop-break-value.rs
@@ -0,0 +1,148 @@
+// Copyright 2016 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.
+
+// run-pass
+#![allow(unreachable_code)]
+#![feature(never_type)]
+
+#[allow(unused)]
+fn never_returns() {
+    loop {
+        break loop {};
+    }
+}
+
+pub fn main() {
+    let value = 'outer: loop {
+        if 1 == 1 {
+            break 13;
+        } else {
+            let _never: ! = loop {
+                break loop {
+                    break 'outer panic!();
+                }
+            };
+        }
+    };
+    assert_eq!(value, 13);
+
+    let x = [1, 3u32, 5];
+    let y = [17];
+    let z = [];
+    let coerced: &[_] = loop {
+        match 2 {
+            1 => break &x,
+            2 => break &y,
+            3 => break &z,
+            _ => (),
+        }
+    };
+    assert_eq!(coerced, &[17u32]);
+
+    let trait_unified = loop {
+        break if true {
+            break Default::default()
+        } else {
+            break [13, 14]
+        };
+    };
+    assert_eq!(trait_unified, [0, 0]);
+
+    let trait_unified_2 = loop {
+        if false {
+            break [String::from("Hello")]
+        } else {
+            break Default::default()
+        };
+    };
+    assert_eq!(trait_unified_2, [""]);
+
+    let trait_unified_3 = loop {
+        break if false {
+            break [String::from("Hello")]
+        } else {
+            ["Yes".into()]
+        };
+    };
+    assert_eq!(trait_unified_3, ["Yes"]);
+
+    let regular_break = loop {
+        if true {
+            break;
+        } else {
+            break break Default::default();
+        }
+    };
+    assert_eq!(regular_break, ());
+
+    let regular_break_2 = loop {
+        if true {
+            break Default::default();
+        } else {
+            break;
+        }
+    };
+    assert_eq!(regular_break_2, ());
+
+    let regular_break_3 = loop {
+        break if true {
+            Default::default()
+        } else {
+            break;
+        }
+    };
+    assert_eq!(regular_break_3, ());
+
+    let regular_break_4 = loop {
+        break ();
+        break;
+    };
+    assert_eq!(regular_break_4, ());
+
+    let regular_break_5 = loop {
+        break;
+        break ();
+    };
+    assert_eq!(regular_break_5, ());
+
+    let nested_break_value = 'outer2: loop {
+        let _a: u32 = 'inner: loop {
+            if true {
+                break 'outer2 "hello";
+            } else {
+                break 'inner 17;
+            }
+        };
+        panic!();
+    };
+    assert_eq!(nested_break_value, "hello");
+
+    let break_from_while_cond = loop {
+        'inner_loop: while break 'inner_loop {
+            panic!();
+        }
+        break 123;
+    };
+    assert_eq!(break_from_while_cond, 123);
+
+    let break_from_while_to_outer = 'outer_loop: loop {
+        while break 'outer_loop 567 {
+            panic!("from_inner");
+        }
+        panic!("from outer");
+    };
+    assert_eq!(break_from_while_to_outer, 567);
+
+    let rust = true;
+    let value = loop {
+        break rust;
+    };
+    assert!(value);
+}