Skip to content

Commit

Permalink
Rollup merge of rust-lang#87993 - kornelski:try_reserve_stable, r=jos…
Browse files Browse the repository at this point in the history
…htriplett

Stabilize try_reserve

Stabilization PR for the [`try_reserve` feature](rust-lang#48043 (comment)).
  • Loading branch information
Manishearth authored Oct 5, 2021
2 parents 003d8d3 + 00152d8 commit 279cb9c
Show file tree
Hide file tree
Showing 16 changed files with 14 additions and 42 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_data_structures/src/sso/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const SSO_ARRAY_SIZE: usize = 8;
//
// Missing HashMap API:
// all hasher-related
// try_reserve (unstable)
// try_reserve
// shrink_to (unstable)
// drain_filter (unstable)
// into_keys/into_values (unstable)
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_data_structures/src/sso/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use super::map::SsoHashMap;
//
// Missing HashSet API:
// all hasher-related
// try_reserve (unstable)
// try_reserve
// shrink_to (unstable)
// drain_filter (unstable)
// replace
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_middle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
#![feature(thread_local_const_init)]
#![feature(trusted_step)]
#![feature(try_blocks)]
#![feature(try_reserve)]
#![feature(try_reserve_kind)]
#![feature(nonzero_ops)]
#![recursion_limit = "512"]
Expand Down
4 changes: 2 additions & 2 deletions library/alloc/src/collections/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ use core::fmt::Display;

/// The error type for `try_reserve` methods.
#[derive(Clone, PartialEq, Eq, Debug)]
#[unstable(feature = "try_reserve", reason = "new API", issue = "48043")]
#[stable(feature = "try_reserve", since = "1.57.0")]
pub struct TryReserveError {
kind: TryReserveErrorKind,
}
Expand Down Expand Up @@ -126,7 +126,7 @@ impl From<LayoutError> for TryReserveErrorKind {
}
}

