From f4fb330c67f41af06ae275aafeba2a9bb69d1660 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 4 Nov 2019 13:28:18 +0100 Subject: [PATCH 1/2] test offset_from --- tests/run-pass/ptr_offset_from.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 tests/run-pass/ptr_offset_from.rs diff --git a/tests/run-pass/ptr_offset_from.rs b/tests/run-pass/ptr_offset_from.rs new file mode 100644 index 0000000000..92eb3f6e46 --- /dev/null +++ b/tests/run-pass/ptr_offset_from.rs @@ -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::::new(); + let i = v.into_iter(); + i.size_hint(); +} + +fn main() { + test_raw(); + test_vec_into_iter(); +} From 3847334e725aec9f963afa20520631bf6566a244 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 5 Nov 2019 20:17:45 +0100 Subject: [PATCH 2/2] rustup --- rust-version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-version b/rust-version index 1a58c80128..5511ef0ad6 100644 --- a/rust-version +++ b/rust-version @@ -1 +1 @@ -6c1b220fd747bf244f04b380e4d4ae005068f706 +3a1b3b30c6cdd674049b144a3ced7b711de962b2