From bcffbf938b21c94974ca42cd753c8b1f0e6ac22e Mon Sep 17 00:00:00 2001 From: bluss Date: Tue, 23 Mar 2021 19:41:11 +0100 Subject: [PATCH] MAINT: Delete historical nodrop, nodrop-union directories These crates are deprecated (use ManuallyDrop and/or MaybeUninit instead). --- README.md | 1 - nodrop-union/Cargo.toml | 22 ----- nodrop-union/LICENSE-APACHE | 1 - nodrop-union/LICENSE-MIT | 1 - nodrop-union/README.rst | 25 ----- nodrop-union/src/lib.rs | 154 ----------------------------- nodrop/Cargo.toml | 44 --------- nodrop/LICENSE-APACHE | 1 - nodrop/LICENSE-MIT | 1 - nodrop/README.rst | 71 -------------- nodrop/src/lib.rs | 189 ------------------------------------ 11 files changed, 510 deletions(-) delete mode 100644 nodrop-union/Cargo.toml delete mode 120000 nodrop-union/LICENSE-APACHE delete mode 120000 nodrop-union/LICENSE-MIT delete mode 100644 nodrop-union/README.rst delete mode 100644 nodrop-union/src/lib.rs delete mode 100644 nodrop/Cargo.toml delete mode 120000 nodrop/LICENSE-APACHE delete mode 120000 nodrop/LICENSE-MIT delete mode 100644 nodrop/README.rst delete mode 100644 nodrop/src/lib.rs diff --git a/README.md b/README.md index 8a9625f..85ccbd1 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,6 @@ arrayvec ======== [![Crates.io: arrayvec](https://img.shields.io/crates/v/arrayvec.svg)](https://crates.io/crates/arrayvec) -[![Crates.io: nodrop](https://img.shields.io/crates/v/nodrop.svg)](https://crates.io/crates/nodrop) [![Documentation](https://docs.rs/arrayvec/badge.svg)](https://docs.rs/arrayvec) [![Build Status](https://github.com/bluss/arrayvec/workflows/Continuous%20integration/badge.svg?branch=master)](https://github.com/bluss/arrayvec/actions) diff --git a/nodrop-union/Cargo.toml b/nodrop-union/Cargo.toml deleted file mode 100644 index a8ca494..0000000 --- a/nodrop-union/Cargo.toml +++ /dev/null @@ -1,22 +0,0 @@ -[package] -name = "nodrop-union" -version = "0.1.11" -authors = ["bluss"] - -license = "MIT/Apache-2.0" - -description = """ -A wrapper type to inhibit drop (destructor). Implementation crate for nodrop, the untagged unions implementation (which is unstable / requires nightly) as of this writing. - -***Deprecated: Use ManuallyDrop or MaybeUninit instead!*** -""" -repository = "https://github.com/bluss/arrayvec" - -keywords = [] - -[package.metadata.release] -no-dev-version = true -tag-name = "nodrop-union-{{version}}" - -[badges.maintenance] -status = "deprecated" diff --git a/nodrop-union/LICENSE-APACHE b/nodrop-union/LICENSE-APACHE deleted file mode 120000 index 965b606..0000000 --- a/nodrop-union/LICENSE-APACHE +++ /dev/null @@ -1 +0,0 @@ -../LICENSE-APACHE \ No newline at end of file diff --git a/nodrop-union/LICENSE-MIT b/nodrop-union/LICENSE-MIT deleted file mode 120000 index 76219eb..0000000 --- a/nodrop-union/LICENSE-MIT +++ /dev/null @@ -1 +0,0 @@ -../LICENSE-MIT \ No newline at end of file diff --git a/nodrop-union/README.rst b/nodrop-union/README.rst deleted file mode 100644 index b5e222a..0000000 --- a/nodrop-union/README.rst +++ /dev/null @@ -1,25 +0,0 @@ - -Recent Changes (nodrop-union) ------------------------ - -- 0.1.11 - - - Mark nodrop deprecated - - With the release of arrayvec 0.5, nodrop is unused. - - With the release of Rust 1.36 and MaybeUninit, nodrop-union has no - purpose at all (it was only for nightly releases). - -- 0.1.10 - - - Update to include license files in the crate by @ignatenkobrain - -- 0.1.9 - - - Add ``Copy, Clone`` implementations - -- 0.1.8 - - - Initial release - diff --git a/nodrop-union/src/lib.rs b/nodrop-union/src/lib.rs deleted file mode 100644 index 9c54734..0000000 --- a/nodrop-union/src/lib.rs +++ /dev/null @@ -1,154 +0,0 @@ -//! A wrapper type to inhibit drop (destructor). -//! -//! ***Deprecated: Use ManuallyDrop or MaybeUninit instead!*** -//! -//! **nodrop-union** is the untagged unions (requires Rust nightly channel and -//! unstable as of this writing) implementation for the **nodrop** crate. -//! -//! It is intended you use this through the **nodrop** crate with the `use_union` -//! crate feature enabled. -//! -//! This is the future implementation of nodrop, once it is stable. -//! -//! This implementation is a lot better: -//! -//! - Does not have a destructor at all -//! - Can be Copy if T is Copy -//! - No space overhead / no runtime flag -//! -//! This means that this implementation has extensions that the -//! stable nodrop does not yet have, which is something to be aware of if -//! you are switching. -//! - -#![feature(untagged_unions)] - -#![cfg_attr(not(test), no_std)] -#[cfg(not(test))] -extern crate core as std; - -use std::ops::{Deref, DerefMut}; - -#[allow(unions_with_drop_fields)] -#[derive(Copy)] -union UnionFlag { - value: T, -} - -impl Clone for UnionFlag { - fn clone(&self) -> Self { - unsafe { - UnionFlag { value: self.value.clone() } - } - } -} - -/// A type holding **T** that will not call its destructor on drop -/// -/// The untagged unions implementation of `NoDrop` is Copy where T: Copy, -/// which was not possible in the stable implementation. -#[derive(Copy, Clone)] -pub struct NoDrop(UnionFlag); - -impl NoDrop { - /// Create a new **NoDrop**. - #[inline] - pub fn new(value: T) -> Self { - NoDrop(UnionFlag { value: value }) - } - - /// Extract the inner value. - /// - /// Once extracted, the value can of course drop again. - #[inline] - pub fn into_inner(self) -> T { - unsafe { - self.0.value - } - } -} - -impl Deref for NoDrop { - type Target = T; - - // Use type invariant, always initialized - #[inline] - fn deref(&self) -> &T { - unsafe { - &self.0.value - } - } -} - -impl DerefMut for NoDrop { - // Use type invariant, always initialized - #[inline] - fn deref_mut(&mut self) -> &mut T { - unsafe { - &mut self.0.value - } - } -} - -#[cfg(test)] -mod tests { - use super::NoDrop; - use std::mem; - - #[test] - fn test_drop() { - use std::cell::Cell; - - let flag = &Cell::new(0); - - struct Bump<'a>(&'a Cell); - - impl<'a> Drop for Bump<'a> { - fn drop(&mut self) { - let n = self.0.get(); - self.0.set(n + 1); - } - } - - { - let _ = NoDrop::new([Bump(flag), Bump(flag)]); - } - assert_eq!(flag.get(), 0); - - // test something with the nullable pointer optimization - flag.set(0); - - { - let mut array = NoDrop::new(Vec::new()); - array.push(vec![Bump(flag)]); - array.push(vec![Bump(flag), Bump(flag)]); - array.push(vec![]); - array.push(vec![Bump(flag)]); - drop(array.pop()); - assert_eq!(flag.get(), 1); - drop(array.pop()); - assert_eq!(flag.get(), 1); - drop(array.pop()); - assert_eq!(flag.get(), 3); - } - - // last one didn't drop. - assert_eq!(flag.get(), 3); - - flag.set(0); - { - let array = NoDrop::new(Bump(flag)); - array.into_inner(); - assert_eq!(flag.get(), 1); - } - assert_eq!(flag.get(), 1); - } - - #[test] - fn test_size_of() { - assert!(mem::size_of::>() == mem::size_of::<&i32>()); - assert!(mem::size_of::>>() == mem::size_of::>()); - // No non-nullable pointer optimization! - assert!(mem::size_of::>>() > mem::size_of::>()); - } -} diff --git a/nodrop/Cargo.toml b/nodrop/Cargo.toml deleted file mode 100644 index 0db7b96..0000000 --- a/nodrop/Cargo.toml +++ /dev/null @@ -1,44 +0,0 @@ -[package] -name = "nodrop" -version = "0.1.14" -authors = ["bluss"] - -license = "MIT/Apache-2.0" - -description = """ -A wrapper type to inhibit drop (destructor). - -***Deprecated: Use ManuallyDrop or MaybeUninit instead!*** -""" -documentation = "https://docs.rs/nodrop/" -repository = "https://github.com/bluss/arrayvec" - -keywords = [] -categories = ["rust-patterns"] - -[features] -default = ["std"] - -# Default, requires Rust 1.6+ to disable -# Use libstd -std = [] - -# Optional, Rust 1.21.0 -# Use `needs_drop` to skip overwriting if not necessary -use_needs_drop = [] - -# Optional, nightly channel -use_union = ["nodrop-union"] - -[dependencies.nodrop-union] -path = "../nodrop-union" -version = "0.1.8" -optional = true - -[package.metadata.release] -no-dev-version = true -tag-name = "nodrop-{{version}}" - - -[badges.maintenance] -status = "deprecated" diff --git a/nodrop/LICENSE-APACHE b/nodrop/LICENSE-APACHE deleted file mode 120000 index 965b606..0000000 --- a/nodrop/LICENSE-APACHE +++ /dev/null @@ -1 +0,0 @@ -../LICENSE-APACHE \ No newline at end of file diff --git a/nodrop/LICENSE-MIT b/nodrop/LICENSE-MIT deleted file mode 120000 index 76219eb..0000000 --- a/nodrop/LICENSE-MIT +++ /dev/null @@ -1 +0,0 @@ -../LICENSE-MIT \ No newline at end of file diff --git a/nodrop/README.rst b/nodrop/README.rst deleted file mode 100644 index 3886ba6..0000000 --- a/nodrop/README.rst +++ /dev/null @@ -1,71 +0,0 @@ - -nodrop -====== - -Recent Changes (nodrop) ------------------------ - -- 0.1.14 - - - Mark nodrop deprecated - - With the release of arrayvec 0.5, nodrop is unused. - - With the release of Rust 1.36 and MaybeUninit, nodrop has no - purpose (but for older Rust releases). - -- 0.1.13 - - - Update to include license files in the crate by @ignatenkobrain - -- 0.1.12 - - - Remove dependency on crate odds. - -- 0.1.11 - - - Remove erronous assertion in test (#77) - -- 0.1.10 - - - Update for stable ``needs_drop`` (Rust 1.21, was nightly only) - -- 0.1.9 - - - Fix issue in recent nightly where ``repr(u8)`` did not work. Use - a better way to get rid of the enum layout optimization. - -- 0.1.8 - - - Add crate feature ``use_union`` that uses untagged unions to implement NoDrop. - Finally we have an implementation without hacks, without a runtime flag, - and without an actual ``Drop`` impl (which was needed to suppress drop). - The crate feature requires nightly and is unstable. - -- 0.1.7 - - - Remove crate feature ``no_drop_flag``, because it doesn't compile on nightly - anymore. Drop flags are gone anyway! - -- 0.1.6 - - - Add feature std, which you can opt out of to use ``no_std``. - -- 0.1.5 - - - Added crate feature ``use_needs_drop`` which is a nightly-only - optimization, which skips overwriting if the inner value does not need - drop. - -License -======= - -Dual-licensed to be compatible with the Rust project. - -Licensed under the Apache License, Version 2.0 -http://www.apache.org/licenses/LICENSE-2.0 or the MIT license -http://opensource.org/licenses/MIT, at your -option. This file may not be copied, modified, or distributed -except according to those terms. - - diff --git a/nodrop/src/lib.rs b/nodrop/src/lib.rs deleted file mode 100644 index a1a1547..0000000 --- a/nodrop/src/lib.rs +++ /dev/null @@ -1,189 +0,0 @@ -//! A wrapper type to inhibit drop (destructor). -//! -//! ***Deprecated: Use ManuallyDrop or MaybeUninit instead!*** -//! -//! The **nodrop** crate has the following cargo feature flags: -//! -//! - `std` -//! - Optional, enabled by default -//! - Use libstd -//! - `use_needs_drop` -//! - Optional -//! - Requires Rust 1.21 -//! - Use `needs_drop` to skip overwriting if not necessary -//! - `use_union` -//! - Optional -//! - Requires nightly channel -//! - Using untagged union, finally we have an implementation of `NoDrop` without hacks, -//! for example the fact that `NoDrop` never has a destructor anymore. -//! - -#![cfg_attr(not(any(test, feature="std")), no_std)] -#[cfg(not(any(test, feature="std")))] -extern crate core as std; - -#[cfg(feature = "use_union")] -extern crate nodrop_union as imp; - -pub use imp::NoDrop; - - -#[cfg(not(feature = "use_union"))] -mod imp { - use std::ptr; - use std::mem; - use std::ops::{Deref, DerefMut}; - - /// repr(u8) - Make sure the non-nullable pointer optimization does not occur! - #[repr(u8)] - enum Flag { - Alive(T), - // Dummy u8 field below, again to beat the enum layout opt - Dropped(u8), - } - - - /// A type holding **T** that will not call its destructor on drop - pub struct NoDrop(Flag); - - impl NoDrop { - /// Create a new **NoDrop**. - #[inline] - pub fn new(value: T) -> NoDrop { - NoDrop(Flag::Alive(value)) - } - - /// Extract the inner value. - /// - /// Once extracted, the value can of course drop again. - #[inline] - pub fn into_inner(mut self) -> T { - let inner = unsafe { - ptr::read(&mut *self) - }; - // skip Drop, so we don't even have to overwrite - mem::forget(self); - inner - } - } - - #[cfg(not(feature = "use_needs_drop"))] - #[inline] - fn needs_drop() -> bool { - true - } - - #[cfg(feature = "use_needs_drop")] - #[inline] - fn needs_drop() -> bool { - unsafe { - ::std::mem::needs_drop::() - } - } - - impl Drop for NoDrop { - fn drop(&mut self) { - if needs_drop::() { - // inhibit drop - unsafe { - ptr::write(&mut self.0, Flag::Dropped(0)); - } - } - } - } - - impl Deref for NoDrop { - type Target = T; - - // Use type invariant, always Flag::Alive. - #[inline] - fn deref(&self) -> &T { - match self.0 { - Flag::Alive(ref inner) => inner, - _ => unsafe { debug_assert_unreachable() } - } - } - } - - impl DerefMut for NoDrop { - // Use type invariant, always Flag::Alive. - #[inline] - fn deref_mut(&mut self) -> &mut T { - match self.0 { - Flag::Alive(ref mut inner) => inner, - _ => unsafe { debug_assert_unreachable() } - } - } - } - - #[cfg(test)] - #[test] - fn test_no_nonnullable_opt() { - // Make sure `Flag` does not apply the non-nullable pointer optimization - // as Option would do. - assert!(mem::size_of::>() > mem::size_of::<&i32>()); - assert!(mem::size_of::>>() > mem::size_of::>()); - } - - // copying this code saves us microcrate deps - #[inline] - unsafe fn debug_assert_unreachable() -> ! { - debug_assert!(false, "Reached unreachable section: this is a bug!"); - enum Void { } - match *(1 as *const Void) { } - } -} - -#[cfg(test)] -mod tests { - use super::NoDrop; - - #[test] - fn test_drop() { - use std::cell::Cell; - - let flag = &Cell::new(0); - - struct Bump<'a>(&'a Cell); - - impl<'a> Drop for Bump<'a> { - fn drop(&mut self) { - let n = self.0.get(); - self.0.set(n + 1); - } - } - - { - let _ = NoDrop::new([Bump(flag), Bump(flag)]); - } - assert_eq!(flag.get(), 0); - - // test something with the nullable pointer optimization - flag.set(0); - - { - let mut array = NoDrop::new(Vec::new()); - array.push(vec![Bump(flag)]); - array.push(vec![Bump(flag), Bump(flag)]); - array.push(vec![]); - array.push(vec![Bump(flag)]); - drop(array.pop()); - assert_eq!(flag.get(), 1); - drop(array.pop()); - assert_eq!(flag.get(), 1); - drop(array.pop()); - assert_eq!(flag.get(), 3); - } - - // last one didn't drop. - assert_eq!(flag.get(), 3); - - flag.set(0); - { - let array = NoDrop::new(Bump(flag)); - array.into_inner(); - assert_eq!(flag.get(), 1); - } - assert_eq!(flag.get(), 1); - } -}