Skip to content

Commit 453bd08

Browse files
Adjusting tests for rust-lang/rust#134044 and probably for rust-lang/rust#133199
1 parent 2caa986 commit 453bd08

File tree

5 files changed

+187
-24
lines changed

5 files changed

+187
-24
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
target/
22
.vscode/settings.json
3+
rustc-ice*

src/amount.rs

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer};
4545
/// amounts more convenient. For example, you can compare amounts:
4646
///
4747
/// ```
48+
/// #![cfg_attr(
49+
/// feature = "unstable_generic_const_own_type",
50+
/// feature(generic_const_exprs)
51+
/// )]
52+
///
4853
/// use phantom_newtype::Amount;
4954
///
5055
/// enum Apples {}
@@ -63,6 +68,11 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer};
6368
/// You can do simple arithmetics with amounts:
6469
///
6570
/// ```
71+
/// #![cfg_attr(
72+
/// feature = "unstable_generic_const_own_type",
73+
/// feature(generic_const_exprs)
74+
/// )]
75+
///
6676
/// use phantom_newtype::Amount;
6777
///
6878
/// enum Apples {}
@@ -80,6 +90,11 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer};
8090
/// scalar or divide amounts:
8191
///
8292
/// ```
93+
/// #![cfg_attr(
94+
/// feature = "unstable_generic_const_own_type",
95+
/// feature(generic_const_exprs)
96+
/// )]
97+
///
8398
/// use phantom_newtype::Amount;
8499
///
85100
/// enum Apples {}
@@ -94,6 +109,11 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer};
94109
/// `Amount` instead of `u64` doesn't incur any runtime penalty:
95110
///
96111
/// ```
112+
/// #![cfg_attr(
113+
/// feature = "unstable_generic_const_own_type",
114+
/// feature(generic_const_exprs)
115+
/// )]
116+
///
97117
/// use phantom_newtype::Amount;
98118
///
99119
/// enum Meters {}
@@ -106,6 +126,11 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer};
106126
/// forms of `Amount<Unit, Repr>` and `Repr` are identical.
107127
///
108128
/// ```
129+
/// #![cfg_attr(
130+
/// feature = "unstable_generic_const_own_type",
131+
/// feature(generic_const_exprs)
132+
/// )]
133+
///
109134
/// #[cfg(feature = "serde")] {
110135
/// use phantom_newtype::Amount;
111136
/// use serde::{Serialize, Deserialize};
@@ -124,6 +149,11 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer};
124149
/// You can also declare constants of `Amount<Unit, Repr>` using `new`
125150
/// function:
126151
/// ```
152+
/// #![cfg_attr(
153+
/// feature = "unstable_generic_const_own_type",
154+
/// feature(generic_const_exprs)
155+
/// )]
156+
///
127157
/// use phantom_newtype::Amount;
128158
/// enum Meters {}
129159
/// type Distance = Amount<Meters, u64>;
@@ -136,6 +166,11 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer};
136166
/// matter which `Unit` is used.
137167
///
138168
/// ```
169+
/// #![cfg_attr(
170+
/// feature = "unstable_generic_const_own_type",
171+
/// feature(generic_const_exprs)
172+
/// )]
173+
///
139174
/// use phantom_newtype::Amount;
140175
///
141176
/// type Cell = core::cell::RefCell<i64>;
@@ -156,6 +191,11 @@ impl<const TF: TraitFlags, Unit, Repr: Copy> Amount<TF, Unit, Repr> {
156191
/// Returns the wrapped value.
157192
///
158193
/// ```
194+
/// #![cfg_attr(
195+
/// feature = "unstable_generic_const_own_type",
196+
/// feature(generic_const_exprs)
197+
/// )]
198+
///
159199
/// use phantom_newtype::Amount;
160200
///
161201
/// enum Apples {}
@@ -184,6 +224,11 @@ impl<const TF: TraitFlags, Unit: Default, Repr> Amount<TF, Unit, Repr> {
184224
/// they implement the `Default` trait:
185225
///
186226
/// ```
227+
/// #![cfg_attr(
228+
/// feature = "unstable_generic_const_own_type",
229+
/// feature(generic_const_exprs)
230+
/// )]
231+
///
187232
/// use phantom_newtype::Amount;
188233
///
189234
/// #[derive(Debug, Default)]
@@ -204,7 +249,13 @@ where
204249
/// `display` provides a machanism to implement a custom display
205250
/// for phantom types.
206251
///
207-
/// ```
252+
/// ```ignore
253+
/// #![cfg_attr(
254+
/// feature = "unstable_generic_const_own_type",
255+
/// feature(generic_const_exprs),
256+
/// feature(adt_const_params),
257+
/// )]
258+
///
208259
/// use phantom_newtype::{Amount, DisplayerOf};
209260
/// use core::fmt;
210261
///

src/id.rs

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer};
6161
/// `Id` is cheap to copy if `Repr` is:
6262
///
6363
/// ```
64+
/// #![cfg_attr(
65+
/// feature = "unstable_generic_const_own_type",
66+
/// feature(generic_const_exprs)
67+
/// )]
68+
///
6469
/// use phantom_newtype::Id;
6570
///
6671
/// enum Message {}
@@ -75,6 +80,11 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer};
7580
/// this property:
7681
///
7782
/// ```
83+
/// #![cfg_attr(
84+
/// feature = "unstable_generic_const_own_type",
85+
/// feature(generic_const_exprs)
86+
/// )]
87+
///
7888
/// use phantom_newtype::Id;
7989
/// use std::collections::HashMap;
8090
///
@@ -94,6 +104,11 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer};
94104
/// semantic value in comparing ids.
95105
///
96106
/// ```
107+
/// #![cfg_attr(
108+
/// feature = "unstable_generic_const_own_type",
109+
/// feature(generic_const_exprs)
110+
/// )]
111+
///
97112
/// use std::collections::BTreeMap;
98113
/// use phantom_newtype::Id;
99114
///
@@ -112,6 +127,11 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer};
112127
/// matter which `Entity` is used.
113128
///
114129
/// ```
130+
/// #![cfg_attr(
131+
/// feature = "unstable_generic_const_own_type",
132+
/// feature(generic_const_exprs)
133+
/// )]
134+
///
115135
/// use phantom_newtype::Id;
116136
///
117137
/// type Cell = core::cell::RefCell<i64>;
@@ -126,6 +146,11 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer};
126146
/// forms of `Id<Entity, Repr>` and `Repr` are identical.
127147
///
128148
/// ```
149+
/// #![cfg_attr(
150+
/// feature = "unstable_generic_const_own_type",
151+
/// feature(generic_const_exprs)
152+
/// )]
153+
///
129154
/// #[cfg(feature = "serde")] {
130155
/// use phantom_newtype::Id;
131156
/// use serde::{Serialize, Deserialize};
@@ -147,6 +172,11 @@ impl<const TF: TraitFlags, Entity, Repr> Id<TF, Entity, Repr> {
147172
/// `get` returns the underlying representation of the identifier.
148173
///
149174
/// ```
175+
/// #![cfg_attr(
176+
/// feature = "unstable_generic_const_own_type",
177+
/// feature(generic_const_exprs)
178+
/// )]
179+
///
150180
/// use phantom_newtype::Id;
151181
///
152182
/// enum User {}
@@ -163,6 +193,11 @@ impl<const TF: TraitFlags, Entity, Repr> Id<TF, Entity, Repr> {
163193
/// constants:
164194
///
165195
/// ```
196+
/// #![cfg_attr(
197+
/// feature = "unstable_generic_const_own_type",
198+
/// feature(generic_const_exprs)
199+
/// )]
200+
///
166201
/// use phantom_newtype::Id;
167202
/// enum User {}
168203
/// type UserId = Id<User, u64>;
@@ -184,24 +219,28 @@ where
184219
/// for phantom types.
185220
///
186221
/// ```
187-
/// use phantom_newtype::{Id, DisplayerOf};
222+
/// #![cfg_attr(
223+
/// feature = "unstable_generic_const_own_type",
224+
/// feature(generic_const_exprs),
225+
/// )]
226+
///
227+
/// //use phantom_newtype::{Id, DisplayerOf};
228+
/// use phantom_newtype::DisplayerOf;
229+
/// use phantom_newtype::IdNoCopyNoDefault;
230+
/// //use phantom_newtype::IdIsCopyIsDefault as Id;
231+
/// //use phantom_newtype::IdNoCopyNoDefault as Id;
188232
/// use core::fmt;
189233
///
190234
/// enum Message {}
191-
/// type MessageId = Id<Message, [u8; 32]>;
235+
/// type MessageId = IdNoCopyNoDefault<Message, [u8; 32]>;
192236
///
193237
/// impl DisplayerOf<MessageId> for Message {
194238
/// fn display(id: &MessageId, f: &mut fmt::Formatter<'_>) -> fmt::Result {
195-
/// id.get().iter().try_for_each(|b| write!(f, "{:02x}", b))
239+
/// todo!()
196240
/// }
197241
/// }
198242
///
199-
/// let vec: Vec<_> = (0u8..32u8).collect();
200-
/// let mut arr: [u8; 32] = [0u8; 32];
201-
/// (&mut arr[..]).copy_from_slice(&vec[..]);
202-
///
203-
/// assert_eq!(format!("{}", MessageId::from(arr).display()),
204-
/// "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f");
243+
/// MessageId::from([0u8; 32]);
205244
/// ```
206245
pub fn display(&self) -> DisplayProxy<'_, Self, Entity> {
207246
DisplayProxy::new(self)

src/instant.rs

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer};
3131
/// You can compare instants:
3232
///
3333
/// ```
34+
/// #![cfg_attr(
35+
/// feature = "unstable_generic_const_own_type",
36+
/// feature(generic_const_exprs)
37+
/// )]
38+
///
3439
/// use phantom_newtype::Instant;
3540
///
3641
/// enum SecondsFromEpoch {}
@@ -51,6 +56,11 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer};
5156
/// * Add/subtract amount of units to/from an instant to get another instant.
5257
///
5358
/// ```
59+
/// #![cfg_attr(
60+
/// feature = "unstable_generic_const_own_type",
61+
/// feature(generic_const_exprs)
62+
/// )]
63+
///
5464
/// use phantom_newtype::{Amount, Instant};
5565
///
5666
/// enum SecondsFromEpoch {}
@@ -71,6 +81,11 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer};
7181
/// can scale them by a scalar or divide to get a scalar back:
7282
///
7383
/// ```
84+
/// #![cfg_attr(
85+
/// feature = "unstable_generic_const_own_type",
86+
/// feature(generic_const_exprs)
87+
/// )]
88+
///
7489
/// use phantom_newtype::Instant;
7590
///
7691
/// enum SecondsFromEpoch {}
@@ -86,6 +101,11 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer};
86101
/// `Instant` instead of `u64` doesn't incur any runtime penalty:
87102
///
88103
/// ```
104+
/// #![cfg_attr(
105+
/// feature = "unstable_generic_const_own_type",
106+
/// feature(generic_const_exprs)
107+
/// )]
108+
///
89109
/// use phantom_newtype::Instant;
90110
///
91111
/// enum SecondsFromEpoch {}
@@ -97,7 +117,7 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer};
97117
/// Instants can be serialized and deserialized with `serde`. Serialized
98118
/// forms of `Instant<Unit, Repr>` and `Repr` are identical.
99119
///
100-
/// ```
120+
/// ```ignore
101121
/// #[cfg(feature = "serde")] {
102122
/// use phantom_newtype::Instant;
103123
/// use serde::{Serialize, Deserialize};
@@ -118,6 +138,11 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer};
118138
/// You can also declare constants of `Instant<Unit, Repr>` using `new`
119139
/// function:
120140
/// ```
141+
/// #![cfg_attr(
142+
/// feature = "unstable_generic_const_own_type",
143+
/// feature(generic_const_exprs)
144+
/// )]
145+
///
121146
/// use phantom_newtype::Instant;
122147
///
123148
/// enum SecondsFromEpoch {}
@@ -130,6 +155,11 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer};
130155
/// matter which `Unit` is used.
131156
///
132157
/// ```
158+
/// #![cfg_attr(
159+
/// feature = "unstable_generic_const_own_type",
160+
/// feature(generic_const_exprs)
161+
/// )]
162+
///
133163
/// use phantom_newtype::Instant;
134164
///
135165
/// type Cell = core::cell::RefCell<i64>;
@@ -153,6 +183,11 @@ impl<const TF: TraitFlags, Unit, Repr: Copy> Instant<TF, Unit, Repr> {
153183
/// Returns the wrapped value.
154184
///
155185
/// ```
186+
/// #![cfg_attr(
187+
/// feature = "unstable_generic_const_own_type",
188+
/// feature(generic_const_exprs)
189+
/// )]
190+
///
156191
/// use phantom_newtype::Instant;
157192
///
158193
/// enum Apples {}
@@ -179,6 +214,11 @@ impl<const TF: TraitFlags, Unit: Default, Repr> Instant<TF, Unit, Repr> {
179214
/// they implement the `Default` trait:
180215
///
181216
/// ```
217+
/// #![cfg_attr(
218+
/// feature = "unstable_generic_const_own_type",
219+
/// feature(generic_const_exprs)
220+
/// )]
221+
///
182222
/// use phantom_newtype::Instant;
183223
///
184224
/// #[derive(Debug, Default)]
@@ -199,7 +239,7 @@ where
199239
/// `display` provides a machanism to implement a custom display
200240
/// for phantom types.
201241
///
202-
/// ```
242+
/// ```ignore
203243
/// use phantom_newtype::{Instant, DisplayerOf};
204244
/// use core::fmt;
205245
///

0 commit comments

Comments
 (0)