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 7 pull requests #72732

Closed
wants to merge 51 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
3f661d2
borrowck `DefId` -> `LocalDefId`
lcnr May 11, 2020
a8ed9aa
impl From<[T; N]> for Box<[T]>
pickfire Apr 13, 2020
eccaa01
rustc_target: Add a target spec option for static-pie support
petrochenkov May 1, 2020
96a466c
linker: Support `-static-pie` and `-static -shared`
petrochenkov May 1, 2020
08df311
librustc_mir: Add support for const fn offset/arith_offset
josephlr Apr 24, 2020
9b3dfd8
core: Make pointer offset methods "const fn"
josephlr Apr 24, 2020
88a37a2
test/ui/consts: Add tests for const ptr offsets
josephlr May 15, 2020
6b20f58
miri_unleached: We now allow offset in const fn
josephlr May 18, 2020
55577b4
librustc_mir: Add back use statement
josephlr May 25, 2020
6367b54
librustc_middle: Add function for computing unsigned abs
josephlr May 26, 2020
71ef841
Add checks and tests for computing abs(offset_bytes)
josephlr May 26, 2020
1de3ebb
Add Extend::{extend_one,extend_reserve}
cuviper May 13, 2020
6a26bb9
Use a canonical name for extend_reserve(additional)
cuviper May 26, 2020
7795c4b
Remove an old comment from HashMap::extend_reserve
cuviper May 26, 2020
02226e0
Add extend_one tracking issue 72631
cuviper May 26, 2020
a977df3
Implement RFC 2585
LeSeulArtichaut May 3, 2020
594c499
Add tests
LeSeulArtichaut May 3, 2020
bb67915
Apply suggestions from code review
LeSeulArtichaut May 13, 2020
3ce9d5c
Add more cases to the test
LeSeulArtichaut May 14, 2020
b3e012b
Fix inverted `if` condition
LeSeulArtichaut May 18, 2020
a41f763
Use the lowest of `unsafe_op_in_unsafe_fn` and `safe_borrow_packed` f…
LeSeulArtichaut May 18, 2020
a3bae5c
Fix wrong conflict resolution
LeSeulArtichaut May 19, 2020
925d5ac
Fix and bless tests
LeSeulArtichaut May 21, 2020
9671b44
Add tests for packed borrows in unsafe fns
LeSeulArtichaut May 22, 2020
3599ada
Mark deduplicated errors as expected in gate test
LeSeulArtichaut May 23, 2020
4a538d3
Do not hardcode lint name
LeSeulArtichaut May 23, 2020
e3d27ec
Add explanation about taking the minimum of the two lints
LeSeulArtichaut May 23, 2020
1b08850
Fix import
LeSeulArtichaut May 23, 2020
63066c0
Use `LintId`s to check for gated lints
LeSeulArtichaut May 23, 2020
db684be
Whitelist `unsafe_op_in_unsafe_fn` in rustdoc
LeSeulArtichaut May 27, 2020
3fea832
Fix spacing of expected/found notes without a label
estebank Dec 20, 2019
5ba2220
Name `RegionKind::ReVar` lifetimes in diagnostics
estebank Dec 20, 2019
eb0f4d5
Tweak output for mismatched impl item
estebank Dec 22, 2019
3811232
review comments
estebank Dec 23, 2019
2e2f820
review comment: use FxIndexSet
estebank Dec 27, 2019
d0d30b0
fix rebase
estebank Jan 7, 2020
2b35247
Modify wording
estebank Feb 17, 2020
500504c
fix rebase
estebank Mar 30, 2020
c52dbbc
fix rebase
estebank Apr 14, 2020
7d5415b
Add additional checks for isize overflow
josephlr May 27, 2020
cb6408a
Fix rebase
estebank May 28, 2020
f213acf
review comments: change wording and visual output
estebank May 28, 2020
0e3b31c
Update src/librustdoc/core.rs
nikomatsakis May 28, 2020
1bd6970
Account for `Self` as a type param
estebank May 28, 2020
990bf40
Rollup merge of #67460 - estebank:named-lts, r=nikomatsakis
RalfJung May 29, 2020
5406670
Rollup merge of #71095 - pickfire:box-from-array, r=dtolnay
RalfJung May 29, 2020
eab712e
Rollup merge of #71500 - josephlr:offset, r=oli-obk,RalfJung
RalfJung May 29, 2020
6dbb61a
Rollup merge of #71804 - petrochenkov:static-pie, r=cuviper
RalfJung May 29, 2020
fc03e75
Rollup merge of #71862 - LeSeulArtichaut:unsafe-block-in-unsafe-fn, r…
RalfJung May 29, 2020
d9356fa
Rollup merge of #72103 - lcnr:borrowck-localdefid, r=jonas-schievink
RalfJung May 29, 2020
6fc28da
Rollup merge of #72162 - cuviper:extend_one, r=Mark-Simulacrum
RalfJung May 29, 2020
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
19 changes: 19 additions & 0 deletions src/liballoc/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,25 @@ impl From<Box<str>> for Box<[u8]> {
}
}

