Skip to content
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

Rollup of 16 pull requests #62355

Merged
merged 47 commits into from
Jul 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
fc918a3
rename InterpretCx -> InterpCx
RalfJung Jun 27, 2019
a02d436
wfcheck: resolve the type-vars in `AdtField` types
arielb1 Jun 29, 2019
f7061db
Update mem::replace example to not be identical to mem::take
czipperz Jun 30, 2019
3f39dc1
syntax: Unsupport `foo! bar { ... }` macros in the parser
petrochenkov Jun 30, 2019
d0dc41a
Address review comments
petrochenkov Jul 1, 2019
8d6b1d1
Clean up inherent_impls
Zoxc Apr 16, 2019
b49fb76
miri realloc: do not require giving old size+align
RalfJung Jul 1, 2019
8a3797b
Use mem::take instead of mem::replace with default
czipperz Jun 30, 2019
636f5e6
Convert more usages over
czipperz Jun 30, 2019
b0c199a
Enable mem_take feature in relevant crates
czipperz Jun 30, 2019
1443abc
Revert change in compiletest
czipperz Jun 30, 2019
eddfad3
Fix import of take in collapse_docs.rs
czipperz Jul 2, 2019
dc088b2
refactor check_for_substitution
matklad Jul 2, 2019
db16e17
When possible without changing semantics, implement Iterator::last in…
khuey Jul 2, 2019
c004451
Migrate compile-pass annotations to build-pass
JohnTitor Jul 2, 2019
8d2f80b
Use link attributes on extern "C" blocks with llvm-libuwind
petrhosek Jul 2, 2019
87e8613
Remove needless lifetimes
jeremystucki Jun 21, 2019
0477e07
Remove needless lifetimes
jeremystucki Jun 21, 2019
6ae80cf
Remove needless lifetimes
jeremystucki Jun 21, 2019
d50a3a7
Remove needless lifetimes
jeremystucki Jun 21, 2019
ec71176
Remove needless lifetimes
jeremystucki Jun 21, 2019
d28832d
Remove needless lifetimes
jeremystucki Jun 21, 2019
3cd4df7
Add missing lifetime specifier
jeremystucki Jun 23, 2019
80f4c49
Add missing lifetime specifier
jeremystucki Jun 23, 2019
b17cec5
Add missing lifetime specifier
jeremystucki Jun 23, 2019
edcde70
Add missing lifetime specifier
jeremystucki Jun 24, 2019
88c515d
Revert changes to the standard library
jeremystucki Jun 25, 2019
b4712f0
Fix bucket in CPU usage script
Mark-Simulacrum Jul 3, 2019
c51802a
simplify Option::get_or_insert
matklad Jul 3, 2019
4dd5edc
enable a few more tests in Miri and update the comment for others
RalfJung Jul 3, 2019
6225607
remove bogus example from drop_in_place
RalfJung Jul 3, 2019
e8a88f7
Rollup merge of #62039 - jeremystucki:needless_lifetimes, r=eddyb
Centril Jul 3, 2019
740d5bd
Rollup merge of #62173 - RalfJung:miri-interp, r=oli-obk
Centril Jul 3, 2019
6cfd474
Rollup merge of #62240 - arielb1:resolve-wf-fields, r=pnkfelix
Centril Jul 3, 2019
88c007c
Rollup merge of #62249 - czipperz:use-mem-take-instead-of-replace-def…
Centril Jul 3, 2019
944bda9
Rollup merge of #62252 - czipperz:change-mem-replace-doc-example, r=d…
Centril Jul 3, 2019
8867ba1
Rollup merge of #62258 - petrochenkov:idclean, r=Centril
Centril Jul 3, 2019
d7e42cc
Rollup merge of #62268 - Zoxc:inherent_impls, r=eddyb
Centril Jul 3, 2019
d93b52f
Rollup merge of #62287 - petrhosek:libunwind-link-attribute, r=tmandry
Centril Jul 3, 2019
44f22e6
Rollup merge of #62295 - RalfJung:miri-realloc, r=cramertj
Centril Jul 3, 2019
c0ec567
Rollup merge of #62297 - matklad:peek-delimited, r=petrochenkov
Centril Jul 3, 2019
4049a3c
Rollup merge of #62316 - khuey:efficient_last, r=sfackler
Centril Jul 3, 2019
9193497
Rollup merge of #62317 - JohnTitor:move-tests-to-build-pass, r=Centril
Centril Jul 3, 2019
cd1fa00
Rollup merge of #62337 - Mark-Simulacrum:fix-cpu-usage-script, r=alex…
Centril Jul 3, 2019
839e89c
Rollup merge of #62344 - matklad:simplify-option, r=sfackler
Centril Jul 3, 2019
144ed02
Rollup merge of #62346 - RalfJung:miri-tests, r=Centril
Centril Jul 3, 2019
6363a58
Rollup merge of #62351 - RalfJung:drop-in-place, r=cramertj
Centril Jul 3, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion src/etc/cpu-usage-over-time-plot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

