@@ -8,19 +8,28 @@ use crate::cmp::Ordering;
8
8
use crate :: fmt;
9
9
use crate :: hash:: { Hash , Hasher } ;
10
10
use crate :: marker:: StructuralPartialEq ;
11
+ #[ cfg( not( bootstrap) ) ]
12
+ use crate :: pattern_type;
11
13
12
14
macro_rules! define_valid_range_type {
13
15
( $(
14
16
$( #[ $m: meta] ) *
15
17
$vis: vis struct $name: ident( $int: ident as $uint: ident in $low: literal..=$high: literal) ;
16
18
) +) => { $(
17
- #[ derive( Clone , Copy , Eq ) ]
19
+ #[ derive( Clone , Copy ) ]
18
20
#[ 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) ) ]
21
23
$( #[ $m] ) *
24
+ #[ cfg( bootstrap) ]
22
25
$vis struct $name( $int) ;
23
26
27
+ #[ derive( Clone , Copy ) ]
28
+ #[ repr( transparent) ]
29
+ $( #[ $m] ) *
30
+ #[ cfg( not( bootstrap) ) ]
31
+ $vis struct $name( pattern_type!( $int is $low..=$high) ) ;
32
+
24
33
const _: ( ) = {
25
34
// With the `valid_range` attributes, it's always specified as unsigned
26
35
assert!( <$uint>:: MIN == 0 ) ;
@@ -41,7 +50,7 @@ macro_rules! define_valid_range_type {
41
50
#[ inline]
42
51
pub const unsafe fn new_unchecked( val: $int) -> Self {
43
52
// SAFETY: Caller promised that `val` is non-zero.
44
- unsafe { $name( val) }
53
+ unsafe { $name( crate :: mem :: transmute ( val) ) }
45
54
}
46
55
47
56
#[ inline]
@@ -57,6 +66,8 @@ macro_rules! define_valid_range_type {
57
66
// by <https://github.com/rust-lang/compiler-team/issues/807>.
58
67
impl StructuralPartialEq for $name { }
59
68
69
+ impl Eq for $name { }
70
+
60
71
impl PartialEq for $name {
61
72
#[ inline]
62
73
fn eq( & self , other: & Self ) -> bool {
0 commit comments