#[stable(feature = "box_from_array", since = "1.45.0")]
impl<T, const N: usize> From<[T; N]> for Box<[T]>
where
[T; N]: LengthAtMost32,
{
/// Converts a `[T; N]` into a `Box<[T]>`
///
/// This conversion moves the array to newly heap-allocated memory.
///
/// # Examples
/// ```rust
/// let boxed: Box<[u8]> = Box::from([4, 2]);
/// println!("{:?}", boxed);
/// ```
fn from(array: [T; N]) -> Box<[T]> {
box array
}
}

#[stable(feature = "boxed_slice_try_from", since = "1.43.0")]
impl<T, const N: usize> TryFrom<Box<[T]>> for Box<[T; N]>
where
Expand Down
20 changes: 20 additions & 0 deletions src/liballoc/collections/binary_heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1376,6 +1376,16 @@ impl<T: Ord> Extend<T> for BinaryHeap<T> {
fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I) {
<Self as SpecExtend<I>>::spec_extend(self, iter);
}

#[inline]
fn extend_one(&mut self, item: T) {
self.push(item);
}

#[inline]
fn extend_reserve(&mut self, additional: usize) {
self.reserve(additional);
}
}

impl<T: Ord, I: IntoIterator<Item = T>> SpecExtend<I> for BinaryHeap<T> {
Expand Down Expand Up @@ -1406,4 +1416,14 @@ impl<'a, T: 'a + Ord + Copy> Extend<&'a T> for BinaryHeap<T> {
fn extend<I: IntoIterator<Item = &'a T>>(&mut self, iter: I) {
self.extend(iter.into_iter().cloned());
}

#[inline]
fn extend_one(&mut self, &item: &'a T) {
self.push(item);
}

#[inline]
fn extend_reserve(&mut self, additional: usize) {
self.reserve(additional);
}
}
10 changes: 10 additions & 0 deletions src/liballoc/collections/btree/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1901,13 +1901,23 @@ impl<K: Ord, V> Extend<(K, V)> for BTreeMap<K, V> {
self.insert(k, v);
});
}

#[inline]
fn extend_one(&mut self, (k, v): (K, V)) {
self.insert(k, v);
}
}

#[stable(feature = "extend_ref", since = "1.2.0")]
impl<'a, K: Ord + Copy, V: Copy> Extend<(&'a K, &'a V)> for BTreeMap<K, V> {
fn extend<I: IntoIterator<Item = (&'a K, &'a V)>>(&mut self, iter: I) {
self.extend(iter.into_iter().map(|(&key, &value)| (key, value)));
}

#[inline]
fn extend_one(&mut self, (&k, &v): (&'a K, &'a V)) {
self.insert(k, v);
}
}

#[stable(feature = "rust1", since = "1.0.0")]
Expand Down
10 changes: 10 additions & 0 deletions src/liballoc/collections/btree/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1152,13 +1152,23 @@ impl<T: Ord> Extend<T> for BTreeSet<T> {
self.insert(elem);
});
}

#[inline]
fn extend_one(&mut self, elem: T) {
self.insert(elem);
}
}

#[stable(feature = "extend_ref", since = "1.2.0")]
impl<'a, T: 'a + Ord + Copy> Extend<&'a T> for BTreeSet<T> {
fn extend<I: IntoIterator<Item = &'a T>>(&mut self, iter: I) {
self.extend(iter.into_iter().cloned());
}

#[inline]
fn extend_one(&mut self, &elem: &'a T) {
self.insert(elem);
}
}

#[stable(feature = "rust1", since = "1.0.0")]
Expand Down
10 changes: 10 additions & 0 deletions src/liballoc/collections/linked_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1748,6 +1748,11 @@ impl<T> Extend<T> for LinkedList<T> {
fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I) {
<Self as SpecExtend<I>>::spec_extend(self, iter);
}

