about summary refs log tree commit diff
path: root/tests/ui/expr
diff options
context:
space:
mode:
authorJubilee Young <workingjubilee@gmail.com>2024-05-19 16:11:46 -0700
committerJubilee Young <workingjubilee@gmail.com>2024-05-20 19:55:59 -0700
commitd89500843caf666998619bbc0c88d5857726963d (patch)
treea004fb459e4d686f805a5f22882fc10ed743b87c /tests/ui/expr
parent8e7517d99a8aaab02b512483ae91f8b79553fa3d (diff)
Move 100 entries from tests/ui into subdirs
- Move super-fast-paren-parsing test into ui/parser
- Move stmt_expr_attrs test into ui/feature-gates
- Move macro tests into ui/macros
- Move global_asm tests into ui/asm
- Move env tests into ui/process
- Move xcrate tests into ui/cross-crate
- Move unop tests into ui/unop
- Move backtrace tests into ui/backtrace
- Move check-static tests into ui/statics
- Move expr tests into ui/expr
- Move optimization fuel tests into ui/fuel
- Move ffi attribute tests into ui/ffi-attrs
- Move suggestion tests into ui/suggestions
- Move main tests into ui/fn-main
- Move lint tests into ui/lint
- Move repr tests into ui/repr
- Move intrinsics tests into ui/intrinsics
- Move tool lint tests into ui/tool-attributes
- Move return tests into ui/return
- Move pattern tests into ui/patttern
- Move range tests into ui/range
- Move foreign-fn tests into ui/foreign
- Move orphan-check tests into ui/coherence
- Move inference tests into ui/inference
- Reduce ROOT_ENTRY_LIMIT
Diffstat (limited to 'tests/ui/expr')
-rw-r--r--tests/ui/expr/block-fn.rs9
-rw-r--r--tests/ui/expr/block-generic.rs27
-rw-r--r--tests/ui/expr/block.rs18
-rw-r--r--tests/ui/expr/copy.rs18
-rw-r--r--tests/ui/expr/if-generic.rs29
-rw-r--r--tests/ui/expr/if-panic-all.rs11
-rw-r--r--tests/ui/expr/scope.rs7
7 files changed, 119 insertions, 0 deletions
diff --git a/tests/ui/expr/block-fn.rs b/tests/ui/expr/block-fn.rs
new file mode 100644
index 00000000000..1d3689eb4f3
--- /dev/null
+++ b/tests/ui/expr/block-fn.rs
@@ -0,0 +1,9 @@
+//@ run-pass
+
+fn test_fn() {
+    fn ten() -> isize { return 10; }
+    let rs = ten;
+    assert_eq!(rs(), 10);
+}
+
+pub fn main() { test_fn(); }
diff --git a/tests/ui/expr/block-generic.rs b/tests/ui/expr/block-generic.rs
new file mode 100644
index 00000000000..b36bda917d6
--- /dev/null
+++ b/tests/ui/expr/block-generic.rs
@@ -0,0 +1,27 @@
+//@ run-pass
+#![allow(unused_braces)]
+
+fn test_generic<T: Clone, F>(expected: T, eq: F) where F: FnOnce(T, T) -> bool {
+    let actual: T = { expected.clone() };
+    assert!(eq(expected, actual));
+}
+
+fn test_bool() {
+    fn compare_bool(b1: bool, b2: bool) -> bool { return b1 == b2; }
+    test_generic::<bool, _>(true, compare_bool);
+}
+
+#[derive(Clone)]
+struct Pair {
+    a: isize,
+    b: isize,
+}
+
+fn test_rec() {
+    fn compare_rec(t1: Pair, t2: Pair) -> bool {
+        t1.a == t2.a && t1.b == t2.b
+    }
+    test_generic::<Pair, _>(Pair {a: 1, b: 2}, compare_rec);
+}
+
+pub fn main() { test_bool(); test_rec(); }
diff --git a/tests/ui/expr/block.rs b/tests/ui/expr/block.rs
new file mode 100644
index 00000000000..bf626c9ead3
--- /dev/null
+++ b/tests/ui/expr/block.rs
@@ -0,0 +1,18 @@
+//@ run-pass
+#![allow(unused_braces)]
+#![allow(dead_code)]
+
+// Tests for standalone blocks as expressions
+
+fn test_basic() { let rs: bool = { true }; assert!((rs)); }
+
+struct RS { v1: isize, v2: isize }
+
+fn test_rec() { let rs = { RS {v1: 10, v2: 20} }; assert_eq!(rs.v2, 20); }
+
+fn test_filled_with_stuff() {
+    let rs = { let mut a = 0; while a < 10 { a += 1; } a };
+    assert_eq!(rs, 10);
+}
+
+pub fn main() { test_basic(); test_rec(); test_filled_with_stuff(); }
diff --git a/tests/ui/expr/copy.rs b/tests/ui/expr/copy.rs
new file mode 100644
index 00000000000..cfe47ff6d93
--- /dev/null
+++ b/tests/ui/expr/copy.rs
@@ -0,0 +1,18 @@
+//@ run-pass
+
+fn f(arg: &mut A) {
+    arg.a = 100;
+}
+
+#[derive(Copy, Clone)]
+struct A { a: isize }
+
+pub fn main() {
+    let mut x = A {a: 10};
+    f(&mut x);
+    assert_eq!(x.a, 100);
+    x.a = 20;
+    let mut y = x;
+    f(&mut y);
+    assert_eq!(x.a, 20);
+}
diff --git a/tests/ui/expr/if-generic.rs b/tests/ui/expr/if-generic.rs
new file mode 100644
index 00000000000..ed99ee63a51
--- /dev/null
+++ b/tests/ui/expr/if-generic.rs
@@ -0,0 +1,29 @@
+//@ run-pass
+
+fn test_generic<T, F>(expected: T, not_expected: T, eq: F) where
+    T: Clone,
+    F: FnOnce(T, T) -> bool,
+{
+    let actual: T = if true { expected.clone() } else { not_expected };
+    assert!(eq(expected, actual));
+}
+
+fn test_bool() {
+    fn compare_bool(b1: bool, b2: bool) -> bool { return b1 == b2; }
+    test_generic::<bool, _>(true, false, compare_bool);
+}
+
+#[derive(Clone)]
+struct Pair {
+    a: isize,
+    b: isize,
+}
+
+fn test_rec() {
+    fn compare_rec(t1: Pair, t2: Pair) -> bool {
+        t1.a == t2.a && t1.b == t2.b
+    }
+    test_generic::<Pair, _>(Pair{a: 1, b: 2}, Pair{a: 2, b: 3}, compare_rec);
+}
+
+pub fn main() { test_bool(); test_rec(); }
diff --git a/tests/ui/expr/if-panic-all.rs b/tests/ui/expr/if-panic-all.rs
new file mode 100644
index 00000000000..2ba2a36d165
--- /dev/null
+++ b/tests/ui/expr/if-panic-all.rs
@@ -0,0 +1,11 @@
+//@ run-pass
+// When all branches of an if expression result in panic, the entire if
+// expression results in panic.
+
+pub fn main() {
+    let _x = if true {
+        10
+    } else {
+        if true { panic!() } else { panic!() }
+    };
+}
diff --git a/tests/ui/expr/scope.rs b/tests/ui/expr/scope.rs
new file mode 100644
index 00000000000..57321ce2aa0
--- /dev/null
+++ b/tests/ui/expr/scope.rs
@@ -0,0 +1,7 @@
+//@ run-pass
+// Regression test for issue #762
+
+//@ pretty-expanded FIXME #23616
+
+pub fn f() { }
+pub fn main() { return ::f(); }