Skip to content

Commit 8cacaed

Browse files
Working around ICE and rust-lang/rust#62398 no filtering on allow(deprecated...)
1 parent f6d0b28 commit 8cacaed

File tree

9 files changed

+113
-11
lines changed

9 files changed

+113
-11
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ unstable_transmute_unchecked = []
3232

3333
#default = []
3434
# For type hinting in VS Code (and similar):
35-
default = ["unstable_generic_const_own_type"]
35+
default = ["unstable_generic_const_own_type", "serde"]
3636

3737
[package.metadata.docs.rs]
3838
all-features = true

src/amount.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ impl<const TF: TraitFlags, Unit, Repr> Amount<TF, Unit, Repr>
252252
where
253253
Unit: DisplayerOf<Self>, //@TODO cleanup: Amount<TF, Unit, Repr>>,
254254
{
255-
/// `display` provides a machanism to implement a custom display
255+
/// `display` provides a mechanism to implement a custom display
256256
/// for phantom types.
257257
///
258258
/// ```ignore
@@ -301,16 +301,20 @@ impl<const TF: TraitFlags, Unit, Repr: Clone> Clone for Amount<TF, Unit, Repr> {
301301
}
302302
}
303303

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

309+
#[cfg_attr(feature = "unstable_generic_const_own_type", allow(deprecated))]
307310
impl<Unit, Repr: Default> Default
308311
for Amount<{ trait_flag::TRAIT_FLAGS_IS_COPY_IS_DEFAULT }, Unit, Repr>
309312
{
310313
fn default() -> Self {
311314
Self(Default::default(), PhantomData)
312315
}
313316
}
317+
#[cfg_attr(feature = "unstable_generic_const_own_type", allow(deprecated))]
314318
impl<Unit, Repr: Default> Default
315319
for Amount<{ trait_flag::TRAIT_FLAGS_NO_COPY_IS_DEFAULT }, Unit, Repr>
316320
{

src/id.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ where
232232
/// use core::fmt;
233233
///
234234
/// enum Message {}
235-
/// // This causes ICE:
235+
/// // This causes ICE (with feature `unstable_generic_const_own_type`):
236236
/// //type MessageId = phantom_newtype::Id<Message, [u8; 32]>;
237237
/// // No ICE:
238238
/// type MessageId = phantom_newtype::IdForFlags<{phantom_newtype::trait_flag::TRAIT_FLAGS_NO_COPY_NO_DEFAULT}, Message, [u8; 32]>;
@@ -262,16 +262,20 @@ impl<const TF: TraitFlags, Entity, Repr: Clone> Clone for Id<TF, Entity, Repr> {
262262
}
263263
}
264264

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

270+
#[cfg_attr(feature = "unstable_generic_const_own_type", allow(deprecated))]
268271
impl<Unit, Repr: Default> Default
269272
for Id<{ trait_flag::TRAIT_FLAGS_IS_COPY_IS_DEFAULT }, Unit, Repr>
270273
{
271274
fn default() -> Self {
272275
Self(Default::default(), PhantomData)
273276
}
274277
}
278+
#[cfg_attr(feature = "unstable_generic_const_own_type", allow(deprecated))]
275279
impl<Unit, Repr: Default> Default
276280
for Id<{ trait_flag::TRAIT_FLAGS_NO_COPY_IS_DEFAULT }, Unit, Repr>
277281
{

src/instant.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ impl<const TF: TraitFlags, Unit, Repr> Instant<TF, Unit, Repr>
241241
where
242242
Unit: DisplayerOf<Instant<TF, Unit, Repr>>,
243243
{
244-
/// `display` provides a machanism to implement a custom display
244+
/// `display` provides a mechanism to implement a custom display
245245
/// for phantom types.
246246
///
247247
/// ```ignore
@@ -278,22 +278,26 @@ impl<const TF: TraitFlags, Unit, Repr: Clone> Clone for Instant<TF, Unit, Repr>
278278
}
279279
}
280280

