Stabilize try_reserve

This commit is contained in:
Kornel 2021-08-29 23:21:33 +01:00
parent d25de31a0e
commit 00152d8977
16 changed files with 14 additions and 42 deletions

View File

@ -31,7 +31,7 @@
// //
// Missing HashMap API: // Missing HashMap API:
// all hasher-related // all hasher-related
// try_reserve (unstable) // try_reserve
// shrink_to (unstable) // shrink_to (unstable)
// drain_filter (unstable) // drain_filter (unstable)
// into_keys/into_values (unstable) // into_keys/into_values (unstable)

View File

@ -13,7 +13,7 @@
// //
// Missing HashSet API: // Missing HashSet API:
// all hasher-related // all hasher-related
// try_reserve (unstable) // try_reserve
// shrink_to (unstable) // shrink_to (unstable)
// drain_filter (unstable) // drain_filter (unstable)
// replace // replace

View File

@ -54,7 +54,6 @@
#![feature(thread_local_const_init)] #![feature(thread_local_const_init)]
#![feature(trusted_step)] #![feature(trusted_step)]
#![feature(try_blocks)] #![feature(try_blocks)]
#![feature(try_reserve)]
#![feature(try_reserve_kind)] #![feature(try_reserve_kind)]
#![feature(nonzero_ops)] #![feature(nonzero_ops)]
#![recursion_limit = "512"] #![recursion_limit = "512"]

View File

@ -57,7 +57,7 @@ pub mod btree_set {
/// The error type for `try_reserve` methods. /// The error type for `try_reserve` methods.
#[derive(Clone, PartialEq, Eq, Debug)] #[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 { pub struct TryReserveError {
kind: TryReserveErrorKind, kind: TryReserveErrorKind,
} }
@ -126,7 +126,7 @@ fn from(_: LayoutError) -> Self {
} }
} }
#[unstable(feature = "try_reserve", reason = "new API", issue = "48043")] #[stable(feature = "try_reserve", since = "1.57.0")]
impl Display for TryReserveError { impl Display for TryReserveError {
fn fmt( fn fmt(
&self, &self,

View File

@ -711,7 +711,6 @@ pub fn reserve(&mut self, additional: usize) {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// #![feature(try_reserve)]
/// use std::collections::TryReserveError; /// use std::collections::TryReserveError;
/// use std::collections::VecDeque; /// use std::collections::VecDeque;
/// ///
@ -730,7 +729,7 @@ pub fn reserve(&mut self, additional: usize) {
/// } /// }
/// # process_data(&[1, 2, 3]).expect("why is the test harness OOMing on 12 bytes?"); /// # 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> { pub fn try_reserve_exact(&mut self, additional: usize) -> Result<(), TryReserveError> {
self.try_reserve(additional) self.try_reserve(additional)
} }
@ -749,7 +748,6 @@ pub fn try_reserve_exact(&mut self, additional: usize) -> Result<(), TryReserveE
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// #![feature(try_reserve)]
/// use std::collections::TryReserveError; /// use std::collections::TryReserveError;
/// use std::collections::VecDeque; /// use std::collections::VecDeque;
/// ///
@ -768,7 +766,7 @@ pub fn try_reserve_exact(&mut self, additional: usize) -> Result<(), TryReserveE
/// } /// }
/// # process_data(&[1, 2, 3]).expect("why is the test harness OOMing on 12 bytes?"); /// # 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> { pub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError> {
let old_cap = self.cap(); let old_cap = self.cap();
let used_cap = self.len() + 1; let used_cap = self.len() + 1;

View File

@ -1009,7 +1009,6 @@ pub fn reserve_exact(&mut self, additional: usize) {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// #![feature(try_reserve)]
/// use std::collections::TryReserveError; /// use std::collections::TryReserveError;
/// ///
/// fn process_data(data: &str) -> Result<String, TryReserveError> { /// fn process_data(data: &str) -> Result<String, TryReserveError> {
@ -1025,7 +1024,7 @@ pub fn reserve_exact(&mut self, additional: usize) {
/// } /// }
/// # process_data("rust").expect("why is the test harness OOMing on 4 bytes?"); /// # 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> { pub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError> {
self.vec.try_reserve(additional) self.vec.try_reserve(additional)
} }
@ -1049,7 +1048,6 @@ pub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError>
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// #![feature(try_reserve)]
/// use std::collections::TryReserveError; /// use std::collections::TryReserveError;
/// ///
/// fn process_data(data: &str) -> Result<String, TryReserveError> { /// fn process_data(data: &str) -> Result<String, TryReserveError> {
@ -1065,7 +1063,7 @@ pub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError>
/// } /// }
/// # process_data("rust").expect("why is the test harness OOMing on 4 bytes?"); /// # 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> { pub fn try_reserve_exact(&mut self, additional: usize) -> Result<(), TryReserveError> {
self.vec.try_reserve_exact(additional) self.vec.try_reserve_exact(additional)
} }

View File

@ -849,7 +849,6 @@ pub fn reserve_exact(&mut self, additional: usize) {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// #![feature(try_reserve)]
/// use std::collections::TryReserveError; /// use std::collections::TryReserveError;
/// ///
/// fn process_data(data: &[u32]) -> Result<Vec<u32>, TryReserveError> { /// fn process_data(data: &[u32]) -> Result<Vec<u32>, TryReserveError> {
@ -867,7 +866,7 @@ pub fn reserve_exact(&mut self, additional: usize) {
/// } /// }
/// # process_data(&[1, 2, 3]).expect("why is the test harness OOMing on 12 bytes?"); /// # 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> { pub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError> {
self.buf.try_reserve(self.len, additional) self.buf.try_reserve(self.len, additional)
} }
@ -892,7 +891,6 @@ pub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError>
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// #![feature(try_reserve)]
/// use std::collections::TryReserveError; /// use std::collections::TryReserveError;
/// ///
/// fn process_data(data: &[u32]) -> Result<Vec<u32>, TryReserveError> { /// fn process_data(data: &[u32]) -> Result<Vec<u32>, TryReserveError> {
@ -910,7 +908,7 @@ pub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError>
/// } /// }
/// # process_data(&[1, 2, 3]).expect("why is the test harness OOMing on 12 bytes?"); /// # 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> { pub fn try_reserve_exact(&mut self, additional: usize) -> Result<(), TryReserveError> {
self.buf.try_reserve_exact(self.len, additional) self.buf.try_reserve_exact(self.len, additional)
} }