#[unstable(feature = "try_reserve", reason = "new API", issue = "48043")]
#[stable(feature = "try_reserve", since = "1.57.0")]
impl Display for TryReserveError {
fn fmt(
&self,
Expand Down
6 changes: 2 additions & 4 deletions library/alloc/src/collections/vec_deque/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,6 @@ impl<T, A: Allocator> VecDeque<T, A> {
/// # Examples
///
/// ```
/// #![feature(try_reserve)]
/// use std::collections::TryReserveError;
/// use std::collections::VecDeque;
///
Expand All @@ -730,7 +729,7 @@ impl<T, A: Allocator> VecDeque<T, A> {
/// }
/// # process_data(&[1, 2, 3]).expect("why is the test harness OOMing on 12 bytes?");
/// ```
#[unstable(feature = "try_reserve", reason = "new API", issue = "48043")]
#[stable(feature = "try_reserve", since = "1.57.0")]
pub fn try_reserve_exact(&mut self, additional: usize) -> Result<(), TryReserveError> {
self.try_reserve(additional)
}
Expand All @@ -749,7 +748,6 @@ impl<T, A: Allocator> VecDeque<T, A> {
/// # Examples
///
/// ```
/// #![feature(try_reserve)]
/// use std::collections::TryReserveError;
/// use std::collections::VecDeque;
///
Expand All @@ -768,7 +766,7 @@ impl<T, A: Allocator> VecDeque<T, A> {
/// }
/// # process_data(&[1, 2, 3]).expect("why is the test harness OOMing on 12 bytes?");
/// ```
#[unstable(feature = "try_reserve", reason = "new API", issue = "48043")]
#[stable(feature = "try_reserve", since = "1.57.0")]
pub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError> {
let old_cap = self.cap();
let used_cap = self.len() + 1;
Expand Down
6 changes: 2 additions & 4 deletions library/alloc/src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1009,7 +1009,6 @@ impl String {
/// # Examples
///
/// ```
/// #![feature(try_reserve)]
/// use std::collections::TryReserveError;
///
/// fn process_data(data: &str) -> Result<String, TryReserveError> {
Expand All @@ -1025,7 +1024,7 @@ impl String {
/// }
/// # process_data("rust").expect("why is the test harness OOMing on 4 bytes?");
/// ```
#[unstable(feature = "try_reserve", reason = "new API", issue = "48043")]
#[stable(feature = "try_reserve", since = "1.57.0")]
pub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError> {
self.vec.try_reserve(additional)
}
Expand All @@ -1049,7 +1048,6 @@ impl String {
/// # Examples
///
/// ```
/// #![feature(try_reserve)]
/// use std::collections::TryReserveError;
///
/// fn process_data(data: &str) -> Result<String, TryReserveError> {
Expand All @@ -1065,7 +1063,7 @@ impl String {
/// }
/// # process_data("rust").expect("why is the test harness OOMing on 4 bytes?");
/// ```
#[unstable(feature = "try_reserve", reason = "new API", issue = "48043")]
#[stable(feature = "try_reserve", since = "1.57.0")]
pub fn try_reserve_exact(&mut self, additional: usize) -> Result<(), TryReserveError> {
self.vec.try_reserve_exact(additional)
}
Expand Down
6 changes: 2 additions & 4 deletions library/alloc/src/vec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,6 @@ impl<T, A: Allocator> Vec<T, A> {
/// # Examples
///
/// ```
/// #![feature(try_reserve)]
/// use std::collections::TryReserveError;
///
/// fn process_data(data: &[u32]) -> Result<Vec<u32>, TryReserveError> {
Expand All @@ -867,7 +866,7 @@ impl<T, A: Allocator> Vec<T, A> {
/// }
/// # process_data(&[1, 2, 3]).expect("why is the test harness OOMing on 12 bytes?");
/// ```
#[unstable(feature = "try_reserve", reason = "new API", issue = "48043")]
#[stable(feature = "try_reserve", since = "1.57.0")]
pub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError> {
self.buf.try_reserve(self.len, additional)
}
Expand All @@ -892,7 +891,6 @@ impl<T, A: Allocator> Vec<T, A> {
/// # Examples
///
/// ```
/// #![feature(try_reserve)]
/// use std::collections::TryReserveError;
///
/// fn process_data(data: &[u32]) -> Result<Vec<u32>, TryReserveError> {
Expand All @@ -910,7 +908,7 @@ impl<T, A: Allocator> Vec<T, A> {
/// }
/// # process_data(&[1, 2, 3]).expect("why is the test harness OOMing on 12 bytes?");
/// ```
#[unstable(feature = "try_reserve", reason = "new API", issue = "48043")]
#[stable(feature = "try_reserve", since = "1.57.0")]
pub fn try_reserve_exact(&mut self, additional: usize) -> Result<(), TryReserveError> {
self.buf.try_reserve_exact(self.len, additional)
}
Expand Down
1 change: 0 additions & 1 deletion library/alloc/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#![feature(new_uninit)]
#![feature(pattern)]
#![feature(trusted_len)]
#![feature(try_reserve)]
#![feature(try_reserve_kind)]
#![feature(unboxed_closures)]
#![feature(associated_type_bounds)]
Expand Down
3 changes: 1 addition & 2 deletions library/std/src/collections/hash/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -625,14 +625,13 @@ where
/// # Examples
///
/// ```
/// #![feature(try_reserve)]
/// use std::collections::HashMap;
///
/// let mut map: HashMap<&str, isize> = HashMap::new();
/// map.try_reserve(10).expect("why is the test harness OOMing on 10 bytes?");
/// ```
#[inline]
#[unstable(feature = "try_reserve", reason = "new API", issue = "48043")]
#[stable(feature = "try_reserve", since = "1.57.0")]
pub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError> {
self.base.try_reserve(additional).map_err(map_try_reserve_error)
}
Expand Down
3 changes: 1 addition & 2 deletions library/std/src/collections/hash/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,13 +423,12 @@ where
/// # Examples
///
/// ```
/// #![feature(try_reserve)]
/// use std::collections::HashSet;
/// let mut set: HashSet<i32> = HashSet::new();
/// set.try_reserve(10).expect("why is the test harness OOMing on 10 bytes?");
/// ```
#[inline]
#[unstable(feature = "try_reserve", reason = "new API", issue = "48043")]
#[stable(feature = "try_reserve", since = "1.57.0")]
pub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError> {
self.base.try_reserve(additional).map_err(map_try_reserve_error)
}
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/collections/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ pub use self::hash_map::HashMap;
#[stable(feature = "rust1", since = "1.0.0")]
pub use self::hash_set::HashSet;

#[unstable(feature = "try_reserve", reason = "new API", issue = "48043")]
#[stable(feature = "try_reserve", since = "1.57.0")]
pub use alloc_crate::collections::TryReserveError;
#[unstable(
feature = "try_reserve_kind",
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ impl Error for char::ParseCharError {
}
}

#[unstable(feature = "try_reserve", reason = "new API", issue = "48043")]
#[stable(feature = "try_reserve", since = "1.57.0")]
impl Error for alloc::collections::TryReserveError {}

#[unstable(feature = "duration_checked_float", issue = "83400")]
Expand Down
1 change: 0 additions & 1 deletion library/std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,6 @@
#![feature(total_cmp)]
#![feature(trace_macros)]
#![feature(try_blocks)]
#![feature(try_reserve)]
#![feature(try_reserve_kind)]
#![feature(unboxed_closures)]
#![feature(unwrap_infallible)]
Expand Down
1 change: 0 additions & 1 deletion src/test/ui/closures/issue-87814-2.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// check-pass
#![feature(try_reserve)]

fn main() {
let mut schema_all: (Vec<String>, Vec<String>) = (vec![], vec![]);
Expand Down
4 changes: 0 additions & 4 deletions src/test/ui/feature-gates/feature-gate-try_reserve.rs

This file was deleted.

12 changes: 0 additions & 12 deletions src/test/ui/feature-gates/feature-gate-try_reserve.stderr

This file was deleted.

0 comments on commit 279cb9c

Please sign in to comment.