Skip to content

Commit

Permalink
Auto-format
Browse files Browse the repository at this point in the history
* Changes:

- Add rustfmt.toml with max-width override.
- Run cargo fmt.

* Motivation:

Not perfect, but consistent.
  • Loading branch information
matthieu-m committed Nov 26, 2023
1 parent 89ae93f commit 7c5397c
Show file tree
Hide file tree
Showing 6 changed files with 633 additions and 585 deletions.
1 change: 1 addition & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
max_width = 120
213 changes: 110 additions & 103 deletions src/ghost_borrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,116 +130,123 @@ generate_public_instance!(a, b, c, d, e, f, g, h, i, j, k, l ; T0, T1, T2, T3, T
#[cfg(test)]
mod tests {

use super::*;

#[test]
fn multiple_borrows_tuple() {
let value = GhostToken::new(|token| {
let cell1 = GhostCell::new(42);
let cell2 = GhostCell::new(47);
let cell3 = GhostCell::new(7);
let cell4 = GhostCell::new(9);

let (reference1, reference2, reference3, reference4): (&i32, &i32, &i32, &i32)
= (&cell1, &cell2, &cell3, &cell4).borrow(&token);

(*reference1, *reference2, *reference3, *reference4)
});
assert_eq!((42, 47, 7, 9), value);
}

#[test]
fn multiple_borrows_tuple_ref() {
let value = GhostToken::new(|token| {
let cell1 = GhostCell::new(42);
let cell2 = GhostCell::new(47);
let cell3 = GhostCell::new(7);
let cell4 = GhostCell::new(9);
let tuple = (cell1, cell2, cell3, cell4);

let reference: &(i32, i32, i32, i32) = tuple.borrow(&token);

(reference.0, reference.1, reference.2, reference.3)
});
assert_eq!((42, 47, 7, 9), value);
}

#[test]
fn multiple_borrows_array_ref() {
let value = GhostToken::new(|token| {
let cell1 = GhostCell::new(42);
let cell2 = GhostCell::new(47);
let cell3 = GhostCell::new(7);
let cell4 = GhostCell::new(9);
let array = [cell1, cell2, cell3, cell4];
use super::*;

#[test]
fn multiple_borrows_tuple() {
let value = GhostToken::new(|token| {
let cell1 = GhostCell::new(42);
let cell2 = GhostCell::new(47);
let cell3 = GhostCell::new(7);
let cell4 = GhostCell::new(9);

let (reference1, reference2, reference3, reference4): (&i32, &i32, &i32, &i32) =
(&cell1, &cell2, &cell3, &cell4).borrow(&token);

(*reference1, *reference2, *reference3, *reference4)
});
assert_eq!((42, 47, 7, 9), value);
}

let reference: &[i32; 4] = array.borrow(&token);
#[test]
fn multiple_borrows_tuple_ref() {
let value = GhostToken::new(|token| {
let cell1 = GhostCell::new(42);
let cell2 = GhostCell::new(47);
let cell3 = GhostCell::new(7);
let cell4 = GhostCell::new(9);
let tuple = (cell1, cell2, cell3, cell4);

(reference[0], reference[1], reference[2], reference[3])
});
assert_eq!((42, 47, 7, 9), value);
}
let reference: &(i32, i32, i32, i32) = tuple.borrow(&token);

#[test]
fn multiple_borrows_tuple_unsized() {
let value = GhostToken::new(|token| {
let mut data1 = 42;
let mut data2 = [47];
let mut data3 = 7;
let mut data4 = [9];
(reference.0, reference.1, reference.2, reference.3)
});
assert_eq!((42, 47, 7, 9), value);
}

let cell1 = &*GhostCell::from_mut(&mut data1 as &mut dyn ToString);
let cell2 = &*GhostCell::from_mut(&mut data2 as &mut [i32]);
let cell3 = &*GhostCell::from_mut(&mut data3 as &mut dyn ToString);
let cell4 = &*GhostCell::from_mut(&mut data4 as &mut [i32]);
#[test]
fn multiple_borrows_array_ref() {
let value = GhostToken::new(|token| {
let cell1 = GhostCell::new(42);
let cell2 = GhostCell::new(47);
let cell3 = GhostCell::new(7);
let cell4 = GhostCell::new(9);
let array = [cell1, cell2, cell3, cell4];

let (reference1, reference2, reference3, reference4) = (cell1, cell2, cell3, cell4).borrow(&token);
let reference: &[i32; 4] = array.borrow(&token);

(reference1.to_string(), reference2[0], reference3.to_string(), reference4[0])
});
assert_eq!(("42".to_owned(), 47, "7".to_owned(), 9), value);
}
(reference[0], reference[1], reference[2], reference[3])
});
assert_eq!((42, 47, 7, 9), value);
}

#[test]
fn multiple_borrows_array_unsized_slice() {
let value = GhostToken::new(|token| {
let mut data1 = [42];
let mut data2 = [47];
let mut data3 = [7];
let mut data4 = [9];

let cell1 = &*GhostCell::from_mut(&mut data1 as &mut [i32]);
let cell2 = &*GhostCell::from_mut(&mut data2 as &mut [i32]);
let cell3 = &*GhostCell::from_mut(&mut data3 as &mut [i32]);
let cell4 = &*GhostCell::from_mut(&mut data4 as &mut [i32]);
let array = [cell1, cell2, cell3, cell4];

let reference: [&[i32]; 4] = array.borrow(&token);

reference.map(|slice| slice[0])
});
assert_eq!([42, 47, 7, 9], value);
}
#[test]
fn multiple_borrows_tuple_unsized() {
let value = GhostToken::new(|token| {
let mut data1 = 42;
let mut data2 = [47];
let mut data3 = 7;
let mut data4 = [9];

let cell1 = &*GhostCell::from_mut(&mut data1 as &mut dyn ToString);
let cell2 = &*GhostCell::from_mut(&mut data2 as &mut [i32]);
let cell3 = &*GhostCell::from_mut(&mut data3 as &mut dyn ToString);
let cell4 = &*GhostCell::from_mut(&mut data4 as &mut [i32]);

let (reference1, reference2, reference3, reference4) = (cell1, cell2, cell3, cell4).borrow(&token);

(
reference1.to_string(),
reference2[0],
reference3.to_string(),
reference4[0],
)
});
assert_eq!(("42".to_owned(), 47, "7".to_owned(), 9), value);
}

#[test]
fn multiple_borrows_array_unsized_dyn_trait() {
let value = GhostToken::new(|token| {
let mut data1 = 42;
let mut data2 = 47;
let mut data3 = 7;
let mut data4 = 9;

let cell1 = &*GhostCell::from_mut(&mut data1 as &mut dyn ToString);
let cell2 = &*GhostCell::from_mut(&mut data2 as &mut dyn ToString);
let cell3 = &*GhostCell::from_mut(&mut data3 as &mut dyn ToString);
let cell4 = &*GhostCell::from_mut(&mut data4 as &mut dyn ToString);
let array = [cell1, cell2, cell3, cell4];

let reference: [&dyn ToString; 4] = array.borrow(&token);

reference.map(ToString::to_string)
});
assert_eq!(["42".to_owned(), "47".to_owned(), "7".to_owned(), "9".to_owned()], value);
}
#[test]
fn multiple_borrows_array_unsized_slice() {
let value = GhostToken::new(|token| {
let mut data1 = [42];
let mut data2 = [47];
let mut data3 = [7];
let mut data4 = [9];

let cell1 = &*GhostCell::from_mut(&mut data1 as &mut [i32]);
let cell2 = &*GhostCell::from_mut(&mut data2 as &mut [i32]);
let cell3 = &*GhostCell::from_mut(&mut data3 as &mut [i32]);
let cell4 = &*GhostCell::from_mut(&mut data4 as &mut [i32]);
let array = [cell1, cell2, cell3, cell4];

let reference: [&[i32]; 4] = array.borrow(&token);

reference.map(|slice| slice[0])
});
assert_eq!([42, 47, 7, 9], value);
}

#[test]
fn multiple_borrows_array_unsized_dyn_trait() {
let value = GhostToken::new(|token| {
let mut data1 = 42;
let mut data2 = 47;
let mut data3 = 7;
let mut data4 = 9;

let cell1 = &*GhostCell::from_mut(&mut data1 as &mut dyn ToString);
let cell2 = &*GhostCell::from_mut(&mut data2 as &mut dyn ToString);
let cell3 = &*GhostCell::from_mut(&mut data3 as &mut dyn ToString);
let cell4 = &*GhostCell::from_mut(&mut data4 as &mut dyn ToString);
let array = [cell1, cell2, cell3, cell4];

let reference: [&dyn ToString; 4] = array.borrow(&token);

reference.map(ToString::to_string)
});
assert_eq!(
["42".to_owned(), "47".to_owned(), "7".to_owned(), "9".to_owned()],
value
);
}
} // mod tests
Loading

0 comments on commit 7c5397c

Please sign in to comment.