Skip to content

Commit

Permalink
Auto merge of #2036 - RalfJung:vec, r=RalfJung
Browse files Browse the repository at this point in the history
regression test for reverse() unsoundness

Cc rust-lang/rust#90821
  • Loading branch information
bors committed Mar 24, 2022
2 parents d46b648 + 951ac65 commit 346f8f2
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion tests/run-pass/vec.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// compile-flags: -Zmiri-tag-raw-pointers
// compile-flags: -Zmiri-tag-raw-pointers -Zmiri-check-number-validity
// Gather all references from a mutable iterator and make sure Miri notices if
// using them is dangerous.
fn test_all_refs<'a, T: 'a>(dummy: &mut T, iter: impl Iterator<Item = &'a mut T>) {
Expand Down Expand Up @@ -148,6 +148,16 @@ fn swap_remove() {
vec.swap_remove(1);
}

fn reverse() {
#[repr(align(2))]
#[derive(Debug)]
struct Foo(u8);

let mut v: Vec<_> = (0..50).map(Foo).collect();
v.reverse();
assert!(v[0].0 == 49);
}

fn main() {
assert_eq!(vec_reallocate().len(), 5);

Expand Down Expand Up @@ -176,4 +186,5 @@ fn main() {
sort();
swap();
swap_remove();
reverse();
}

0 comments on commit 346f8f2

Please sign in to comment.