set -ex

bucket=rust-lang-ci-evalazure
bucket=rust-lang-ci2
commit=$1
builder=$2

Expand Down
8 changes: 8 additions & 0 deletions src/liballoc/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,14 @@ impl<I: Iterator + ?Sized> Iterator for Box<I> {
(**self).nth(n)
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<I: Iterator + Sized> Iterator for Box<I> {
fn last(self) -> Option<I::Item> where I: Sized {
(*self).last()
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<I: DoubleEndedIterator + ?Sized> DoubleEndedIterator for Box<I> {
fn next_back(&mut self) -> Option<I::Item> {
Expand Down
5 changes: 5 additions & 0 deletions src/liballoc/collections/binary_heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,11 @@ impl<'a, T> Iterator for Iter<'a, T> {
fn size_hint(&self) -> (usize, Option<usize>) {
self.iter.size_hint()
}

#[inline]
fn last(self) -> Option<&'a T> {
self.iter.last()
}
}

#[stable(feature = "rust1", since = "1.0.0")]
Expand Down
32 changes: 30 additions & 2 deletions src/liballoc/collections/btree/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -770,8 +770,8 @@ impl<K: Ord, V> BTreeMap<K, V> {
}

// First, we merge `self` and `other` into a sorted sequence in linear time.
let self_iter = mem::replace(self, BTreeMap::new()).into_iter();
let other_iter = mem::replace(other, BTreeMap::new()).into_iter();
let self_iter = mem::take(self).into_iter();
let other_iter = mem::take(other).into_iter();
let iter = MergeIter {
left: self_iter.peekable(),
right: other_iter.peekable(),
Expand Down Expand Up @@ -1193,6 +1193,10 @@ impl<'a, K: 'a, V: 'a> Iterator for Iter<'a, K, V> {
fn size_hint(&self) -> (usize, Option<usize>) {
(self.length, Some(self.length))
}

fn last(mut self) -> Option<(&'a K, &'a V)> {
self.next_back()
}
}

#[stable(feature = "fused", since = "1.26.0")]
Expand Down Expand Up @@ -1253,6 +1257,10 @@ impl<'a, K: 'a, V: 'a> Iterator for IterMut<'a, K, V> {
fn size_hint(&self) -> (usize, Option<usize>) {
(self.length, Some(self.length))
}

fn last(mut self) -> Option<(&'a K, &'a mut V)> {
self.next_back()
}
}

#[stable(feature = "rust1", since = "1.0.0")]
Expand Down Expand Up @@ -1421,6 +1429,10 @@ impl<'a, K, V> Iterator for Keys<'a, K, V> {
fn size_hint(&self) -> (usize, Option<usize>) {
self.inner.size_hint()
}

fn last(mut self) -> Option<&'a K> {
self.next_back()
}
}

#[stable(feature = "rust1", since = "1.0.0")]
Expand Down Expand Up @@ -1458,6 +1470,10 @@ impl<'a, K, V> Iterator for Values<'a, K, V> {
fn size_hint(&self) -> (usize, Option<usize>) {
self.inner.size_hint()
}

fn last(mut self) -> Option<&'a V> {
self.next_back()
}
}

#[stable(feature = "rust1", since = "1.0.0")]
Expand Down Expand Up @@ -1495,6 +1511,10 @@ impl<'a, K, V> Iterator for Range<'a, K, V> {
unsafe { Some(self.next_unchecked()) }
}
}

fn last(mut self) -> Option<(&'a K, &'a V)> {
self.next_back()
}
}

#[stable(feature = "map_values_mut", since = "1.10.0")]
Expand All @@ -1508,6 +1528,10 @@ impl<'a, K, V> Iterator for ValuesMut<'a, K, V> {
fn size_hint(&self) -> (usize, Option<usize>) {
self.inner.size_hint()
}

fn last(mut self) -> Option<&'a mut V> {
self.next_back()
}
}

