Skip to content

Commit

Permalink
Working around ICE and rust-lang/rust#62398 no filtering on allow(dep…
Browse files Browse the repository at this point in the history
…recated...)
  • Loading branch information
peter-lyons-kehl committed Dec 10, 2024
1 parent f6d0b28 commit 8cacaed
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ unstable_transmute_unchecked = []

#default = []
# For type hinting in VS Code (and similar):
default = ["unstable_generic_const_own_type"]
default = ["unstable_generic_const_own_type", "serde"]

[package.metadata.docs.rs]
all-features = true
Expand Down
6 changes: 5 additions & 1 deletion src/amount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ impl<const TF: TraitFlags, Unit, Repr> Amount<TF, Unit, Repr>
where
Unit: DisplayerOf<Self>, //@TODO cleanup: Amount<TF, Unit, Repr>>,
{
/// `display` provides a machanism to implement a custom display
/// `display` provides a mechanism to implement a custom display
/// for phantom types.
///
/// ```ignore
Expand Down Expand Up @@ -301,16 +301,20 @@ impl<const TF: TraitFlags, Unit, Repr: Clone> Clone for Amount<TF, Unit, Repr> {
}
}

#[cfg_attr(feature = "unstable_generic_const_own_type", allow(deprecated))]
impl<Unit, Repr: Copy> Copy for Amount<{ trait_flag::TRAIT_FLAGS_IS_COPY_IS_DEFAULT }, Unit, Repr> {}
#[cfg_attr(feature = "unstable_generic_const_own_type", allow(deprecated))]
impl<Unit, Repr: Copy> Copy for Amount<{ trait_flag::TRAIT_FLAGS_IS_COPY_NO_DEFAULT }, Unit, Repr> {}

#[cfg_attr(feature = "unstable_generic_const_own_type", allow(deprecated))]
impl<Unit, Repr: Default> Default
for Amount<{ trait_flag::TRAIT_FLAGS_IS_COPY_IS_DEFAULT }, Unit, Repr>
{
fn default() -> Self {
Self(Default::default(), PhantomData)
}
}
#[cfg_attr(feature = "unstable_generic_const_own_type", allow(deprecated))]
impl<Unit, Repr: Default> Default
for Amount<{ trait_flag::TRAIT_FLAGS_NO_COPY_IS_DEFAULT }, Unit, Repr>
{
Expand Down
6 changes: 5 additions & 1 deletion src/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ where
/// use core::fmt;
///
/// enum Message {}
/// // This causes ICE:
/// // This causes ICE (with feature `unstable_generic_const_own_type`):
/// //type MessageId = phantom_newtype::Id<Message, [u8; 32]>;
/// // No ICE:
/// type MessageId = phantom_newtype::IdForFlags<{phantom_newtype::trait_flag::TRAIT_FLAGS_NO_COPY_NO_DEFAULT}, Message, [u8; 32]>;
Expand Down Expand Up @@ -262,16 +262,20 @@ impl<const TF: TraitFlags, Entity, Repr: Clone> Clone for Id<TF, Entity, Repr> {
}
}

#[cfg_attr(feature = "unstable_generic_const_own_type", allow(deprecated))]
impl<Entity, Repr: Copy> Copy for Id<{ trait_flag::TRAIT_FLAGS_IS_COPY_IS_DEFAULT }, Entity, Repr> {}
#[cfg_attr(feature = "unstable_generic_const_own_type", allow(deprecated))]
impl<Entity, Repr: Copy> Copy for Id<{ trait_flag::TRAIT_FLAGS_IS_COPY_NO_DEFAULT }, Entity, Repr> {}

