Skip to content

Commit d52c44e

Browse files
committed
Auto merge of #49460 - kennytm:rollup, r=kennytm
Rollup of 12 pull requests - Successful merges: #49243, #49329, #49364, #49400, #49405, #49427, #49428, #49429, #49439, #49442, #49444, #49452 - Failed merges:
2 parents e5277c1 + 30560bb commit d52c44e

File tree

35 files changed

+472
-158
lines changed

35 files changed

+472
-158
lines changed

src/doc/unstable-book/src/library-features/string-retain.md

-23
This file was deleted.

src/liballoc/binary_heap.rs

+25
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,31 @@ impl<T: Ord> BinaryHeap<T> {
509509
self.data.shrink_to_fit();
510510
}
511511

512+
/// Discards capacity with a lower bound.
513+
///
514+
/// The capacity will remain at least as large as both the length
515+
/// and the supplied value.
516+
///
517+
/// Panics if the current capacity is smaller than the supplied
518+
/// minimum capacity.
519+
///
520+
/// # Examples
521+
///
522+
/// ```
523+
/// #![feature(shrink_to)]
524+
/// use std::collections::BinaryHeap;
525+
/// let mut heap: BinaryHeap<i32> = BinaryHeap::with_capacity(100);
526+
///
527+
/// assert!(heap.capacity() >= 100);
528+
/// heap.shrink_to(10);
529+
/// assert!(heap.capacity() >= 10);
530+
/// ```
531+
#[inline]
532+
#[unstable(feature = "shrink_to", reason = "new API", issue="0")]
533+
pub fn shrink_to(&mut self, min_capacity: usize) {
534+
self.data.shrink_to(min_capacity)
535+
}
536+
512537
/// Removes the greatest item from the binary heap and returns it, or `None` if it
513538
/// is empty.
514539
///

src/liballoc/string.rs

+29-3
Original file line numberDiff line numberDiff line change
@@ -1015,6 +1015,34 @@ impl String {
10151015
self.vec.shrink_to_fit()
10161016
}
10171017

