@@ -8,19 +8,28 @@ use crate::cmp::Ordering;
88use crate :: fmt;
99use crate :: hash:: { Hash , Hasher } ;
1010use crate :: marker:: StructuralPartialEq ;
11+ #[ cfg( not( bootstrap) ) ]
12+ use crate :: pattern_type;
1113
1214macro_rules! define_valid_range_type {
1315 ( $(
1416 $( #[ $m: meta] ) *
1517 $vis: vis struct $name: ident( $int: ident as $uint: ident in $low: literal..=$high: literal) ;
1618 ) +) => { $(
17- #[ derive( Clone , Copy , Eq ) ]
19+ #[ derive( Clone , Copy ) ]
1820 #[ repr( transparent) ]
19- #[ rustc_layout_scalar_valid_range_start( $low) ]
20- #[ rustc_layout_scalar_valid_range_end( $high) ]
21+ #[ cfg_attr ( bootstrap , rustc_layout_scalar_valid_range_start( $low) ) ]
22+ #[ cfg_attr ( bootstrap , rustc_layout_scalar_valid_range_end( $high) ) ]
2123 $( #[ $m] ) *
24+ #[ cfg( bootstrap) ]
2225 $vis struct $name( $int) ;
2326
27+ #[ derive( Clone , Copy ) ]
28+ #[ repr( transparent) ]
29+ $( #[ $m] ) *
30+ #[ cfg( not( bootstrap) ) ]
31+ $vis struct $name( pattern_type!( $int is $low..=$high) ) ;
32+
2433 const _: ( ) = {
2534 // With the `valid_range` attributes, it's always specified as unsigned
2635 assert!( <$uint>:: MIN == 0 ) ;
@@ -41,7 +50,7 @@ macro_rules! define_valid_range_type {
4150 #[ inline]
4251 pub const unsafe fn new_unchecked( val: $int) -> Self {
4352 // SAFETY: Caller promised that `val` is non-zero.
44- unsafe { $name( val) }
53+ unsafe { $name( crate :: mem :: transmute ( val) ) }
4554 }
4655
4756 #[ inline]
@@ -57,6 +66,8 @@ macro_rules! define_valid_range_type {
5766 // by <https://github.com/rust-lang/compiler-team/issues/807>.
5867 impl StructuralPartialEq for $name { }
5968
69+ impl Eq for $name { }
70+
6071 impl PartialEq for $name {
6172 #[ inline]
6273 fn eq( & self , other: & Self ) -> bool {
0 commit comments