#[cfg_attr(feature = "unstable_generic_const_own_type", allow(deprecated))]
impl<Unit, Repr: Default> Default
for Id<{ trait_flag::TRAIT_FLAGS_IS_COPY_IS_DEFAULT }, Unit, Repr>
{
fn default() -> Self {
Self(Default::default(), PhantomData)
}
}
#[cfg_attr(feature = "unstable_generic_const_own_type", allow(deprecated))]
impl<Unit, Repr: Default> Default
for Id<{ trait_flag::TRAIT_FLAGS_NO_COPY_IS_DEFAULT }, Unit, Repr>
{
Expand Down
6 changes: 5 additions & 1 deletion src/instant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ impl<const TF: TraitFlags, Unit, Repr> Instant<TF, Unit, Repr>
where
Unit: DisplayerOf<Instant<TF, Unit, Repr>>,
{
/// `display` provides a machanism to implement a custom display
/// `display` provides a mechanism to implement a custom display
/// for phantom types.
///
/// ```ignore
Expand Down Expand Up @@ -278,22 +278,26 @@ impl<const TF: TraitFlags, Unit, Repr: Clone> Clone for Instant<TF, Unit, Repr>
}
}

#[cfg_attr(feature = "unstable_generic_const_own_type", allow(deprecated))]
impl<Unit, Repr: Copy> Copy
for Instant<{ trait_flag::TRAIT_FLAGS_IS_COPY_IS_DEFAULT }, Unit, Repr>
{
}
#[cfg_attr(feature = "unstable_generic_const_own_type", allow(deprecated))]
impl<Unit, Repr: Copy> Copy
for Instant<{ trait_flag::TRAIT_FLAGS_IS_COPY_NO_DEFAULT }, Unit, Repr>
{
}

