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

regression test for reverse() unsoundness #2036

Merged
merged 2 commits into from
Mar 24, 2022
Merged
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
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();
}