@@ -24,9 +24,16 @@ impl Parse for Newtype {
24
24
let mut consts = Vec :: new ( ) ;
25
25
let mut encodable = true ;
26
26
let mut ord = true ;
27
+ let mut gate_rustc_only = quote ! { } ;
28
+ let mut gate_rustc_only_cfg = quote ! { all( ) } ;
27
29
28
30
attrs. retain ( |attr| match attr. path ( ) . get_ident ( ) {
29
31
Some ( ident) => match & * ident. to_string ( ) {
32
+ "gate_rustc_only" => {
33
+ gate_rustc_only = quote ! { #[ cfg( feature = "nightly" ) ] } ;
34
+ gate_rustc_only_cfg = quote ! { feature = "nightly" } ;
35
+ false
36
+ }
30
37
"custom_encodable" => {
31
38
encodable = false ;
32
39
false
@@ -88,11 +95,13 @@ impl Parse for Newtype {
88
95
89
96
let encodable_impls = if encodable {
90
97
quote ! {
98
+ #gate_rustc_only
91
99
impl <D : :: rustc_serialize:: Decoder > :: rustc_serialize:: Decodable <D > for #name {
92
100
fn decode( d: & mut D ) -> Self {
93
101
Self :: from_u32( d. read_u32( ) )
94
102
}
95
103
}
104
+ #gate_rustc_only
96
105
impl <E : :: rustc_serialize:: Encoder > :: rustc_serialize:: Encodable <E > for #name {
97
106
fn encode( & self , e: & mut E ) {
98
107
e. emit_u32( self . private) ;
@@ -110,6 +119,7 @@ impl Parse for Newtype {
110
119
111
120
let step = if ord {
112
121
quote ! {
122
+ #gate_rustc_only
113
123
impl :: std:: iter:: Step for #name {
114
124
#[ inline]
115
125
fn steps_between( start: & Self , end: & Self ) -> Option <usize > {
@@ -131,6 +141,7 @@ impl Parse for Newtype {
131
141
}
132
142
133
143
// Safety: The implementation of `Step` upholds all invariants.
144
+ #gate_rustc_only
134
145
unsafe impl :: std:: iter:: TrustedStep for #name { }
135
146
}
136
147
} else {
@@ -148,6 +159,7 @@ impl Parse for Newtype {
148
159
let spec_partial_eq_impl = if let Lit :: Int ( max) = & max {
149
160
if let Ok ( max_val) = max. base10_parse :: < u32 > ( ) {
150
161
quote ! {
162
+ #gate_rustc_only
151
163
impl core:: option:: SpecOptionPartialEq for #name {
152
164
#[ inline]
153
165
fn eq( l: & Option <Self >, r: & Option <Self >) -> bool {
@@ -173,8 +185,8 @@ impl Parse for Newtype {
173
185
Ok ( Self ( quote ! {
174
186
#( #attrs) *
175
187
#[ derive( Clone , Copy , PartialEq , Eq , Hash , #( #derive_paths) , * ) ]
176
- #[ rustc_layout_scalar_valid_range_end( #max) ]
177
- #[ rustc_pass_by_value]
188
+ #[ cfg_attr ( #gate_rustc_only_cfg , rustc_layout_scalar_valid_range_end( #max) ) ]
189
+ #[ cfg_attr ( #gate_rustc_only_cfg , rustc_pass_by_value) ]
178
190
#vis struct #name {
179
191
private: u32 ,
180
192
}
0 commit comments