#[cfg_attr(feature = "unstable_generic_const_own_type", allow(deprecated))]
impl<Unit, Repr: Default> Default
for Instant<{ trait_flag::TRAIT_FLAGS_IS_COPY_IS_DEFAULT }, Unit, Repr>
{
fn default() -> Self {
Self(Default::default(), PhantomData)
}
}
#[cfg_attr(feature = "unstable_generic_const_own_type", allow(deprecated))]
impl<Unit, Repr: Default> Default
for Instant<{ trait_flag::TRAIT_FLAGS_NO_COPY_IS_DEFAULT }, Unit, Repr>
{
Expand Down
12 changes: 12 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,42 +50,54 @@ pub use displayer::{DisplayProxy, DisplayerOf};
pub use id::Id as IdForFlags;

// Short names. Also in mod prelude:
#[cfg_attr(feature = "unstable_generic_const_own_type", allow(deprecated))]
pub type Id<Unit, Repr> = id::Id<{ trait_flag::TRAIT_FLAGS_IS_COPY_IS_DEFAULT }, Unit, Repr>;
#[cfg_attr(feature = "unstable_generic_const_own_type", allow(deprecated))]
pub type IdNoCopy<Unit, Repr> = id::Id<{ trait_flag::TRAIT_FLAGS_NO_COPY_IS_DEFAULT }, Unit, Repr>;
#[cfg_attr(feature = "unstable_generic_const_own_type", allow(deprecated))]
pub type IdNoDefault<Unit, Repr> =
id::Id<{ trait_flag::TRAIT_FLAGS_IS_COPY_NO_DEFAULT }, Unit, Repr>;
#[cfg_attr(feature = "unstable_generic_const_own_type", allow(deprecated))]
pub type IdNoCopyNoDefault<Unit, Repr> =
id::Id<{ trait_flag::TRAIT_FLAGS_NO_COPY_NO_DEFAULT }, Unit, Repr>;

// Long names. Also in mod prelude_full:
pub type IdIsCopyIsDefault<Unit, Repr> = Id<Unit, Repr>;
pub type IdIsCopyNoDefault<Unit, Repr> = IdNoDefault<Unit, Repr>;
pub type IdNoCopyIsDefault<Unit, Repr> = IdNoCopy<Unit, Repr>;

#[cfg_attr(feature = "unstable_generic_const_own_type", allow(deprecated))]
pub type Amount<Unit, Repr> =
amount::Amount<{ trait_flag::TRAIT_FLAGS_IS_COPY_IS_DEFAULT }, Unit, Repr>;
#[cfg_attr(feature = "unstable_generic_const_own_type", allow(deprecated))]
pub type AmountNoCopy<Unit, Repr> =
amount::Amount<{ trait_flag::TRAIT_FLAGS_NO_COPY_IS_DEFAULT }, Unit, Repr>;
#[cfg_attr(feature = "unstable_generic_const_own_type", allow(deprecated))]
pub type AmountNoDefault<Unit, Repr> =
amount::Amount<{ trait_flag::TRAIT_FLAGS_IS_COPY_NO_DEFAULT }, Unit, Repr>;
#[cfg_attr(feature = "unstable_generic_const_own_type", allow(deprecated))]
pub type AmountNoCopyNoDefault<Unit, Repr> =
amount::Amount<{ trait_flag::TRAIT_FLAGS_NO_COPY_NO_DEFAULT }, Unit, Repr>;

// Long names. Also in mod prelude_full:
pub type AmountIsCopyIsDefault<Unit, Repr> = Amount<Unit, Repr>;
pub type AmountIsCopyNoDefault<Unit, Repr> = AmountNoDefault<Unit, Repr>;
pub type AmountNoCopyIsDefault<Unit, Repr> = AmountNoCopy<Unit, Repr>;

// Short names. Also in mod prelude:
#[cfg_attr(feature = "unstable_generic_const_own_type", allow(deprecated))]
pub type Instant<Unit, Repr> =
instant::Instant<{ trait_flag::TRAIT_FLAGS_IS_COPY_IS_DEFAULT }, Unit, Repr>;
#[cfg_attr(feature = "unstable_generic_const_own_type", allow(deprecated))]
pub type InstantNoCopy<Unit, Repr> =
instant::Instant<{ trait_flag::TRAIT_FLAGS_NO_COPY_IS_DEFAULT }, Unit, Repr>;
#[cfg_attr(feature = "unstable_generic_const_own_type", allow(deprecated))]
pub type InstantNoDefault<Unit, Repr> =
instant::Instant<{ trait_flag::TRAIT_FLAGS_IS_COPY_NO_DEFAULT }, Unit, Repr>;
#[cfg_attr(feature = "unstable_generic_const_own_type", allow(deprecated))]
pub type InstantNoCopyNoDefault<Unit, Repr> =
instant::Instant<{ trait_flag::TRAIT_FLAGS_NO_COPY_NO_DEFAULT }, Unit, Repr>;

// Long names. Also in mod prelude_full:
pub type InstantIsCopyIsDefault<Unit, Repr> = Instant<Unit, Repr>;
pub type InstantIsCopyNoDefault<Unit, Repr> = InstantNoDefault<Unit, Repr>;
Expand Down
6 changes: 4 additions & 2 deletions src/to.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub trait AsFrom<T> {}
pub trait AsFromMut<T> {}

#[derive(Copy, Clone)]
pub struct Amm<T:Copy, Repr: Copy>(PhantomData<core::sync::atomic::AtomicPtr<T>>, Repr);
pub struct Amm<T: Copy, Repr: Copy>(PhantomData<core::sync::atomic::AtomicPtr<T>>, Repr);

#[cfg(feature = "unstable_transmute_unchecked")]
pub const unsafe fn transmute_unchecked<T, U>(x: T) -> U {
Expand Down Expand Up @@ -147,7 +147,9 @@ pub fn in_to_out_f64<PROPERTY: Copy>(inp: Amm<(In, PROPERTY), f64>) -> Amm<(Out,
/// the above `impl` automatically enables this:
inp.to()
}
pub fn in_to_out<PROPERTY: Copy, UNIT: Copy>(inp: Amm<(In, PROPERTY), UNIT>) -> Amm<(Out, PROPERTY), UNIT> {
pub fn in_to_out<PROPERTY: Copy, UNIT: Copy>(
inp: Amm<(In, PROPERTY), UNIT>,
) -> Amm<(Out, PROPERTY), UNIT> {
/// the above `impl` automatically enables this:
inp.to()
}
26 changes: 22 additions & 4 deletions src/trait_flag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ pub enum TraitFlagsValues {
pub type TraitFlags = u8;
#[cfg(feature = "unstable_generic_const_own_type")]
/// `nightly` warning: Direct use of [IdForFlags] (and hence direct use of TraitFlags) is unstable!
#[deprecated(note = "`nightly` warning: Direct use of IdForFlags (and hence direct use of TraitFlags) is unstable!")]
#[deprecated(
note = "`nightly` warning: Direct use of IdForFlags (and hence direct use of TraitFlags) is unstable!"
)]
pub type TraitFlags = TraitFlagsValues;

#[cfg_attr(feature = "unstable_generic_const_own_type", allow(deprecated))]
Expand All @@ -46,16 +48,31 @@ const fn trait_flags_new(tfv: TraitFlagsValues) -> TraitFlags {
const TRAIT_FLAG_BIT_COPY: u8 = 0b1;
const TRAIT_FLAG_BIT_DEFAULT: u8 = 0b10;

#[cfg_attr(
feature = "unstable_generic_const_own_type",
deprecated(note = "`nightly` warning: Direct use is unstable!")
)]
#[cfg_attr(feature = "unstable_generic_const_own_type", allow(deprecated))]
pub const TRAIT_FLAGS_IS_COPY_IS_DEFAULT: TraitFlags =
trait_flags_new(TraitFlagsValues::TRAIT_FLAGS_IS_COPY_IS_DEFAULT);
#[cfg_attr(
feature = "unstable_generic_const_own_type",
deprecated(note = "`nightly` warning: Direct use is unstable!")
)]
#[cfg_attr(feature = "unstable_generic_const_own_type", allow(deprecated))]
pub const TRAIT_FLAGS_IS_COPY_NO_DEFAULT: TraitFlags =
trait_flags_new(TraitFlagsValues::TRAIT_FLAGS_IS_COPY_NO_DEFAULT);
#[cfg_attr(
feature = "unstable_generic_const_own_type",
deprecated(note = "`nightly` warning: Direct use is unstable!")
)]
#[cfg_attr(feature = "unstable_generic_const_own_type", allow(deprecated))]
pub const TRAIT_FLAGS_NO_COPY_IS_DEFAULT: TraitFlags =
trait_flags_new(TraitFlagsValues::TRAIT_FLAGS_NO_COPY_IS_DEFAULT);
#[cfg_attr(feature = "unstable_generic_const_own_type", deprecated(note = "`nightly` warning: Direct use is unstable!"))]
#[cfg_attr(
feature = "unstable_generic_const_own_type",
deprecated(note = "`nightly` warning: Direct use is unstable!")
)]
#[cfg_attr(feature = "unstable_generic_const_own_type", allow(deprecated))]
pub const TRAIT_FLAGS_NO_COPY_NO_DEFAULT: TraitFlags =
trait_flags_new(TraitFlagsValues::TRAIT_FLAGS_NO_COPY_NO_DEFAULT);
Expand All @@ -82,16 +99,17 @@ mod test_flags {
use super::*;

#[test]
#[allow(deprecated)]
fn all() {
assert_eq!(is_copy(TRAIT_FLAGS_IS_COPY_IS_DEFAULT), true);
assert_eq!(is_copy(TRAIT_FLAGS_IS_COPY_NO_DEFAULT), true);
assert_eq!(is_copy(TRAIT_FLAGS_NO_COPY_IS_DEFAULT), false);
assert_eq!(is_copy(#[allow(deprecated)] TRAIT_FLAGS_NO_COPY_NO_DEFAULT), false);
assert_eq!(is_copy(TRAIT_FLAGS_NO_COPY_NO_DEFAULT), false);

assert_eq!(is_default(TRAIT_FLAGS_IS_COPY_IS_DEFAULT), true);
assert_eq!(is_default(TRAIT_FLAGS_NO_COPY_IS_DEFAULT), true);
assert_eq!(is_default(TRAIT_FLAGS_IS_COPY_NO_DEFAULT), false);
assert_eq!(is_default(#[allow(deprecated)] TRAIT_FLAGS_NO_COPY_NO_DEFAULT), false);
assert_eq!(is_default(TRAIT_FLAGS_NO_COPY_NO_DEFAULT), false);
}
}

Expand Down
58 changes: 58 additions & 0 deletions tests-nightly/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests-nightly/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ version = "0.1.0"
edition = "2024"

[dependencies]
phantom_newtype = { path = "..", features = ["unstable_generic_const_own_type"] }
phantom_newtype = { path = "..", features = ["unstable_generic_const_own_type", "unstable_transmute_unchecked"] }

0 comments on commit 8cacaed

Please sign in to comment.