Skip to content

Rollup of 9 pull requests #35649

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

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
9d6fa40
Add regression test for #22894.
frewsxcv Aug 8, 2016
045c8c8
std: Optimize panic::catch_unwind slightly
alexcrichton Jul 9, 2016
fb84bb1
track Location in visitor, combine Location
scottcarr Aug 11, 2016
d099e30
Introduce `as_slice` method on `std::vec::IntoIter` struct.
frewsxcv Aug 7, 2016
01a766e
Introduce `as_mut_slice` method on `std::vec::IntoIter` struct.
frewsxcv Aug 7, 2016
4224737
Improve &-ptr printing
Aug 12, 2016
9b9aae8
Allow attributes to be marked used before `cfg` proccessing.
jseyfried Aug 12, 2016
9794fe5
Add regression test.
jseyfried Aug 12, 2016
f76a737
Correct span for pub_restricted field
sanxiyn Aug 8, 2016
d56a5b9
Upgrade linkchecker to url 1.2.0.
ahmedcharles Aug 13, 2016
08e470f
compiletest: Remove dead code.
ahmedcharles Aug 13, 2016
3949b54
Rollup merge of #35444 - alexcrichton:optimize-catch-unwind, r=brson
Manishearth Aug 13, 2016
0b59b6f
Rollup merge of #35447 - frewsxcv:vec-into-iter-as-slice, r=alexcrichton
Manishearth Aug 13, 2016
c13fe9b
Rollup merge of #35491 - sanxiyn:pub-restricted-span, r=nikomatsakis
Manishearth Aug 13, 2016
c752da3
Rollup merge of #35533 - frewsxcv:22984, r=brson
Manishearth Aug 13, 2016
cef6e24
Rollup merge of #35542 - scottcarr:visitor_refactor, r=nikomatsakis
Manishearth Aug 13, 2016
d92f339
Rollup merge of #35611 - jonathandturner:ptr-helper, r=nikomatsakis
Manishearth Aug 13, 2016
fdce693
Rollup merge of #35617 - jseyfried:fix_unused_cfg_attr_path, r=eddyb
Manishearth Aug 13, 2016
81680af
Rollup merge of #35638 - ahmedcharles:url, r=alexcrichton
Manishearth Aug 13, 2016
570c79d
Rollup merge of #35640 - ahmedcharles:dead, r=alexcrichton
Manishearth Aug 13, 2016
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
63 changes: 51 additions & 12 deletions src/libcollections/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1446,13 +1446,12 @@ impl<T> IntoIterator for Vec<T> {
#[inline]
fn into_iter(mut self) -> IntoIter<T> {
unsafe {
let ptr = self.as_mut_ptr();
assume(!ptr.is_null());
let begin = ptr as *const T;
let begin = self.as_mut_ptr();
assume(!begin.is_null());
let end = if mem::size_of::<T>() == 0 {
arith_offset(ptr as *const i8, self.len() as isize) as *const T
arith_offset(begin as *const i8, self.len() as isize) as *const T
} else {
ptr.offset(self.len() as isize) as *const T
begin.offset(self.len() as isize) as *const T
};
let buf = ptr::read(&self.buf);
mem::forget(self);
Expand Down Expand Up @@ -1710,10 +1709,52 @@ impl<'a, T> FromIterator<T> for Cow<'a, [T]> where T: Clone {
#[stable(feature = "rust1", since = "1.0.0")]
pub struct IntoIter<T> {
_buf: RawVec<T>,
ptr: *const T,
ptr: *mut T,
end: *const T,
}

impl<T> IntoIter<T> {
/// Returns the remaining items of this iterator as a slice.
///
/// # Examples
///
/// ```rust
/// # #![feature(vec_into_iter_as_slice)]
/// let vec = vec!['a', 'b', 'c'];
/// let mut into_iter = vec.into_iter();
/// assert_eq!(into_iter.as_slice(), &['a', 'b', 'c']);
/// let _ = into_iter.next().unwrap();
/// assert_eq!(into_iter.as_slice(), &['b', 'c']);
/// ```
#[unstable(feature = "vec_into_iter_as_slice", issue = "35601")]
pub fn as_slice(&self) -> &[T] {
unsafe {
slice::from_raw_parts(self.ptr, self.len())
}
}

/// Returns the remaining items of this iterator as a mutable slice.
///
/// # Examples
///
/// ```rust
/// # #![feature(vec_into_iter_as_slice)]
/// let vec = vec!['a', 'b', 'c'];
/// let mut into_iter = vec.into_iter();
/// assert_eq!(into_iter.as_slice(), &['a', 'b', 'c']);
/// into_iter.as_mut_slice()[2] = 'z';
/// assert_eq!(into_iter.next().unwrap(), 'a');
/// assert_eq!(into_iter.next().unwrap(), 'b');
/// assert_eq!(into_iter.next().unwrap(), 'z');
/// ```
#[unstable(feature = "vec_into_iter_as_slice", issue = "35601")]
pub fn as_mut_slice(&self) -> &mut [T] {
unsafe {
slice::from_raw_parts_mut(self.ptr, self.len())
}
}
}

#[stable(feature = "rust1", since = "1.0.0")]
unsafe impl<T: Send> Send for IntoIter<T> {}
#[stable(feature = "rust1", since = "1.0.0")]
Expand All @@ -1726,14 +1767,14 @@ impl<T> Iterator for IntoIter<T> {
#[inline]
fn next(&mut self) -> Option<T> {
unsafe {
if self.ptr == self.end {
if self.ptr as *const _ == self.end {
None
} else {
if mem::size_of::<T>() == 0 {
// purposefully don't use 'ptr.offset' because for
// vectors with 0-size elements this would return the
// same pointer.
self.ptr = arith_offset(self.ptr as *const i8, 1) as *const T;
self.ptr = arith_offset(self.ptr as *const i8, 1) as *mut T;

// Use a non-null pointer value
Some(ptr::read(EMPTY as *mut T))
Expand Down Expand Up @@ -1776,7 +1817,7 @@ impl<T> DoubleEndedIterator for IntoIter<T> {
} else {
if mem::size_of::<T>() == 0 {
// See above for why 'ptr.offset' isn't used
self.end = arith_offset(self.end as *const i8, -1) as *const T;
self.end = arith_offset(self.end as *const i8, -1) as *mut T;

// Use a non-null pointer value
Some(ptr::read(EMPTY as *mut T))
Expand All @@ -1796,9 +1837,7 @@ impl<T> ExactSizeIterator for IntoIter<T> {}
#[stable(feature = "vec_into_iter_clone", since = "1.8.0")]
impl<T: Clone> Clone for IntoIter<T> {
fn clone(&self) -> IntoIter<T> {
unsafe {
slice::from_raw_parts(self.ptr, self.len()).to_owned().into_iter()
}
self.as_slice().to_owned().into_iter()
}
}

Expand Down
1 change: 1 addition & 0 deletions src/libcollectionstest/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#![feature(unboxed_closures)]
#![feature(unicode)]
#![feature(vec_deque_contains)]
#![feature(vec_into_iter_as_slice)]

extern crate collections;
extern crate test;
Expand Down
23 changes: 23 additions & 0 deletions src/libcollectionstest/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,29 @@ fn test_split_off() {
assert_eq!(vec2, [5, 6]);
}

#[test]
fn test_into_iter_as_slice() {
let vec = vec!['a', 'b', 'c'];
let mut into_iter = vec.into_iter();
assert_eq!(into_iter.as_slice(), &['a', 'b', 'c']);
let _ = into_iter.next().unwrap();
assert_eq!(into_iter.as_slice(), &['b', 'c']);
let _ = into_iter.next().unwrap();
let _ = into_iter.next().unwrap();
assert_eq!(into_iter.as_slice(), &[]);
}

#[test]
fn test_into_iter_as_mut_slice() {
let vec = vec!['a', 'b', 'c'];
let mut into_iter = vec.into_iter();
assert_eq!(into_iter.as_slice(), &['a', 'b', 'c']);
into_iter.as_mut_slice()[0] = 'x';
into_iter.as_mut_slice()[1] = 'y';
assert_eq!(into_iter.next().unwrap(), 'x');
assert_eq!(into_iter.as_slice(), &['y', 'c']);
}

#[test]
fn test_into_iter_count() {
assert_eq!(vec![1, 2, 3].into_iter().count(), 3);
Expand Down
11 changes: 11 additions & 0 deletions src/librustc/mir/repr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1233,3 +1233,14 @@ impl<'a, 'b> GraphSuccessors<'b> for Mir<'a> {
type Item = BasicBlock;
type Iter = IntoIter<BasicBlock>;
}

#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash, Ord, PartialOrd)]
pub struct Location {
/// the location is within this block
pub block: BasicBlock,

/// the location is the start of the this statement; or, if `statement_index`
/// == num-statements, then the start of the terminator.
pub statement_index: usize,
}

Loading