@@ -321,23 +321,26 @@ fn kind_from_prim(ek: u32) -> Option<ErrorKind> {
321
321
// that our encoding relies on for correctness and soundness. (Some of these are
322
322
// a bit overly thorough/cautious, admittedly)
323
323
//
324
- // If any of these are hit on a platform that libstd supports, we should just
325
- // make sure `repr_unpacked.rs` is used instead.
324
+ // If any of these are hit on a platform that libstd supports, we should likely
325
+ // just use `repr_unpacked.rs` there instead (unless the fix is easy) .
326
326
macro_rules! static_assert {
327
327
( $condition: expr) => {
328
- const _: [ ( ) ; 0 ] = [ ( ) ; ( !$condition) as usize ] ;
328
+ const _: ( ) = assert!( $condition) ;
329
+ } ;
330
+ ( @usize_eq: $lhs: expr, $rhs: expr) => {
331
+ const _: [ ( ) ; $lhs] = [ ( ) ; $rhs] ;
329
332
} ;
330
333
}
331
334
332
335
// The bitpacking we use requires pointers be exactly 64 bits.
333
- static_assert ! ( size_of:: <NonNull <( ) >>( ) == 8 ) ;
336
+ static_assert ! ( @usize_eq : size_of:: <NonNull <( ) >>( ) , 8 ) ;
334
337
335
338
// We also require pointers and usize be the same size.
336
- static_assert ! ( size_of:: <NonNull <( ) >>( ) == size_of:: <usize >( ) ) ;
339
+ static_assert ! ( @usize_eq : size_of:: <NonNull <( ) >>( ) , size_of:: <usize >( ) ) ;
337
340
338
341
// `Custom` and `SimpleMessage` need to be thin pointers.
339
- static_assert ! ( size_of:: <& ' static SimpleMessage >( ) == 8 ) ;
340
- static_assert ! ( size_of:: <Box <Custom >>( ) == 8 ) ;
342
+ static_assert ! ( @usize_eq : size_of:: <& ' static SimpleMessage >( ) , 8 ) ;
343
+ static_assert ! ( @usize_eq : size_of:: <Box <Custom >>( ) , 8 ) ;
341
344
342
345
// And they must have >= 4 byte alignment.
343
346
static_assert ! ( align_of:: <SimpleMessage >( ) >= 4 ) ;
@@ -346,20 +349,21 @@ static_assert!(align_of::<Custom>() >= 4);
346
349
// This is obviously true (`TAG_CUSTOM` is `0b01`), but our implementation of
347
350
// `Repr::new_custom` and such would be wrong if it were not, so we check.
348
351
static_assert ! ( size_of:: <Custom >( ) >= TAG_CUSTOM ) ;
352
+
349
353
// These two store a payload which is allowed to be zero, so they must be
350
354
// non-zero to preserve the `NonNull`'s range invariant.
351
355
static_assert ! ( TAG_OS != 0 ) ;
352
356
static_assert ! ( TAG_SIMPLE != 0 ) ;
353
357
// We can't tag `SimpleMessage`s, the tag must be 0.
354
- static_assert ! ( TAG_SIMPLE_MESSAGE == 0 ) ;
358
+ static_assert ! ( @usize_eq : TAG_SIMPLE_MESSAGE , 0 ) ;
355
359
356
360
// Check that the point of all of this still holds.
357
361
//
358
362
// We'd check against `io::Error`, but *technically* it's allowed to vary,
359
363
// as it's not `#[repr(transparent)]`/`#[repr(C)]`. We could add that, but
360
364
// the `#[repr()]` would show up in rustdoc, which might be seen as a stable
361
365
// commitment.
362
- static_assert ! ( size_of:: <Repr >( ) == 8 ) ;
363
- static_assert ! ( size_of:: <Option <Repr >>( ) == 8 ) ;
364
- static_assert ! ( size_of:: <Result <( ) , Repr >>( ) == 8 ) ;
365
- static_assert ! ( size_of:: <Result <usize , Repr >>( ) == 16 ) ;
366
+ static_assert ! ( @usize_eq : size_of:: <Repr >( ) , 8 ) ;
367
+ static_assert ! ( @usize_eq : size_of:: <Option <Repr >>( ) , 8 ) ;
368
+ static_assert ! ( @usize_eq : size_of:: <Result <( ) , Repr >>( ) , 8 ) ;
369
+ static_assert ! ( @usize_eq : size_of:: <Result <usize , Repr >>( ) , 16 ) ;
0 commit comments