1018+
/// Shrinks the capacity of this `String` with a lower bound.
1019+
///
1020+
/// The capacity will remain at least as large as both the length
1021+
/// and the supplied value.
1022+
///
1023+
/// Panics if the current capacity is smaller than the supplied
1024+
/// minimum capacity.
1025+
///
1026+
/// # Examples
1027+
///
1028+
/// ```
1029+
/// #![feature(shrink_to)]
1030+
/// let mut s = String::from("foo");
1031+
///
1032+
/// s.reserve(100);
1033+
/// assert!(s.capacity() >= 100);
1034+
///
1035+
/// s.shrink_to(10);
1036+
/// assert!(s.capacity() >= 10);
1037+
/// s.shrink_to(0);
1038+
/// assert!(s.capacity() >= 3);
1039+
/// ```
1040+
#[inline]
1041+
#[unstable(feature = "shrink_to", reason = "new API", issue="0")]
1042+
pub fn shrink_to(&mut self, min_capacity: usize) {
1043+
self.vec.shrink_to(min_capacity)
1044+
}
1045+
10181046
/// Appends the given [`char`] to the end of this `String`.
10191047
///
10201048
/// [`char`]: ../../std/primitive.char.html
@@ -1177,16 +1205,14 @@ impl String {
11771205
/// # Examples
11781206
///
11791207
/// ```
1180-
/// #![feature(string_retain)]
1181-
///
11821208
/// let mut s = String::from("f_o_ob_ar");
11831209
///
11841210
/// s.retain(|c| c != '_');
11851211
///
11861212
/// assert_eq!(s, "foobar");
11871213
/// ```
11881214
#[inline]
1189-
#[unstable(feature = "string_retain", issue = "43874")]
1215+
#[stable(feature = "string_retain", since = "1.26.0")]
11901216
pub fn retain<F>(&mut self, mut f: F)
11911217
where F: FnMut(char) -> bool
11921218
{

src/liballoc/vec.rs

+30-4
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
6767
#![stable(feature = "rust1", since = "1.0.0")]
6868

69-
use core::cmp::Ordering;
69+
use core::cmp::{self, Ordering};
7070
use core::fmt;
7171
use core::hash::{self, Hash};
7272
use core::intrinsics::{arith_offset, assume};
@@ -334,9 +334,10 @@ impl<T> Vec<T> {
334334
/// The vector will be able to hold exactly `capacity` elements without
335335
/// reallocating. If `capacity` is 0, the vector will not allocate.
336336
///
337-
/// It is important to note that this function does not specify the *length*
338-
/// of the returned vector, but only the *capacity*. For an explanation of
339-
/// the difference between length and capacity, see *[Capacity and reallocation]*.
337+
/// It is important to note that although the returned vector has the
338+
/// *capacity* specified, the vector will have a zero *length*. For an
339+
/// explanation of the difference between length and capacity, see
340+
/// *[Capacity and reallocation]*.
340341
///
341342
/// [Capacity and reallocation]: #capacity-and-reallocation
342343
///
@@ -586,6 +587,31 @@ impl<T> Vec<T> {
586587
self.buf.shrink_to_fit(self.len);
587588
}
588589

590+
/// Shrinks the capacity of the vector with a lower bound.
591+
///
592+
/// The capacity will remain at least as large as both the length
593+
/// and the supplied value.
594+
///
595+
/// Panics if the current capacity is smaller than the supplied
596+
/// minimum capacity.
597+
///
598+
/// # Examples
599+
///
600+
/// ```
601+
/// #![feature(shrink_to)]
602+
/// let mut vec = Vec::with_capacity(10);
603+
/// vec.extend([1, 2, 3].iter().cloned());
604+
/// assert_eq!(vec.capacity(), 10);
605+
/// vec.shrink_to(4);
606+
/// assert!(vec.capacity() >= 4);
607+
/// vec.shrink_to(0);
608+
/// assert!(vec.capacity() >= 3);
609+
/// ```
610+
#[unstable(feature = "shrink_to", reason = "new API", issue="0")]
611+
pub fn shrink_to(&mut self, min_capacity: usize) {
612+
self.buf.shrink_to_fit(cmp::max(self.len, min_capacity));
613+
}
614+
589615
/// Converts the vector into [`Box<[T]>`][owned slice].
590616
///
591617
/// Note that this will drop any excess capacity.

src/liballoc/vec_deque.rs

+34-1
Original file line numberDiff line numberDiff line change
@@ -676,9 +676,42 @@ impl<T> VecDeque<T> {
676676
/// ```
677677
#[stable(feature = "deque_extras_15", since = "1.5.0")]
678678
pub fn shrink_to_fit(&mut self) {
679+
self.shrink_to(0);
680+
}
681+
682+
/// Shrinks the capacity of the `VecDeque` with a lower bound.
683+
///
684+
/// The capacity will remain at least as large as both the length
685+
/// and the supplied value.
686+
///
687+
/// Panics if the current capacity is smaller than the supplied
688+
/// minimum capacity.
689+
///
690+
/// # Examples
691+
///
692+
/// ```
693+
/// #![feature(shrink_to)]
694+
/// use std::collections::VecDeque;
695+
///
696+
/// let mut buf = VecDeque::with_capacity(15);
697+
/// buf.extend(0..4);
698+
/// assert_eq!(buf.capacity(), 15);
699+
/// buf.shrink_to(6);
700+
/// assert!(buf.capacity() >= 6);
701+
/// buf.shrink_to(0);
702+
/// assert!(buf.capacity() >= 4);
703+
/// ```
704+
#[unstable(feature = "shrink_to", reason = "new API", issue="0")]
705+
pub fn shrink_to(&mut self, min_capacity: usize) {
706+
assert!(self.capacity() >= min_capacity, "Tried to shrink to a larger capacity");
707+
679708
// +1 since the ringbuffer always leaves one space empty
680709
// len + 1 can't overflow for an existing, well-formed ringbuffer.
681-
let target_cap = cmp::max(self.len() + 1, MINIMUM_CAPACITY + 1).next_power_of_two();
710+
let target_cap = cmp::max(
711+
cmp::max(min_capacity, self.len()) + 1,
712+
MINIMUM_CAPACITY + 1
713+
).next_power_of_two();
714+
682715
if target_cap < self.cap() {
683716
// There are three cases of interest:
684717
// All elements are out of desired bounds

src/librustc_const_eval/lib.rs

-59
This file was deleted.

src/librustc_driver/driver.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,9 @@ pub fn phase_2_configure_and_expand_inner<'a, F>(sess: &'a Session,
901901
Some(future) => {
902902
let prev_graph = time(sess, "blocked while dep-graph loading finishes", || {
903903
future.open()
904-
.expect("Could not join with background dep_graph thread")
904+
.unwrap_or_else(|e| rustc_incremental::LoadResult::Error {
905+
message: format!("could not decode incremental cache: {:?}", e)
906+
})
905907
.open(sess)
906908
});
907909
DepGraph::new(prev_graph)

src/librustc_incremental/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ pub use assert_dep_graph::assert_dep_graph;
3939
pub use persist::dep_graph_tcx_init;
4040
pub use persist::load_dep_graph;
4141
pub use persist::load_query_result_cache;
42+
pub use persist::LoadResult;
4243
pub use persist::save_dep_graph;
4344
pub use persist::save_trans_partition;
4445
pub use persist::save_work_products;

src/librustc_incremental/persist/load.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ impl LoadResult<PreviousDepGraph> {
8989
pub fn open(self, sess: &Session) -> PreviousDepGraph {
9090
match self {
9191
LoadResult::Error { message } => {
92-
sess.fatal(&message) /* never returns */
92+
sess.warn(&message);
93+
PreviousDepGraph::new(SerializedDepGraph::new())
9394
},
9495
LoadResult::DataOutOfDate => {
9596
if let Err(err) = delete_all_session_dir_contents(sess) {

src/librustc_incremental/persist/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pub use self::fs::prepare_session_directory;
2727
pub use self::load::dep_graph_tcx_init;
2828
pub use self::load::load_dep_graph;
2929
pub use self::load::load_query_result_cache;
30+
pub use self::load::LoadResult;
3031
pub use self::save::save_dep_graph;
3132
pub use self::save::save_work_products;
3233
pub use self::work_product::save_trans_partition;

src/librustc_trans/back/link.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,7 @@ fn link_natively(sess: &Session,
713713
// linking executables as pie. Different versions of gcc seem to use
714714
// different quotes in the error message so don't check for them.
715715
if sess.target.target.options.linker_is_gnu &&
716+
sess.linker_flavor() != LinkerFlavor::Ld &&
716717
(out.contains("unrecognized command line option") ||
717718
out.contains("unknown argument")) &&
718719
out.contains("-no-pie") &&
@@ -1008,8 +1009,9 @@ fn link_args(cmd: &mut Linker,
10081009
} else {
10091010
// recent versions of gcc can be configured to generate position
10101011
// independent executables by default. We have to pass -no-pie to
1011-
// explicitly turn that off.
1012-
if sess.target.target.options.linker_is_gnu {
1012+
// explicitly turn that off. Not applicable to ld.
1013+
if sess.target.target.options.linker_is_gnu
1014+
&& sess.linker_flavor() != LinkerFlavor::Ld {
10131015
cmd.no_position_independent_executable();
10141016
}
10151017
}

0 commit comments

Comments
 (0)