#[stable(feature = "map_values_mut", since = "1.10.0")]
Expand Down Expand Up @@ -1626,6 +1650,10 @@ impl<'a, K, V> Iterator for RangeMut<'a, K, V> {
unsafe { Some(self.next_unchecked()) }
}
}

fn last(mut self) -> Option<(&'a K, &'a mut V)> {
self.next_back()
}
}

impl<'a, K, V> RangeMut<'a, K, V> {
Expand Down
7 changes: 7 additions & 0 deletions src/liballoc/collections/btree/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1019,6 +1019,9 @@ impl<'a, T> Iterator for Iter<'a, T> {
fn size_hint(&self) -> (usize, Option<usize>) {
self.iter.size_hint()
}
fn last(mut self) -> Option<&'a T> {
self.next_back()
}
}
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> DoubleEndedIterator for Iter<'a, T> {
Expand Down Expand Up @@ -1073,6 +1076,10 @@ impl<'a, T> Iterator for Range<'a, T> {
fn next(&mut self) -> Option<&'a T> {
self.iter.next().map(|(k, _)| k)
}

fn last(mut self) -> Option<&'a T> {
self.next_back()
}
}

#[stable(feature = "btree_range", since = "1.17.0")]
Expand Down
12 changes: 11 additions & 1 deletion src/liballoc/collections/linked_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ impl<T> LinkedList<T> {
let len = self.len();
assert!(at <= len, "Cannot split off at a nonexistent index");
if at == 0 {
return mem::replace(self, Self::new());
return mem::take(self);
} else if at == len {
return Self::new();
}
Expand Down Expand Up @@ -832,6 +832,11 @@ impl<'a, T> Iterator for Iter<'a, T> {
fn size_hint(&self) -> (usize, Option<usize>) {
(self.len, Some(self.len))
}

#[inline]
fn last(mut self) -> Option<&'a T> {
self.next_back()
}
}

#[stable(feature = "rust1", since = "1.0.0")]
Expand Down Expand Up @@ -881,6 +886,11 @@ impl<'a, T> Iterator for IterMut<'a, T> {
fn size_hint(&self) -> (usize, Option<usize>) {
(self.len, Some(self.len))
}

#[inline]
fn last(mut self) -> Option<&'a mut T> {
self.next_back()
}
}

#[stable(feature = "rust1", since = "1.0.0")]
Expand Down
10 changes: 10 additions & 0 deletions src/liballoc/collections/vec_deque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2206,6 +2206,11 @@ impl<'a, T> Iterator for Iter<'a, T> {
self.tail = self.head - iter.len();
final_res
}

#[inline]
fn last(mut self) -> Option<&'a T> {
self.next_back()
}
}

#[stable(feature = "rust1", since = "1.0.0")]
Expand Down Expand Up @@ -2319,6 +2324,11 @@ impl<'a, T> Iterator for IterMut<'a, T> {
accum = front.iter_mut().fold(accum, &mut f);
back.iter_mut().fold(accum, &mut f)
}

