diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-19 09:26:03 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-19 09:26:03 +0000 |
commit | 9918693037dce8aa4bb6f08741b6812923486c18 (patch) | |
tree | 21d2b40bec7e6a7ea664acee056eb3d08e15a1cf /vendor/self_cell | |
parent | Releasing progress-linux version 1.75.0+dfsg1-5~progress7.99u1. (diff) | |
download | rustc-9918693037dce8aa4bb6f08741b6812923486c18.tar.xz rustc-9918693037dce8aa4bb6f08741b6812923486c18.zip |
Merging upstream version 1.76.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/self_cell')
-rw-r--r-- | vendor/self_cell/.cargo-checksum.json | 2 | ||||
-rw-r--r-- | vendor/self_cell/Cargo.toml | 26 | ||||
-rw-r--r-- | vendor/self_cell/README.md | 18 | ||||
-rw-r--r-- | vendor/self_cell/src/lib.rs | 33 | ||||
-rw-r--r-- | vendor/self_cell/src/unsafe_self_cell.rs | 21 |
5 files changed, 59 insertions, 41 deletions
diff --git a/vendor/self_cell/.cargo-checksum.json b/vendor/self_cell/.cargo-checksum.json index 303f1e05f..4c3ac958a 100644 --- a/vendor/self_cell/.cargo-checksum.json +++ b/vendor/self_cell/.cargo-checksum.json @@ -1 +1 @@ -{"files":{"Cargo.toml":"ab60ad0024cea3e0c60fc4d116adc7fae35d5f85b042d285bba65f22c42407d5","LICENSE":"c71d239df91726fc519c6eb72d318ec65820627232b2f796219e87dcf35d0ab4","README.md":"51dac2de0fd70602457b5f94f96c765385adfb2b14266c4c83946c89968e0886","src/lib.rs":"1127bdfd2390f17eac015e9379ad72a8d9bfbb057bc82ed2e386f1b074c83b06","src/unsafe_self_cell.rs":"fb2b71ea2057085dcc8ff1430f8684f67aa08e1519cd51704d264593819bf3fb"},"package":"1ef965a420fe14fdac7dd018862966a4c14094f900e1650bbc71ddd7d580c8af"}
\ No newline at end of file +{"files":{"Cargo.toml":"23f841dba94fa7fe766d12dd678929c4b699089ad1cf52bbd0f9e50ae04c30d0","LICENSE":"c71d239df91726fc519c6eb72d318ec65820627232b2f796219e87dcf35d0ab4","README.md":"212bd1321e9db9669af44b685e747ff9f93f42c1682cddfabd850dc0e7e60d9f","src/lib.rs":"685d62032a35faa9519dc0ae725dd9c3c28d600f80e2bac626d90f54bc470c67","src/unsafe_self_cell.rs":"9db2f5b2d33c19fc5c52f4fd2a5d80cf3af05ec86308c2ba85924f0708f0ce6f"},"package":"e388332cd64eb80cd595a00941baf513caffae8dce9cfd0467fc9c66397dade6"}
\ No newline at end of file diff --git a/vendor/self_cell/Cargo.toml b/vendor/self_cell/Cargo.toml index f8ba952e5..3cf65b5c9 100644 --- a/vendor/self_cell/Cargo.toml +++ b/vendor/self_cell/Cargo.toml @@ -12,21 +12,37 @@ [package] edition = "2018" name = "self_cell" -version = "0.10.2" +version = "1.0.2" authors = ["Lukas Bergdoll <lukas.bergdoll@gmail.com>"] -include = ["src/*.rs", "Cargo.toml", "README.md", "LICENSE"] +include = [ + "src/*.rs", + "Cargo.toml", + "README.md", + "LICENSE", +] description = "Safe-to-use proc-macro-free self-referential structs in stable Rust." documentation = "https://docs.rs/self_cell" readme = "README.md" -keywords = ["lifetime", "borrowing", "self", "reference", "intrusive"] -categories = ["rust-patterns", "memory-management"] +keywords = [ + "lifetime", + "borrowing", + "self", + "reference", + "intrusive", +] +categories = [ + "rust-patterns", + "memory-management", +] license = "Apache-2.0" repository = "https://github.com/Voultapher/self_cell" + [dependencies.rustversion] version = ">=1" optional = true + [dev-dependencies.once_cell] -version = ">=1" +version = "=1.1.0" [features] old_rust = ["rustversion"] diff --git a/vendor/self_cell/README.md b/vendor/self_cell/README.md index 819bdc87c..dc8e8078f 100644 --- a/vendor/self_cell/README.md +++ b/vendor/self_cell/README.md @@ -143,15 +143,13 @@ cargo miri test ### Related projects -[ouroboros](https://github.com/joshua-maros/ouroboros) - -[rental](https://github.com/jpernst/rental) - -[Schroedinger](https://github.com/dureuill/sc) - -[owning_ref](https://github.com/Kimundi/owning-ref-rs) - -[ghost-cell](https://github.com/matthieu-m/ghost-cell) +- [ouroboros](https://github.com/joshua-maros/ouroboros) +- [rental](https://github.com/jpernst/rental) | soundness issues (tests fail with recent miri versions) and [deprecated](https://github.com/jpernst/rental#warning-this-crate-is-no-longer-maintained-or-supported) +- [Schroedinger](https://github.com/dureuill/sc) | [soundness issues](https://github.com/dureuill/sc/issues/1) +- [owning_ref](https://github.com/Kimundi/owning-ref-rs) | [soundness issues](https://rustsec.org/advisories/RUSTSEC-2022-0040.html) and [seems unmaintained](https://github.com/Kimundi/owning-ref-rs/issues/81) +- [ghost-cell](https://github.com/matthieu-m/ghost-cell) +- [qcell](https://github.com/uazu/qcell/) +- [selfref](https://docs.rs/selfref) ## Min required rustc version @@ -162,7 +160,7 @@ support down to rustc version 1.36. However this requires polyfilling std library functionality for older rustc with technically UB versions. Testing does not show older rustc versions (ab)using this. Use at your own risk. -The minimum versions are a best effor and may change with any new major release. +The minimum versions are best-effort and may change with any new major release. ## Contributing diff --git a/vendor/self_cell/src/lib.rs b/vendor/self_cell/src/lib.rs index e2d8f2ee6..4f764df9d 100644 --- a/vendor/self_cell/src/lib.rs +++ b/vendor/self_cell/src/lib.rs @@ -263,7 +263,7 @@ pub mod unsafe_self_cell; /// /// * **covariant**: This generates the direct reference accessor function /// `borrow_dependent`. This is only safe to do if this compiles `fn -/// _assert_covariance<'x: 'y, 'y>(x: $Dependent<'x>) -> $Dependent<'y> +/// _assert_covariance<'x: 'y, 'y>(x: &'y $Dependent<'x>) -> &'y $Dependent<'y> /// {x}`. Otherwise you could choose a lifetime that is too short for types /// with interior mutability like `Cell`, which can lead to UB in safe code. /// Which would violate the promise of this library that it is safe-to-use. @@ -337,6 +337,12 @@ macro_rules! self_cell { } impl $(<$OwnerLifetime>)? $StructName $(<$OwnerLifetime>)? { + /// Constructs a new self-referential struct. + /// + /// The provided `owner` will be moved into a heap allocated box. + /// Followed by construction of the dependent value, by calling + /// `dependent_builder` with a shared reference to the owner that + /// remains valid for the lifetime of the constructed struct. $Vis fn new( owner: $Owner, dependent_builder: impl for<'_q> FnOnce(&'_q $Owner) -> $Dependent<'_q> @@ -364,9 +370,7 @@ macro_rules! self_cell { let joined_void_ptr = NonNull::new($crate::alloc::alloc::alloc(layout)).unwrap(); - let mut joined_ptr = core::mem::transmute::<NonNull<u8>, NonNull<JoinedCell>>( - joined_void_ptr - ); + let mut joined_ptr = joined_void_ptr.cast::<JoinedCell>(); let (owner_ptr, dependent_ptr) = JoinedCell::_field_pointers(joined_ptr.as_ptr()); @@ -390,6 +394,9 @@ macro_rules! self_cell { } } + /// Tries to create a new structure with a given dependent builder. + /// + /// Consumes owner on error. $Vis fn try_new<Err>( owner: $Owner, dependent_builder: @@ -408,9 +415,7 @@ macro_rules! self_cell { let joined_void_ptr = NonNull::new($crate::alloc::alloc::alloc(layout)).unwrap(); - let mut joined_ptr = core::mem::transmute::<NonNull<u8>, NonNull<JoinedCell>>( - joined_void_ptr - ); + let mut joined_ptr = joined_void_ptr.cast::<JoinedCell>(); let (owner_ptr, dependent_ptr) = JoinedCell::_field_pointers(joined_ptr.as_ptr()); @@ -438,6 +443,9 @@ macro_rules! self_cell { } } + /// Tries to create a new structure with a given dependent builder. + /// + /// Returns owner on error. $Vis fn try_new_or_recover<Err>( owner: $Owner, dependent_builder: @@ -456,9 +464,7 @@ macro_rules! self_cell { let joined_void_ptr = NonNull::new($crate::alloc::alloc::alloc(layout)).unwrap(); - let mut joined_ptr = core::mem::transmute::<NonNull<u8>, NonNull<JoinedCell>>( - joined_void_ptr - ); + let mut joined_ptr = joined_void_ptr.cast::<JoinedCell>(); let (owner_ptr, dependent_ptr) = JoinedCell::_field_pointers(joined_ptr.as_ptr()); @@ -499,10 +505,12 @@ macro_rules! self_cell { } } + /// Borrows owner. $Vis fn borrow_owner<'_q>(&'_q self) -> &'_q $Owner { unsafe { self.unsafe_self_cell.borrow_owner::<$Dependent<'_q>>() } } + /// Calls given closure `func` with a shared reference to dependent. $Vis fn with_dependent<'outer_fn, Ret>( &'outer_fn self, func: impl for<'_q> FnOnce(&'_q $Owner, &'outer_fn $Dependent<'_q> @@ -515,6 +523,7 @@ macro_rules! self_cell { } } + /// Calls given closure `func` with an unique reference to dependent. $Vis fn with_dependent_mut<'outer_fn, Ret>( &'outer_fn mut self, func: impl for<'_q> FnOnce(&'_q $Owner, &'outer_fn mut $Dependent<'_q>) -> Ret @@ -528,6 +537,7 @@ macro_rules! self_cell { $crate::_covariant_access!($Covariance, $Vis, $Dependent); + /// Consumes `self` and returns the the owner. $Vis fn into_owner(self) -> $Owner { // This is only safe to do with repr(transparent). let unsafe_self_cell = unsafe { core::mem::transmute::< @@ -565,8 +575,9 @@ macro_rules! self_cell { #[macro_export] macro_rules! _covariant_access { (covariant, $Vis:vis, $Dependent:ident) => { + /// Borrows dependent. $Vis fn borrow_dependent<'_q>(&'_q self) -> &'_q $Dependent<'_q> { - fn _assert_covariance<'x: 'y, 'y>(x: $Dependent<'x>) -> $Dependent<'y> { + fn _assert_covariance<'x: 'y, 'y>(x: &'y $Dependent<'x>) -> &'y $Dependent<'y> { // This function only compiles for covariant types. x // Change the macro invocation to not_covariant. } diff --git a/vendor/self_cell/src/unsafe_self_cell.rs b/vendor/self_cell/src/unsafe_self_cell.rs index b0b934d6f..f661f10b4 100644 --- a/vendor/self_cell/src/unsafe_self_cell.rs +++ b/vendor/self_cell/src/unsafe_self_cell.rs @@ -1,5 +1,5 @@ use core::marker::PhantomData; -use core::mem::{self, transmute}; +use core::mem; use core::ptr::{drop_in_place, read, NonNull}; extern crate alloc; @@ -53,22 +53,19 @@ impl<ContainedIn, Owner, DependentStatic> UnsafeSelfCell<ContainedIn, Owner, Dep // Calling any of these *unsafe* functions with the wrong Dependent type is UB. pub unsafe fn borrow_owner<'a, Dependent>(&'a self) -> &'a Owner { - let joined_ptr = - transmute::<NonNull<u8>, NonNull<JoinedCell<Owner, Dependent>>>(self.joined_void_ptr); + let joined_ptr = self.joined_void_ptr.cast::<JoinedCell<Owner, Dependent>>(); &(*joined_ptr.as_ptr()).owner } pub unsafe fn borrow_dependent<'a, Dependent>(&'a self) -> &'a Dependent { - let joined_ptr = - transmute::<NonNull<u8>, NonNull<JoinedCell<Owner, Dependent>>>(self.joined_void_ptr); + let joined_ptr = self.joined_void_ptr.cast::<JoinedCell<Owner, Dependent>>(); &(*joined_ptr.as_ptr()).dependent } pub unsafe fn borrow_mut<'a, Dependent>(&'a mut self) -> (&'a Owner, &'a mut Dependent) { - let joined_ptr = - transmute::<NonNull<u8>, NonNull<JoinedCell<Owner, Dependent>>>(self.joined_void_ptr); + let joined_ptr = self.joined_void_ptr.cast::<JoinedCell<Owner, Dependent>>(); // This function used to return `&'a mut JoinedCell<Owner, Dependent>`. // It now creates two references to the fields instead to avoid claiming mutable access @@ -81,8 +78,7 @@ impl<ContainedIn, Owner, DependentStatic> UnsafeSelfCell<ContainedIn, Owner, Dep // Any subsequent use of this struct other than dropping it is UB. pub unsafe fn drop_joined<Dependent>(&mut self) { - let joined_ptr = - transmute::<NonNull<u8>, NonNull<JoinedCell<Owner, Dependent>>>(self.joined_void_ptr); + let joined_ptr = self.joined_void_ptr.cast::<JoinedCell<Owner, Dependent>>(); // Also used in case drop_in_place(...dependent) fails let _guard = OwnerAndCellDropGuard { joined_ptr }; @@ -98,8 +94,7 @@ impl<ContainedIn, Owner, DependentStatic> UnsafeSelfCell<ContainedIn, Owner, Dep } pub unsafe fn into_owner<Dependent>(self) -> Owner { - let joined_ptr = - transmute::<NonNull<u8>, NonNull<JoinedCell<Owner, Dependent>>>(self.joined_void_ptr); + let joined_ptr = self.joined_void_ptr.cast::<JoinedCell<Owner, Dependent>>(); // In case drop_in_place(...dependent) fails let drop_guard = OwnerAndCellDropGuard::new(joined_ptr); @@ -170,9 +165,7 @@ impl<Owner, Dependent> Drop for OwnerAndCellDropGuard<Owner, Dependent> { // Deallocate even when the drop_in_place(...owner) panics let _guard = DeallocGuard { - ptr: unsafe { - transmute::<*mut JoinedCell<Owner, Dependent>, *mut u8>(self.joined_ptr.as_ptr()) - }, + ptr: self.joined_ptr.as_ptr() as *mut u8, layout: Layout::new::<JoinedCell<Owner, Dependent>>(), }; |