aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Vander Stoep <jeffv@google.com>2022-12-19 17:11:23 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2022-12-19 17:11:23 +0000
commit6a888e706a2da4ee4a6d686400fdf14e95cafe2e (patch)
tree9db7f5b9aee709a192b43be05d67744983fe9a75
parent37aea479d8aa9aa17b885ae0e2ab9c31f962aba3 (diff)
parentec0cac032563154c05f6f9400ef9df7d23ef4870 (diff)
downloadslab-6a888e706a2da4ee4a6d686400fdf14e95cafe2e.tar.gz
Upgrade slab to 0.4.7 am: 9b675bea75 am: 0d28f6826e am: ec0cac0325
Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/slab/+/2361864 Change-Id: I78d6787417d885d9b25c2246e6020bda90ed4b52 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--.cargo_vcs_info.json7
-rw-r--r--Android.bp5
-rw-r--r--CHANGELOG.md16
-rw-r--r--Cargo.toml25
-rw-r--r--Cargo.toml.orig10
-rw-r--r--METADATA12
-rw-r--r--build.rs24
-rw-r--r--src/lib.rs59
-rw-r--r--tests/slab.rs6
9 files changed, 139 insertions, 25 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json
index 90db974..aa15a75 100644
--- a/.cargo_vcs_info.json
+++ b/.cargo_vcs_info.json
@@ -1,5 +1,6 @@
{
"git": {
- "sha1": "c512385b1a70100c8597f0f519390c80e90c9529"
- }
-}
+ "sha1": "817a2ec227e819f308e8e4d0487084940b4ef831"
+ },
+ "path_in_vcs": ""
+} \ No newline at end of file
diff --git a/Android.bp b/Android.bp
index d6285ad..39d18c2 100644
--- a/Android.bp
+++ b/Android.bp
@@ -23,7 +23,7 @@ rust_library {
host_supported: true,
crate_name: "slab",
cargo_env_compat: true,
- cargo_pkg_version: "0.4.5",
+ cargo_pkg_version: "0.4.7",
srcs: ["src/lib.rs"],
edition: "2018",
features: [
@@ -44,7 +44,7 @@ rust_test {
host_supported: true,
crate_name: "slab",
cargo_env_compat: true,
- cargo_pkg_version: "0.4.5",
+ cargo_pkg_version: "0.4.7",
srcs: ["tests/slab.rs"],
test_suites: ["general-tests"],
auto_gen_config: true,
@@ -61,4 +61,5 @@ rust_test {
"libserde_test",
"libslab",
],
+ proc_macros: ["librustversion"],
}
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 501a25c..88ac716 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,8 +1,18 @@
+# 0.4.7 (July 19, 2022)
+
+* Use `#[track_caller]` on Rust 1.46+ (#119)
+* Make `Slab::new` const on Rust 1.39+ (#119)
+
+# 0.4.6 (April 2, 2022)
+
+* Add `Slab::vacant_key` (#114)
+* Fix stacked borrows violation in `Slab::get2_unchecked_mut` (#115)
+
# 0.4.5 (October 13, 2021)
- * Add alternate debug output for listing items in the slab (#108)
- * Fix typo in debug output of IntoIter (#109)
- * Impl 'Clone' for 'Iter' (#110)
+* Add alternate debug output for listing items in the slab (#108)
+* Fix typo in debug output of IntoIter (#109)
+* Impl 'Clone' for 'Iter' (#110)
# 0.4.4 (August 06, 2021)
diff --git a/Cargo.toml b/Cargo.toml
index e1cca93..f1c192e 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -11,23 +11,35 @@
[package]
edition = "2018"
+rust-version = "1.31"
name = "slab"
-version = "0.4.5"
+version = "0.4.7"
authors = ["Carl Lerche <me@carllerche.com>"]
exclude = ["/.*"]
description = "Pre-allocated storage for a uniform data type"
-homepage = "https://github.com/tokio-rs/slab"
-documentation = "https://docs.rs/slab"
readme = "README.md"
-keywords = ["slab", "allocator", "no_std"]
-categories = ["memory-management", "data-structures", "no-std"]
+keywords = [
+ "slab",
+ "allocator",
+ "no_std",
+]
+categories = [
+ "memory-management",
+ "data-structures",
+ "no-std",
+]
license = "MIT"
repository = "https://github.com/tokio-rs/slab"
+
[dependencies.serde]
version = "1.0.95"
features = ["alloc"]
optional = true
default-features = false
+
+[dev-dependencies.rustversion]
+version = "1"
+
[dev-dependencies.serde]
version = "1"
features = ["derive"]
@@ -35,6 +47,9 @@ features = ["derive"]
[dev-dependencies.serde_test]
version = "1"
+[build-dependencies.autocfg]
+version = "1"
+
[features]
default = ["std"]
std = []
diff --git a/Cargo.toml.orig b/Cargo.toml.orig
index bc25be8..d8f19e8 100644
--- a/Cargo.toml.orig
+++ b/Cargo.toml.orig
@@ -6,15 +6,13 @@ name = "slab"
# - README.md
# - Update CHANGELOG.md
# - Create git tag
-version = "0.4.5"
+version = "0.4.7"
authors = ["Carl Lerche <me@carllerche.com>"]
edition = "2018"
+rust-version = "1.31"
license = "MIT"
description = "Pre-allocated storage for a uniform data type"
-documentation = "https://docs.rs/slab"
-homepage = "https://github.com/tokio-rs/slab"
repository = "https://github.com/tokio-rs/slab"
-readme = "README.md"
keywords = ["slab", "allocator", "no_std"]
categories = ["memory-management", "data-structures", "no-std"]
exclude = ["/.*"]
@@ -23,9 +21,13 @@ exclude = ["/.*"]
std = []
default = ["std"]
+[build-dependencies]
+autocfg = "1"
+
[dependencies]
serde = { version = "1.0.95", optional = true, default-features = false, features = ["alloc"] }
[dev-dependencies]
+rustversion = "1"
serde = { version = "1", features = ["derive"] }
serde_test = "1"
diff --git a/METADATA b/METADATA
index 6ca4640..dbd8fc2 100644
--- a/METADATA
+++ b/METADATA
@@ -1,3 +1,7 @@
+# This project was upgraded with external_updater.
+# Usage: tools/external_updater/updater.sh update rust/crates/slab
+# For more info, check https://cs.android.com/android/platform/superproject/+/master:tools/external_updater/README.md
+
name: "slab"
description: "Pre-allocated storage for a uniform data type"
third_party {
@@ -7,13 +11,13 @@ third_party {
}
url {
type: ARCHIVE
- value: "https://static.crates.io/crates/slab/slab-0.4.5.crate"
+ value: "https://static.crates.io/crates/slab/slab-0.4.7.crate"
}
- version: "0.4.5"
+ version: "0.4.7"
license_type: NOTICE
last_upgrade_date {
year: 2022
- month: 3
- day: 1
+ month: 12
+ day: 19
}
}
diff --git a/build.rs b/build.rs
new file mode 100644
index 0000000..b60351a
--- /dev/null
+++ b/build.rs
@@ -0,0 +1,24 @@
+fn main() {
+ let cfg = match autocfg::AutoCfg::new() {
+ Ok(cfg) => cfg,
+ Err(e) => {
+ // If we couldn't detect the compiler version and features, just
+ // print a warning. This isn't a fatal error: we can still build
+ // Slab, we just can't enable cfgs automatically.
+ println!(
+ "cargo:warning=slab: failed to detect compiler features: {}",
+ e
+ );
+ return;
+ }
+ };
+ // Note that this is `no_`*, not `has_*`. This allows treating as the latest
+ // stable rustc is used when the build script doesn't run. This is useful
+ // for non-cargo build systems that don't run the build script.
+ if !cfg.probe_rustc_version(1, 39) {
+ println!("cargo:rustc-cfg=slab_no_const_vec_new");
+ }
+ if !cfg.probe_rustc_version(1, 46) {
+ println!("cargo:rustc-cfg=slab_no_track_caller");
+ }
+}
diff --git a/src/lib.rs b/src/lib.rs
index 271c1db..577f7b9 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -219,14 +219,35 @@ impl<T> Slab<T> {
/// The function does not allocate and the returned slab will have no
/// capacity until `insert` is called or capacity is explicitly reserved.
///
+ /// This is `const fn` on Rust 1.39+.
+ ///
/// # Examples
///
/// ```
/// # use slab::*;
/// let slab: Slab<i32> = Slab::new();
/// ```
- pub fn new() -> Slab<T> {
- Slab::with_capacity(0)
+ #[cfg(not(slab_no_const_vec_new))]
+ pub const fn new() -> Self {
+ Self {
+ entries: Vec::new(),
+ next: 0,
+ len: 0,
+ }
+ }
+ /// Construct a new, empty `Slab`.
+ ///
+ /// The function does not allocate and the returned slab will have no
+ /// capacity until `insert` is called or capacity is explicitly reserved.
+ ///
+ /// This is `const fn` on Rust 1.39+.
+ #[cfg(slab_no_const_vec_new)]
+ pub fn new() -> Self {
+ Self {
+ entries: Vec::new(),
+ next: 0,
+ len: 0,
+ }
}
/// Construct a new, empty `Slab` with the specified capacity.
@@ -830,8 +851,10 @@ impl<T> Slab<T> {
/// assert_eq!(slab[key2], 1);
/// ```
pub unsafe fn get2_unchecked_mut(&mut self, key1: usize, key2: usize) -> (&mut T, &mut T) {
- let ptr1 = self.entries.get_unchecked_mut(key1) as *mut Entry<T>;
- let ptr2 = self.entries.get_unchecked_mut(key2) as *mut Entry<T>;
+ debug_assert_ne!(key1, key2);
+ let ptr = self.entries.as_mut_ptr();
+ let ptr1 = ptr.add(key1);
+ let ptr2 = ptr.add(key2);
match (&mut *ptr1, &mut *ptr2) {
(&mut Entry::Occupied(ref mut val1), &mut Entry::Occupied(ref mut val2)) => {
(val1, val2)
@@ -875,6 +898,7 @@ impl<T> Slab<T> {
/// slab.key_of(bad); // this will panic
/// unreachable!();
/// ```
+ #[cfg_attr(not(slab_no_track_caller), track_caller)]
pub fn key_of(&self, present_element: &T) -> usize {
let element_ptr = present_element as *const T as usize;
let base_ptr = self.entries.as_ptr() as usize;
@@ -917,6 +941,30 @@ impl<T> Slab<T> {
key
}
+ /// Returns the key of the next vacant entry.
+ ///
+ /// This function returns the key of the vacant entry which will be used
+ /// for the next insertion. This is equivalent to
+ /// `slab.vacant_entry().key()`, but it doesn't require mutable access.
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// # use slab::*;
+ /// let mut slab = Slab::new();
+ /// assert_eq!(slab.vacant_key(), 0);
+ ///
+ /// slab.insert(0);
+ /// assert_eq!(slab.vacant_key(), 1);
+ ///
+ /// slab.insert(1);
+ /// slab.remove(0);
+ /// assert_eq!(slab.vacant_key(), 0);
+ /// ```
+ pub fn vacant_key(&self) -> usize {
+ self.next
+ }
+
/// Return a handle to a vacant entry allowing for further manipulation.
///
/// This function is useful when creating values that must contain their
@@ -1019,6 +1067,7 @@ impl<T> Slab<T> {
/// assert_eq!(slab.remove(hello), "hello");
/// assert!(!slab.contains(hello));
/// ```
+ #[cfg_attr(not(slab_no_track_caller), track_caller)]
pub fn remove(&mut self, key: usize) -> T {
self.try_remove(key).expect("invalid key")
}
@@ -1126,6 +1175,7 @@ impl<T> Slab<T> {
impl<T> ops::Index<usize> for Slab<T> {
type Output = T;
+ #[cfg_attr(not(slab_no_track_caller), track_caller)]
fn index(&self, key: usize) -> &T {
match self.entries.get(key) {
Some(&Entry::Occupied(ref v)) => v,
@@ -1135,6 +1185,7 @@ impl<T> ops::Index<usize> for Slab<T> {
}
impl<T> ops::IndexMut<usize> for Slab<T> {
+ #[cfg_attr(not(slab_no_track_caller), track_caller)]
fn index_mut(&mut self, key: usize) -> &mut T {
match self.entries.get_mut(key) {
Some(&mut Entry::Occupied(ref mut v)) => v,
diff --git a/tests/slab.rs b/tests/slab.rs
index 8b03c1e..34371d1 100644
--- a/tests/slab.rs
+++ b/tests/slab.rs
@@ -698,3 +698,9 @@ fn try_remove() {
assert_eq!(slab.try_remove(key), None);
assert_eq!(slab.get(key), None);
}
+
+#[rustversion::since(1.39)]
+#[test]
+fn const_new() {
+ static _SLAB: Slab<()> = Slab::new();
+}