summaryrefslogtreecommitdiff
path: root/tools/mir_opt_test/tests/deborrow.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tools/mir_opt_test/tests/deborrow.rs')
-rw-r--r--tools/mir_opt_test/tests/deborrow.rs36
1 files changed, 36 insertions, 0 deletions
diff --git a/tools/mir_opt_test/tests/deborrow.rs b/tools/mir_opt_test/tests/deborrow.rs
new file mode 100644
index 00000000..10959aa3
--- /dev/null
+++ b/tools/mir_opt_test/tests/deborrow.rs
@@ -0,0 +1,36 @@
+//
+// Tests for the "de-borrow" class of optimisations (that try to remove useless borrows)
+//
+
+#[test="simple_exp"]
+fn simple(a: (i32,)) -> i32
+{
+ let b: &(i32,);
+ bb0: {
+ ASSIGN b = &a;
+ ASSIGN retval = b*.0;
+ } RETURN;
+}
+fn simple_exp(a: (i32,)) -> i32
+{
+ bb0: {
+ ASSIGN retval = a.0;
+ } RETURN;
+}
+
+// Should also work for mutable borrows
+#[test="simple_mut_exp"]
+fn simple_mut(a: (i32,)) -> i32
+{
+ let b: &mut (i32,);
+ bb0: {
+ ASSIGN b = &mut a;
+ ASSIGN retval = b*.0;
+ } RETURN;
+}
+fn simple_mut_exp(a: (i32,)) -> i32
+{
+ bb0: {
+ ASSIGN retval = a.0;
+ } RETURN;
+} \ No newline at end of file