diff options
| author | Amanieu d'Antras <amanieu@gmail.com> | 2017-03-31 13:52:46 +0100 |
|---|---|---|
| committer | Amanieu d'Antras <amanieu@gmail.com> | 2017-04-03 01:36:56 +0100 |
| commit | 7b89bd7ccacd0908d7e22a5cf383c8cc147bc3d5 (patch) | |
| tree | f07ae40b18015742cbd15859b22ec37f5b4d9aa3 /src/libcollections | |
| parent | c82f1325cfb5f3fd5028225f692cb134517016f1 (diff) | |
| download | rust-7b89bd7ccacd0908d7e22a5cf383c8cc147bc3d5.tar.gz rust-7b89bd7ccacd0908d7e22a5cf383c8cc147bc3d5.zip | |
Add ptr::offset_to
Diffstat (limited to 'src/libcollections')
| -rw-r--r-- | src/libcollections/lib.rs | 1 | ||||
| -rw-r--r-- | src/libcollections/vec.rs | 12 |
2 files changed, 5 insertions, 8 deletions
diff --git a/src/libcollections/lib.rs b/src/libcollections/lib.rs index 72e950bc91f..2b345e3d0a5 100644 --- a/src/libcollections/lib.rs +++ b/src/libcollections/lib.rs @@ -61,6 +61,7 @@ #![feature(unique)] #![feature(untagged_unions)] #![cfg_attr(test, feature(rand, test))] +#![feature(offset_to)] #![no_std] diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index 56b60a3e003..f12380a9ea5 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -2073,14 +2073,10 @@ impl<T> Iterator for IntoIter<T> { #[inline] fn size_hint(&self) -> (usize, Option<usize>) { - let diff = (self.end as usize) - (self.ptr as usize); - let size = mem::size_of::<T>(); - let exact = diff / - (if size == 0 { - 1 - } else { - size - }); + 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), + }; (exact, Some(exact)) } |