#[inline]
fn last(mut self) -> Option<&'a mut T> {
self.next_back()
}
}

#[stable(feature = "rust1", since = "1.0.0")]
Expand Down
1 change: 1 addition & 0 deletions src/liballoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
#![feature(maybe_uninit_extra, maybe_uninit_slice, maybe_uninit_array)]
#![feature(alloc_layout_extra)]
#![feature(try_trait)]
#![feature(mem_take)]

// Allow testing this library

Expand Down
2 changes: 1 addition & 1 deletion src/liballoc/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ impl ToOwned for str {
}

fn clone_into(&self, target: &mut String) {
let mut b = mem::replace(target, String::new()).into_bytes();
let mut b = mem::take(target).into_bytes();
self.as_bytes().clone_into(&mut b);
*target = unsafe { String::from_utf8_unchecked(b) }
}
Expand Down
5 changes: 5 additions & 0 deletions src/liballoc/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2385,6 +2385,11 @@ impl Iterator for Drain<'_> {
fn size_hint(&self) -> (usize, Option<usize>) {
self.iter.size_hint()
}

#[inline]
fn last(mut self) -> Option<char> {
self.next_back()
}
}

#[stable(feature = "drain", since = "1.6.0")]
Expand Down
1 change: 0 additions & 1 deletion src/liballoc/tests/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,6 @@ fn from_into_inner() {
it.next().unwrap();
let vec = it.collect::<Vec<_>>();
assert_eq!(vec, [2, 3]);
#[cfg(not(miri))] // Miri does not support comparing dangling pointers
assert!(ptr != vec.as_ptr());
}

