Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More examples 2 #22

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions test-files/80_conditional_field_drop.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
struct T {}
struct S {f: T, g: T}
fn test(b: bool) {
let mut s = S {f: T{}, g: T{}};
if b {
drop(s.f);
}
}
fn main(){}
32 changes: 32 additions & 0 deletions test-files/81_coupling_triangle.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
struct T {}
fn test(cond: bool) {
let mut x = T {};
let mut y = T {};
let x1: &mut T;
let y1: &mut T;
let mut a: &mut T;
let mut b: &mut T;
let mut c: &mut T;
if cond {
b = &mut x;
a = &mut (*b);
x1 = &mut (*a);
c = &mut y;
y1 = &mut c;
// x1 -> a -> b -> x
// y1 -> c -> y
} else {
a = &mut x;
c = &mut a;
x1 = &mut c;
b = &mut y;
y1 = &mut b;
// x1 -> c -> a -> x
// y1 -> b -> y
}
let test_x1 = x1;
let test_y1 = y1;
let test_x = x;
let test_y = y;
}
fn main() {}
39 changes: 39 additions & 0 deletions test-files/82_coupling_square_right.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
struct T {}
fn test(cond: bool) {
let mut x = T {};
let mut y = T {};
let x1: &mut T;
let y1: &mut T;
let mut a: &mut T;
let mut b: &mut T;
let mut c: &mut T;
let mut d: &mut T;
if cond {
b = &mut x;
a = &mut (*b);
x1 = &mut (*a);
d = &mut y;
c = &mut d;
y1 = &mut c;
// x1 -> a -> b -> x
// y1 -> c -> d -> y
} else {
a = &mut x;
c = &mut a;
x1 = &mut c;
b = &mut y;
d = &mut b;
y1 = &mut d;
// x1 -> c -> a -> x
// y1 -> d -> b -> y
}
let test_x1 = x1;
let test_y1 = y1;
let test_c = c;
let test_a = a;
let test_d = d;
let test_b = b;
let test_x = x;
let test_y = y;
}
fn main() {}
35 changes: 35 additions & 0 deletions test-files/83_coupling_square_left.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
struct T {}
fn test(cond: bool) {
let mut x = T {};
let mut y = T {};
let x1: &mut T;
let y1: &mut T;
let mut a: &mut T;
let mut b: &mut T;
let mut c: &mut T;
let mut d: &mut T;
if cond {
b = &mut x;
a = &mut (*b);
x1 = &mut (*a);
d = &mut y;
c = &mut d;
y1 = &mut c;
// x1 -> a -> b -> x
// y1 -> c -> d -> y
} else {
c = &mut x;
a = &mut c;
x1 = &mut a;
d = &mut y;
b = &mut d;
y1 = &mut b;
// x1 -> a -> c -> x
// y1 -> b -> d -> y
}
let test_x1 = x1;
let test_y1 = y1;
let test_x = x;
let test_y = y;
}
fn main() {}
27 changes: 27 additions & 0 deletions test-files/84_coupling_triangle_simple.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
struct T {}
fn test(cond: bool) {
let mut x = T {};
let mut y = T {};
let mut a: &mut T;
let x1: &mut T;
let y1: &mut T;
let mut a: &mut T;
if cond {
a = &mut x;
x1 = &mut (*a);
y1 = &mut y;
// x1 -> a -> x
// y1 -> y
} else {
a = &mut y;
x1 = &mut x;
y1 = &mut (*a);
// x1 -> x
// y1 -> a -> y
}
let test_x1 = x1;
let test_y1 = y1;
let test_x = x;
let test_y = y;
}
fn main() {}
11 changes: 11 additions & 0 deletions test-files/85_conditional_reassign_borrow.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
struct T {}
fn main () {}
fn test(b: bool) {
let t0 = T {};
let t1 = T {};
let mut x = &t0;
if b {
x = &t1;
}
let test_x = x;
}
10 changes: 10 additions & 0 deletions test-files/86_iterated_borrow.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
struct T {}
fn main () {}
fn test(b: bool) {
let mut t = T {};
let mut x : &mut T = &mut t;
let y : &mut (&mut T) = &mut x;
let test_y = y;
let test_x = x;
let test_t = t;
}
21 changes: 21 additions & 0 deletions test-files/87_function_w_reborrow.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
struct T{}
fn f<'a, 'b, 'c, 'd, 'e, 'f>(x: &'a mut T, y: &'b mut T, z: &'c mut T) -> (&'d mut T, &'e mut T)
where 'a: 'd, 'b: 'd, 'b: 'e, 'c: 'e
{ todo!() }
fn main() {
let mut t1 = T {};
let mut t2 = T {};
let mut t3 = T {};
let mut x = &mut t1;
let mut y = &mut t2;
let mut z = &mut t3;
let (r1, r2) = f(x, y, z);
let test_r1 = r1;
let test_r2 = r2;
let test_x = x;
let test_y = y;
let test_z = z;
let test_t1 = t1;
let test_t2 = t2;
let test_t3 = t3;
}
11 changes: 11 additions & 0 deletions test-files/88_impossible_function.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
struct T {}
fn f<'b, 'a: 'b>(t: &'b mut T) -> &'a mut T { panic!(); }
fn main() {
let mut t = T {};
let u = &mut t;
let v = f(u);
/* can use u and v in any order here */
let test_v = v;
let test_u = u;
let test_t = t;
}
32 changes: 32 additions & 0 deletions test-files/89_iterated_borrow_invariant.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
struct T {}
fn main () {}
fn test() {
let mut t = T {};
let mut x : &mut T = &mut t;
let mut y : &mut (&mut T) = &mut x;

let mut t1 = T {};
let mut x1 : &mut T = &mut t1;
let mut y1 : &mut (&mut T) = &mut x1;

let mut c = y;
y = y1;
y1 = c;

let test_y = y;
let test_y1 = y1;

let test_x1 = x1;
let test_x = x;

let test_t1 = t1;
let test_t = t;

// let test_y = y;
// let test_x1 = x1;
// let test_t1 = t1;

// let test_y1 = y1;
// let test_x = x;
// let test_t = t;
}
5 changes: 5 additions & 0 deletions test-files/90_iterated_borrow_assign_fn.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
struct T {}
fn main () {}
fn test<'b, 'a : 'b>(x : &'a mut (&'b mut T), y : &'a mut (&'b mut T)) {
*x = *y;
}
31 changes: 31 additions & 0 deletions test-files/91_iterated_borrow_swap_fn.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
struct T {}
fn test<'b, 'a : 'b>(x : &'a mut (&'b mut T), y : &'a mut (&'b mut T), c : &'a mut &'b mut T) -> (&'a mut &'b mut T, &'a mut &'b mut T) {
*c = *x;
*x = *y;
*y = *c;
return (x, y);
}
fn main () {
let mut t1 = T {};
let mut t2 = T {};
let mut t3 = T {};
let mut x1 = &mut t1;
let mut x2 = &mut t2;
let mut x3 = &mut t3;
let mut y1 : &mut &mut T = &mut x1;
let mut y2 : &mut &mut T = &mut x2;
let mut y3 : &mut &mut T = &mut x3;

let (y1, y2) = test(y1, y2, y3);
// Fails: let test_t3 = t3;

let test_y1 = y1;
let test_y2 = y2;

let test_t3 = t3;

let test_t1 = t1;
let test_t2 = t2;

// OK let test_t3 = t3;
}