diff options
| author | Alexis Bourget <alexis.bourget@gmail.com> | 2020-09-10 15:41:16 +0200 |
|---|---|---|
| committer | Alexis Bourget <alexis.bourget@gmail.com> | 2020-09-21 21:50:27 +0200 |
| commit | 6bc0357dadd9d41a8166d4c2ab8a27c0bb8150d3 (patch) | |
| tree | b5ea412aa68591fb7234e326df7a94862af8373f /library/alloc/tests | |
| parent | 275eed7eb1d45e8173b932e2abfdae2201d2cf62 (diff) | |
| download | rust-6bc0357dadd9d41a8166d4c2ab8a27c0bb8150d3.tar.gz rust-6bc0357dadd9d41a8166d4c2ab8a27c0bb8150d3.zip | |
Move vec-cycle test
Diffstat (limited to 'library/alloc/tests')
| -rw-r--r-- | library/alloc/tests/vec.rs | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/library/alloc/tests/vec.rs b/library/alloc/tests/vec.rs index a49ca7c256a..d93de65d3d8 100644 --- a/library/alloc/tests/vec.rs +++ b/library/alloc/tests/vec.rs @@ -1,4 +1,5 @@ use std::borrow::Cow; +use std::cell::Cell; use std::collections::TryReserveError::*; use std::fmt::Debug; use std::iter::InPlaceIterable; @@ -1831,3 +1832,41 @@ fn partialeq_vec_full() { assert_partial_eq_valid!(vec2,vec3; array2,array3); assert_partial_eq_valid!(vec2,vec3; arrayref2,arrayref3); } + +#[test] +fn test_vec_cycle() { + #[derive(Debug)] + struct C<'a> { + v: Vec<Cell<Option<&'a C<'a>>>>, + } + + impl<'a> C<'a> { + fn new() -> C<'a> { + C { v: Vec::new() } + } + } + + let mut c1 = C::new(); + let mut c2 = C::new(); + let mut c3 = C::new(); + + // Push + c1.v.push(Cell::new(None)); + c1.v.push(Cell::new(None)); + + c2.v.push(Cell::new(None)); + c2.v.push(Cell::new(None)); + + c3.v.push(Cell::new(None)); + c3.v.push(Cell::new(None)); + + // Set + c1.v[0].set(Some(&c2)); + c1.v[1].set(Some(&c3)); + + c2.v[0].set(Some(&c2)); + c2.v[1].set(Some(&c3)); + + c3.v[0].set(Some(&c1)); + c3.v[1].set(Some(&c2)); +} |