#[inline]
fn extend_one(&mut self, elem: T) {
self.push_back(elem);
}
}

impl<I: IntoIterator> SpecExtend<I> for LinkedList<I::Item> {
Expand All @@ -1767,6 +1772,11 @@ impl<'a, T: 'a + Copy> Extend<&'a T> for LinkedList<T> {
fn extend<I: IntoIterator<Item = &'a T>>(&mut self, iter: I) {
self.extend(iter.into_iter().cloned());
}

#[inline]
fn extend_one(&mut self, &elem: &'a T) {
self.push_back(elem);
}
}

#[stable(feature = "rust1", since = "1.0.0")]
Expand Down
20 changes: 20 additions & 0 deletions src/liballoc/collections/vec_deque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2881,13 +2881,33 @@ impl<A> Extend<A> for VecDeque<A> {
}
}
}

#[inline]
fn extend_one(&mut self, elem: A) {
self.push_back(elem);
}

#[inline]
fn extend_reserve(&mut self, additional: usize) {
self.reserve(additional);
}
}

#[stable(feature = "extend_ref", since = "1.2.0")]
impl<'a, T: 'a + Copy> Extend<&'a T> for VecDeque<T> {
fn extend<I: IntoIterator<Item = &'a T>>(&mut self, iter: I) {
self.extend(iter.into_iter().cloned());
}

#[inline]
fn extend_one(&mut self, &elem: &T) {
self.push_back(elem);
}

#[inline]
fn extend_reserve(&mut self, additional: usize) {
self.reserve(additional);
}
}

#[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 @@ -93,6 +93,7 @@
#![feature(container_error_extra)]
#![feature(dropck_eyepatch)]
#![feature(exact_size_is_empty)]
#![feature(extend_one)]
#![feature(fmt_internals)]
#![feature(fn_traits)]
#![feature(fundamental)]
Expand Down
35 changes: 35 additions & 0 deletions src/liballoc/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1799,34 +1799,69 @@ impl Extend<char> for String {
self.reserve(lower_bound);
iterator.for_each(move |c| self.push(c));
}

#[inline]
fn extend_one(&mut self, c: char) {
self.push(c);
}

#[inline]
fn extend_reserve(&mut self, additional: usize) {
self.reserve(additional);
}
}

#[stable(feature = "extend_ref", since = "1.2.0")]
impl<'a> Extend<&'a char> for String {
fn extend<I: IntoIterator<Item = &'a char>>(&mut self, iter: I) {
self.extend(iter.into_iter().cloned());
}

#[inline]
fn extend_one(&mut self, &c: &'a char) {
self.push(c);
}

#[inline]
fn extend_reserve(&mut self, additional: usize) {
self.reserve(additional);
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a> Extend<&'a str> for String {
fn extend<I: IntoIterator<Item = &'a str>>(&mut self, iter: I) {
iter.into_iter().for_each(move |s| self.push_str(s));
}

#[inline]
fn extend_one(&mut self, s: &'a str) {
self.push_str(s);
}
}

#[stable(feature = "extend_string", since = "1.4.0")]
impl Extend<String> for String {
fn extend<I: IntoIterator<Item = String>>(&mut self, iter: I) {
iter.into_iter().for_each(move |s| self.push_str(&s));
}

#[inline]
fn extend_one(&mut self, s: String) {
self.push_str(&s);
}
}

#[stable(feature = "herd_cows", since = "1.19.0")]
impl<'a> Extend<Cow<'a, str>> for String {
fn extend<I: IntoIterator<Item = Cow<'a, str>>>(&mut self, iter: I) {
iter.into_iter().for_each(move |s| self.push_str(&s));
}

#[inline]
fn extend_one(&mut self, s: Cow<'a, str>) {
self.push_str(&s);
}
}

/// A convenience impl that delegates to the impl for `&str`.
Expand Down
20 changes: 20 additions & 0 deletions src/liballoc/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2045,6 +2045,16 @@ impl<T> Extend<T> for Vec<T> {
fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I) {
<Self as SpecExtend<T, I::IntoIter>>::spec_extend(self, iter.into_iter())
}

#[inline]
fn extend_one(&mut self, item: T) {
self.push(item);
}

#[inline]
fn extend_reserve(&mut self, additional: usize) {
self.reserve(additional);
}
}

