From b394165538bc52063f79a1820135cfefa19370e7 Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Sat, 31 Mar 2018 22:35:37 -0700 Subject: Deprecate offset_to; switch core&alloc to using offset_from instead Bonus: might make code than uses `.len()` on slice iterators faster --- src/liballoc/lib.rs | 2 +- src/liballoc/vec.rs | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'src/liballoc') diff --git a/src/liballoc/lib.rs b/src/liballoc/lib.rs index e98b58994bf..009441e1680 100644 --- a/src/liballoc/lib.rs +++ b/src/liballoc/lib.rs @@ -103,13 +103,13 @@ #![feature(lang_items)] #![feature(needs_allocator)] #![feature(nonzero)] -#![feature(offset_to)] #![feature(optin_builtin_traits)] #![feature(pattern)] #![feature(pin)] #![feature(placement_in_syntax)] #![feature(placement_new_protocol)] #![feature(ptr_internals)] +#![feature(ptr_offset_from)] #![feature(rustc_attrs)] #![feature(slice_get_slice)] #![feature(slice_rsplit)] diff --git a/src/liballoc/vec.rs b/src/liballoc/vec.rs index 2eedb964f88..d8ec956df8a 100644 --- a/src/liballoc/vec.rs +++ b/src/liballoc/vec.rs @@ -2338,9 +2338,10 @@ impl Iterator for IntoIter { #[inline] fn size_hint(&self) -> (usize, Option) { - let exact = match self.ptr.offset_to(self.end) { - Some(x) => x as usize, - None => (self.end as usize).wrapping_sub(self.ptr as usize), + let exact = if mem::size_of::() == 0 { + (self.end as usize).wrapping_sub(self.ptr as usize) + } else { + unsafe { self.end.offset_from(self.ptr) as usize } }; (exact, Some(exact)) } -- cgit 1.4.1-3-g733a5