View File

@ -8,7 +8,6 @@
#![feature(new_uninit)] #![feature(new_uninit)]
#![feature(pattern)] #![feature(pattern)]
#![feature(trusted_len)] #![feature(trusted_len)]
#![feature(try_reserve)]
#![feature(try_reserve_kind)] #![feature(try_reserve_kind)]
#![feature(unboxed_closures)] #![feature(unboxed_closures)]
#![feature(associated_type_bounds)] #![feature(associated_type_bounds)]

View File

@ -625,14 +625,13 @@ pub fn reserve(&mut self, additional: usize) {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// #![feature(try_reserve)]
/// use std::collections::HashMap; /// use std::collections::HashMap;
/// ///
/// let mut map: HashMap<&str, isize> = HashMap::new(); /// let mut map: HashMap<&str, isize> = HashMap::new();
/// map.try_reserve(10).expect("why is the test harness OOMing on 10 bytes?"); /// map.try_reserve(10).expect("why is the test harness OOMing on 10 bytes?");
/// ``` /// ```
#[inline] #[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> { pub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError> {
self.base.try_reserve(additional).map_err(map_try_reserve_error) self.base.try_reserve(additional).map_err(map_try_reserve_error)
} }

View File

@ -423,13 +423,12 @@ pub fn reserve(&mut self, additional: usize) {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// #![feature(try_reserve)]
/// use std::collections::HashSet; /// use std::collections::HashSet;
/// let mut set: HashSet<i32> = HashSet::new(); /// let mut set: HashSet<i32> = HashSet::new();
/// set.try_reserve(10).expect("why is the test harness OOMing on 10 bytes?"); /// set.try_reserve(10).expect("why is the test harness OOMing on 10 bytes?");
/// ``` /// ```
#[inline] #[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> { pub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError> {
self.base.try_reserve(additional).map_err(map_try_reserve_error) self.base.try_reserve(additional).map_err(map_try_reserve_error)
} }

View File

@ -420,7 +420,7 @@
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
pub use self::hash_set::HashSet; 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; pub use alloc_crate::collections::TryReserveError;
#[unstable( #[unstable(
feature = "try_reserve_kind", feature = "try_reserve_kind",

View File

@ -595,7 +595,7 @@ fn description(&self) -> &str {
} }
} }
#[unstable(feature = "try_reserve", reason = "new API", issue = "48043")] #[stable(feature = "try_reserve", since = "1.57.0")]
impl Error for alloc::collections::TryReserveError {} impl Error for alloc::collections::TryReserveError {}
#[unstable(feature = "duration_checked_float", issue = "83400")] #[unstable(feature = "duration_checked_float", issue = "83400")]

View File

@ -331,7 +331,6 @@
#![feature(total_cmp)] #![feature(total_cmp)]
#![feature(trace_macros)] #![feature(trace_macros)]
#![feature(try_blocks)] #![feature(try_blocks)]
#![feature(try_reserve)]
#![feature(try_reserve_kind)] #![feature(try_reserve_kind)]
#![feature(unboxed_closures)] #![feature(unboxed_closures)]
#![feature(unwrap_infallible)] #![feature(unwrap_infallible)]

View File

@ -1,5 +1,4 @@
// check-pass // check-pass
#![feature(try_reserve)]
fn main() { fn main() {
let mut schema_all: (Vec<String>, Vec<String>) = (vec![], vec![]); let mut schema_all: (Vec<String>, Vec<String>) = (vec![], vec![]);

View File

@ -1,4 +0,0 @@
fn main() {
let v = Vec::new();
v.try_reserve(10); //~ ERROR: use of unstable library feature 'try_reserve'
}

View File

@ -1,12 +0,0 @@
error[E0658]: use of unstable library feature 'try_reserve': new API
--> $DIR/feature-gate-try_reserve.rs:3:7
|
LL | v.try_reserve(10);
| ^^^^^^^^^^^
|
= note: see issue #48043 <https://github.com/rust-lang/rust/issues/48043> for more information
= help: add `#![feature(try_reserve)]` to the crate attributes to enable
error: aborting due to previous error
For more information about this error, try `rustc --explain E0658`.