Skip to content

test offset_from #1032

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

Merged
merged 2 commits into from
Nov 5, 2019
Merged
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
2 changes: 1 addition & 1 deletion rust-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6c1b220fd747bf244f04b380e4d4ae005068f706
3a1b3b30c6cdd674049b144a3ced7b711de962b2
29 changes: 29 additions & 0 deletions tests/run-pass/ptr_offset_from.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#![feature(ptr_offset_from)]

fn test_raw() { unsafe {
let buf = [0u32; 4];

let x = buf.as_ptr() as *const u8;
let y = x.offset(12);

assert_eq!(y.offset_from(x), 12);
assert_eq!(x.offset_from(y), -12);
assert_eq!((y as *const u32).offset_from(x as *const u32), 12/4);
assert_eq!((x as *const u32).offset_from(y as *const u32), -12/4);

let x = (((x as usize) * 2) / 2) as *const u8;
assert_eq!(y.offset_from(x), 12);
assert_eq!(x.offset_from(y), -12);
} }

// This also internally uses offset_from.
fn test_vec_into_iter() {
let v = Vec::<i32>::new();
let i = v.into_iter();
i.size_hint();
}

fn main() {
test_raw();
test_vec_into_iter();
}