Expand Down
1 change: 1 addition & 0 deletions src/libcore/ascii.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ impl Iterator for EscapeDefault {
type Item = u8;
fn next(&mut self) -> Option<u8> { self.range.next().map(|i| self.data[i]) }
fn size_hint(&self) -> (usize, Option<usize>) { self.range.size_hint() }
fn last(mut self) -> Option<u8> { self.next_back() }
}
#[stable(feature = "rust1", since = "1.0.0")]
impl DoubleEndedIterator for EscapeDefault {
Expand Down
1 change: 1 addition & 0 deletions src/libcore/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
#![feature(adx_target_feature)]
#![feature(maybe_uninit_slice, maybe_uninit_array)]
#![feature(external_doc)]
#![feature(mem_take)]

#[prelude_import]
#[allow(unused)]
Expand Down
28 changes: 20 additions & 8 deletions src/libcore/mem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,12 @@ pub fn swap<T>(x: &mut T, y: &mut T) {
/// mem::take(&mut self.buf)
/// }
/// }
///
/// let mut buffer = Buffer { buf: vec![0, 1] };
/// assert_eq!(buffer.buf.len(), 2);
///
/// assert_eq!(buffer.get_and_reset(), vec![0, 1]);
/// assert_eq!(buffer.buf.len(), 0);
/// ```
///
/// [`Clone`]: ../../std/clone/trait.Clone.html
Expand Down Expand Up @@ -586,17 +592,17 @@ pub fn take<T: Default>(dest: &mut T) -> T {
/// struct Buffer<T> { buf: Vec<T> }
///
/// impl<T> Buffer<T> {
/// fn get_and_reset(&mut self) -> Vec<T> {
/// fn replace_index(&mut self, i: usize, v: T) -> T {
/// // error: cannot move out of dereference of `&mut`-pointer
/// let buf = self.buf;
/// self.buf = Vec::new();
/// buf
/// let t = self.buf[i];
/// self.buf[i] = v;
/// t
/// }
/// }
/// ```
///
/// Note that `T` does not necessarily implement [`Clone`], so it can't even clone and reset
/// `self.buf`. But `replace` can be used to disassociate the original value of `self.buf` from
/// Note that `T` does not necessarily implement [`Clone`], so we can't even clone `self.buf[i]` to
/// avoid the move. But `replace` can be used to disassociate the original value at that index from
/// `self`, allowing it to be returned:
///
/// ```
Expand All @@ -605,10 +611,16 @@ pub fn take<T: Default>(dest: &mut T) -> T {
///
/// # struct Buffer<T> { buf: Vec<T> }
/// impl<T> Buffer<T> {
/// fn get_and_reset(&mut self) -> Vec<T> {
/// mem::replace(&mut self.buf, Vec::new())
/// fn replace_index(&mut self, i: usize, v: T) -> T {
/// mem::replace(&mut self.buf[i], v)
/// }
/// }
///
/// let mut buffer = Buffer { buf: vec![0, 1] };
/// assert_eq!(buffer.buf[0], 0);
///
/// assert_eq!(buffer.replace_index(0, 2), 0);
/// assert_eq!(buffer.buf[0], 2);
/// ```
///
/// [`Clone`]: ../../std/clone/trait.Clone.html
Expand Down
12 changes: 2 additions & 10 deletions src/libcore/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -777,15 +777,7 @@ impl<T> Option<T> {
#[inline]
#[stable(feature = "option_entry", since = "1.20.0")]
pub fn get_or_insert(&mut self, v: T) -> &mut T {
match *self {
None => *self = Some(v),
_ => (),
}

match *self {
Some(ref mut v) => v,
None => unsafe { hint::unreachable_unchecked() },
}
self.get_or_insert_with(|| v)
}

/// Inserts a value computed from `f` into the option if it is [`None`], then
Expand Down Expand Up @@ -845,7 +837,7 @@ impl<T> Option<T> {
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn take(&mut self) -> Option<T> {
mem::replace(self, None)
mem::take(self)
}

/// Replaces the actual value in the option by the value given in parameter,
Expand Down
32 changes: 5 additions & 27 deletions src/libcore/ptr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,19 @@ pub use unique::Unique;
/// as the compiler doesn't need to prove that it's sound to elide the
/// copy.
///
/// Unaligned values cannot be dropped in place, they must be copied to an aligned
/// location first using [`ptr::read_unaligned`].
///
/// [`ptr::read`]: ../ptr/fn.read.html
/// [`ptr::read_unaligned`]: ../ptr/fn.read_unaligned.html
///
/// # Safety
///
/// Behavior is undefined if any of the following conditions are violated:
///
/// * `to_drop` must be [valid] for reads.
///
/// * `to_drop` must be properly aligned. See the example below for how to drop
/// an unaligned pointer.
/// * `to_drop` must be properly aligned.
///
/// Additionally, if `T` is not [`Copy`], using the pointed-to value after
/// calling `drop_in_place` can cause undefined behavior. Note that `*to_drop =
Expand Down Expand Up @@ -153,31 +156,6 @@ pub use unique::Unique;
/// assert!(weak.upgrade().is_none());
/// ```
///
/// Unaligned values cannot be dropped in place, they must be copied to an aligned
/// location first:
/// ```
/// use std::ptr;
/// use std::mem::{self, MaybeUninit};
///
/// unsafe fn drop_after_copy<T>(to_drop: *mut T) {
/// let mut copy: MaybeUninit<T> = MaybeUninit::uninit();
/// ptr::copy(to_drop, copy.as_mut_ptr(), 1);
/// drop(copy.assume_init());
/// }
///
/// #[repr(packed, C)]
/// struct Packed {
/// _padding: u8,
/// unaligned: Vec<i32>,
/// }
///
/// let mut p = Packed { _padding: 0, unaligned: vec![42] };
/// unsafe {
/// drop_after_copy(&mut p.unaligned as *mut _);
/// mem::forget(p);
/// }
/// ```
///
/// Notice that the compiler performs this copy automatically when dropping packed structs,
/// i.e., you do not usually have to worry about such issues unless you call `drop_in_place`
/// manually.
Expand Down
Loading