281+
#[cfg_attr(feature = "unstable_generic_const_own_type", allow(deprecated))]
281282
impl<Unit, Repr: Copy> Copy
282283
for Instant<{ trait_flag::TRAIT_FLAGS_IS_COPY_IS_DEFAULT }, Unit, Repr>
283284
{
284285
}
286+
#[cfg_attr(feature = "unstable_generic_const_own_type", allow(deprecated))]
285287
impl<Unit, Repr: Copy> Copy
286288
for Instant<{ trait_flag::TRAIT_FLAGS_IS_COPY_NO_DEFAULT }, Unit, Repr>
287289
{
288290
}
289291

292+
#[cfg_attr(feature = "unstable_generic_const_own_type", allow(deprecated))]
290293
impl<Unit, Repr: Default> Default
291294
for Instant<{ trait_flag::TRAIT_FLAGS_IS_COPY_IS_DEFAULT }, Unit, Repr>
292295
{
293296
fn default() -> Self {
294297
Self(Default::default(), PhantomData)
295298
}
296299
}
300+
#[cfg_attr(feature = "unstable_generic_const_own_type", allow(deprecated))]
297301
impl<Unit, Repr: Default> Default
298302
for Instant<{ trait_flag::TRAIT_FLAGS_NO_COPY_IS_DEFAULT }, Unit, Repr>
299303
{

src/lib.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,42 +50,54 @@ pub use displayer::{DisplayProxy, DisplayerOf};
5050
pub use id::Id as IdForFlags;
5151

5252
// Short names. Also in mod prelude:
53+
#[cfg_attr(feature = "unstable_generic_const_own_type", allow(deprecated))]
5354
pub type Id<Unit, Repr> = id::Id<{ trait_flag::TRAIT_FLAGS_IS_COPY_IS_DEFAULT }, Unit, Repr>;
55+
#[cfg_attr(feature = "unstable_generic_const_own_type", allow(deprecated))]
5456
pub type IdNoCopy<Unit, Repr> = id::Id<{ trait_flag::TRAIT_FLAGS_NO_COPY_IS_DEFAULT }, Unit, Repr>;
57+
#[cfg_attr(feature = "unstable_generic_const_own_type", allow(deprecated))]
5558
pub type IdNoDefault<Unit, Repr> =
5659
id::Id<{ trait_flag::TRAIT_FLAGS_IS_COPY_NO_DEFAULT }, Unit, Repr>;
5760
#[cfg_attr(feature = "unstable_generic_const_own_type", allow(deprecated))]
5861
pub type IdNoCopyNoDefault<Unit, Repr> =
5962
id::Id<{ trait_flag::TRAIT_FLAGS_NO_COPY_NO_DEFAULT }, Unit, Repr>;
63+
6064
// Long names. Also in mod prelude_full:
6165
pub type IdIsCopyIsDefault<Unit, Repr> = Id<Unit, Repr>;
6266
pub type IdIsCopyNoDefault<Unit, Repr> = IdNoDefault<Unit, Repr>;
6367
pub type IdNoCopyIsDefault<Unit, Repr> = IdNoCopy<Unit, Repr>;
6468

69+
#[cfg_attr(feature = "unstable_generic_const_own_type", allow(deprecated))]
6570
pub type Amount<Unit, Repr> =
6671
amount::Amount<{ trait_flag::TRAIT_FLAGS_IS_COPY_IS_DEFAULT }, Unit, Repr>;
72+
#[cfg_attr(feature = "unstable_generic_const_own_type", allow(deprecated))]
6773
pub type AmountNoCopy<Unit, Repr> =
6874
amount::Amount<{ trait_flag::TRAIT_FLAGS_NO_COPY_IS_DEFAULT }, Unit, Repr>;
75+
#[cfg_attr(feature = "unstable_generic_const_own_type", allow(deprecated))]
6976
pub type AmountNoDefault<Unit, Repr> =
7077
amount::Amount<{ trait_flag::TRAIT_FLAGS_IS_COPY_NO_DEFAULT }, Unit, Repr>;
7178
#[cfg_attr(feature = "unstable_generic_const_own_type", allow(deprecated))]
7279
pub type AmountNoCopyNoDefault<Unit, Repr> =
7380
amount::Amount<{ trait_flag::TRAIT_FLAGS_NO_COPY_NO_DEFAULT }, Unit, Repr>;
81+
7482
// Long names. Also in mod prelude_full:
7583
pub type AmountIsCopyIsDefault<Unit, Repr> = Amount<Unit, Repr>;
7684
pub type AmountIsCopyNoDefault<Unit, Repr> = AmountNoDefault<Unit, Repr>;
7785
pub type AmountNoCopyIsDefault<Unit, Repr> = AmountNoCopy<Unit, Repr>;
7886

7987
// Short names. Also in mod prelude:
88+
#[cfg_attr(feature = "unstable_generic_const_own_type", allow(deprecated))]
8089
pub type Instant<Unit, Repr> =
8190
instant::Instant<{ trait_flag::TRAIT_FLAGS_IS_COPY_IS_DEFAULT }, Unit, Repr>;
91+
#[cfg_attr(feature = "unstable_generic_const_own_type", allow(deprecated))]
8292
pub type InstantNoCopy<Unit, Repr> =
8393
instant::Instant<{ trait_flag::TRAIT_FLAGS_NO_COPY_IS_DEFAULT }, Unit, Repr>;
94+
#[cfg_attr(feature = "unstable_generic_const_own_type", allow(deprecated))]
8495
pub type InstantNoDefault<Unit, Repr> =
8596
instant::Instant<{ trait_flag::TRAIT_FLAGS_IS_COPY_NO_DEFAULT }, Unit, Repr>;
8697
#[cfg_attr(feature = "unstable_generic_const_own_type", allow(deprecated))]
8798
pub type InstantNoCopyNoDefault<Unit, Repr> =
8899
instant::Instant<{ trait_flag::TRAIT_FLAGS_NO_COPY_NO_DEFAULT }, Unit, Repr>;
100+
89101
// Long names. Also in mod prelude_full:
90102
pub type InstantIsCopyIsDefault<Unit, Repr> = Instant<Unit, Repr>;
91103
pub type InstantIsCopyNoDefault<Unit, Repr> = InstantNoDefault<Unit, Repr>;

src/to.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub trait AsFrom<T> {}
3636
pub trait AsFromMut<T> {}
3737

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

4141
#[cfg(feature = "unstable_transmute_unchecked")]
4242
pub const unsafe fn transmute_unchecked<T, U>(x: T) -> U {
@@ -147,7 +147,9 @@ pub fn in_to_out_f64<PROPERTY: Copy>(inp: Amm<(In, PROPERTY), f64>) -> Amm<(Out,
147147
/// the above `impl` automatically enables this:
148148
inp.to()
149149
}
150-
pub fn in_to_out<PROPERTY: Copy, UNIT: Copy>(inp: Amm<(In, PROPERTY), UNIT>) -> Amm<(Out, PROPERTY), UNIT> {
150+
pub fn in_to_out<PROPERTY: Copy, UNIT: Copy>(
151+
inp: Amm<(In, PROPERTY), UNIT>,
152+
) -> Amm<(Out, PROPERTY), UNIT> {
151153
/// the above `impl` automatically enables this:
152154
inp.to()
153155
}

src/trait_flag.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ pub enum TraitFlagsValues {
2727
pub type TraitFlags = u8;
2828
#[cfg(feature = "unstable_generic_const_own_type")]
2929
/// `nightly` warning: Direct use of [IdForFlags] (and hence direct use of TraitFlags) is unstable!
30-
#[deprecated(note = "`nightly` warning: Direct use of IdForFlags (and hence direct use of TraitFlags) is unstable!")]
30+
#[deprecated(
31+
note = "`nightly` warning: Direct use of IdForFlags (and hence direct use of TraitFlags) is unstable!"
32+
)]
3133
pub type TraitFlags = TraitFlagsValues;
3234

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

51+
#[cfg_attr(
52+
feature = "unstable_generic_const_own_type",
53+
deprecated(note = "`nightly` warning: Direct use is unstable!")
54+
)]
4955
#[cfg_attr(feature = "unstable_generic_const_own_type", allow(deprecated))]
5056
pub const TRAIT_FLAGS_IS_COPY_IS_DEFAULT: TraitFlags =
5157
trait_flags_new(TraitFlagsValues::TRAIT_FLAGS_IS_COPY_IS_DEFAULT);
58+
#[cfg_attr(
59+
feature = "unstable_generic_const_own_type",
60+
deprecated(note = "`nightly` warning: Direct use is unstable!")
61+
)]
5262
#[cfg_attr(feature = "unstable_generic_const_own_type", allow(deprecated))]
5363
pub const TRAIT_FLAGS_IS_COPY_NO_DEFAULT: TraitFlags =
5464
trait_flags_new(TraitFlagsValues::TRAIT_FLAGS_IS_COPY_NO_DEFAULT);
65+
#[cfg_attr(
66+
feature = "unstable_generic_const_own_type",
67+
deprecated(note = "`nightly` warning: Direct use is unstable!")
68+
)]
5569
#[cfg_attr(feature = "unstable_generic_const_own_type", allow(deprecated))]
5670
pub const TRAIT_FLAGS_NO_COPY_IS_DEFAULT: TraitFlags =
5771
trait_flags_new(TraitFlagsValues::TRAIT_FLAGS_NO_COPY_IS_DEFAULT);
58-
#[cfg_attr(feature = "unstable_generic_const_own_type", deprecated(note = "`nightly` warning: Direct use is unstable!"))]
72+
#[cfg_attr(
73+
feature = "unstable_generic_const_own_type",
74+
deprecated(note = "`nightly` warning: Direct use is unstable!")
75+
)]
5976
#[cfg_attr(feature = "unstable_generic_const_own_type", allow(deprecated))]
6077
pub const TRAIT_FLAGS_NO_COPY_NO_DEFAULT: TraitFlags =
6178
trait_flags_new(TraitFlagsValues::TRAIT_FLAGS_NO_COPY_NO_DEFAULT);
@@ -82,16 +99,17 @@ mod test_flags {
8299
use super::*;
83100

84101
#[test]
102+
#[allow(deprecated)]
85103
fn all() {
86104
assert_eq!(is_copy(TRAIT_FLAGS_IS_COPY_IS_DEFAULT), true);
87105
assert_eq!(is_copy(TRAIT_FLAGS_IS_COPY_NO_DEFAULT), true);
88106
assert_eq!(is_copy(TRAIT_FLAGS_NO_COPY_IS_DEFAULT), false);
89-
assert_eq!(is_copy(#[allow(deprecated)] TRAIT_FLAGS_NO_COPY_NO_DEFAULT), false);
107+
assert_eq!(is_copy(TRAIT_FLAGS_NO_COPY_NO_DEFAULT), false);
90108

91109
assert_eq!(is_default(TRAIT_FLAGS_IS_COPY_IS_DEFAULT), true);
92110
assert_eq!(is_default(TRAIT_FLAGS_NO_COPY_IS_DEFAULT), true);
93111
assert_eq!(is_default(TRAIT_FLAGS_IS_COPY_NO_DEFAULT), false);
94-
assert_eq!(is_default(#[allow(deprecated)] TRAIT_FLAGS_NO_COPY_NO_DEFAULT), false);
112+
assert_eq!(is_default(TRAIT_FLAGS_NO_COPY_NO_DEFAULT), false);
95113
}
96114
}
97115

tests-nightly/Cargo.lock

Lines changed: 58 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests-nightly/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ version = "0.1.0"
44
edition = "2024"
55

66
[dependencies]
7-
phantom_newtype = { path = "..", features = ["unstable_generic_const_own_type"] }
7+
phantom_newtype = { path = "..", features = ["unstable_generic_const_own_type", "unstable_transmute_unchecked"] }

0 commit comments

Comments
 (0)