// Specialization trait used for Vec::from_iter and Vec::extend
Expand Down Expand Up @@ -2316,6 +2326,16 @@ impl<'a, T: 'a + Copy> Extend<&'a T> for Vec<T> {
fn extend<I: IntoIterator<Item = &'a T>>(&mut self, iter: I) {
self.spec_extend(iter.into_iter())
}

#[inline]
fn extend_one(&mut self, &item: &'a T) {
self.push(item);
}

#[inline]
fn extend_reserve(&mut self, additional: usize) {
self.reserve(additional);
}
}

macro_rules! __impl_slice_eq1 {
Expand Down
2 changes: 2 additions & 0 deletions src/libcore/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1314,6 +1314,7 @@ extern "rust-intrinsic" {
/// The stabilized version of this intrinsic is
/// [`std::pointer::offset`](../../std/primitive.pointer.html#method.offset).
#[must_use = "returns a new pointer rather than modifying its argument"]
#[rustc_const_unstable(feature = "const_ptr_offset", issue = "71499")]
pub fn offset<T>(dst: *const T, offset: isize) -> *const T;

/// Calculates the offset from a pointer, potentially wrapping.
Expand All @@ -1331,6 +1332,7 @@ extern "rust-intrinsic" {
/// The stabilized version of this intrinsic is
/// [`std::pointer::wrapping_offset`](../../std/primitive.pointer.html#method.wrapping_offset).
#[must_use = "returns a new pointer rather than modifying its argument"]
#[rustc_const_unstable(feature = "const_ptr_offset", issue = "71499")]
pub fn arith_offset<T>(dst: *const T, offset: isize) -> *const T;

/// Equivalent to the appropriate `llvm.memcpy.p0i8.0i8.*` intrinsic, with
Expand Down
17 changes: 16 additions & 1 deletion src/libcore/iter/traits/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ impl<I: Iterator> IntoIterator for I {
pub trait Extend<A> {
/// Extends a collection with the contents of an iterator.
///
/// As this is the only method for this trait, the [trait-level] docs
/// As this is the only required method for this trait, the [trait-level] docs
/// contain more details.
///
/// [trait-level]: trait.Extend.html
Expand All @@ -341,11 +341,26 @@ pub trait Extend<A> {
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
fn extend<T: IntoIterator<Item = A>>(&mut self, iter: T);

/// Extends a collection with exactly one element.
#[unstable(feature = "extend_one", issue = "72631")]
fn extend_one(&mut self, item: A) {
self.extend(Some(item));
}

/// Reserves capacity in a collection for the given number of additional elements.
///
/// The default implementation does nothing.
#[unstable(feature = "extend_one", issue = "72631")]
fn extend_reserve(&mut self, additional: usize) {
let _ = additional;
}
}

#[stable(feature = "extend_for_unit", since = "1.28.0")]
impl Extend<()> for () {
fn extend<T: IntoIterator<Item = ()>>(&mut self, iter: T) {
iter.into_iter().for_each(drop)
}
fn extend_one(&mut self, _item: ()) {}
}
14 changes: 10 additions & 4 deletions src/libcore/iter/traits/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1700,9 +1700,9 @@ pub trait Iterator {
) -> impl FnMut((), T) + 'a {
move |(), x| {
if f(&x) {
left.extend(Some(x));
left.extend_one(x);
} else {
right.extend(Some(x));
right.extend_one(x);
}
}
}
Expand Down Expand Up @@ -2675,14 +2675,20 @@ pub trait Iterator {
us: &'a mut impl Extend<B>,
) -> impl FnMut((), (A, B)) + 'a {
move |(), (t, u)| {
ts.extend(Some(t));
us.extend(Some(u));
ts.extend_one(t);
us.extend_one(u);
}
}

let mut ts: FromA = Default::default();
let mut us: FromB = Default::default();

let (lower_bound, _) = self.size_hint();
if lower_bound > 0 {
ts.extend_reserve(lower_bound);
us.extend_reserve(lower_bound);
}

self.fold((), extend(&mut ts, &mut us));

(ts, us)
Expand Down
1 change: 1 addition & 0 deletions src/libcore/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
#![feature(const_panic)]
#![feature(const_fn_union)]
#![feature(const_generics)]
#![feature(const_ptr_offset)]
#![feature(const_ptr_offset_from)]
#![feature(const_result)]
#![feature(const_slice_from_raw_parts)]
Expand Down
Loading