@@ -24,9 +24,16 @@ impl Parse for Newtype {
2424 let mut consts = Vec :: new ( ) ;
2525 let mut encodable = true ;
2626 let mut ord = true ;
27+ let mut gate_rustc_only = quote ! { } ;
28+ let mut gate_rustc_only_cfg = quote ! { all( ) } ;
2729
2830 attrs. retain ( |attr| match attr. path ( ) . get_ident ( ) {
2931 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+ }
3037 "custom_encodable" => {
3138 encodable = false ;
3239 false
@@ -88,11 +95,13 @@ impl Parse for Newtype {
8895
8996 let encodable_impls = if encodable {
9097 quote ! {
98+ #gate_rustc_only
9199 impl <D : :: rustc_serialize:: Decoder > :: rustc_serialize:: Decodable <D > for #name {
92100 fn decode( d: & mut D ) -> Self {
93101 Self :: from_u32( d. read_u32( ) )
94102 }
95103 }
104+ #gate_rustc_only
96105 impl <E : :: rustc_serialize:: Encoder > :: rustc_serialize:: Encodable <E > for #name {
97106 fn encode( & self , e: & mut E ) {
98107 e. emit_u32( self . private) ;
@@ -110,6 +119,7 @@ impl Parse for Newtype {
110119
111120 let step = if ord {
112121 quote ! {
122+ #gate_rustc_only
113123 impl :: std:: iter:: Step for #name {
114124 #[ inline]
115125 fn steps_between( start: & Self , end: & Self ) -> Option <usize > {
@@ -131,6 +141,7 @@ impl Parse for Newtype {
131141 }
132142
133143 // Safety: The implementation of `Step` upholds all invariants.
144+ #gate_rustc_only
134145 unsafe impl :: std:: iter:: TrustedStep for #name { }
135146 }
136147 } else {
@@ -148,6 +159,7 @@ impl Parse for Newtype {
148159 let spec_partial_eq_impl = if let Lit :: Int ( max) = & max {
149160 if let Ok ( max_val) = max. base10_parse :: < u32 > ( ) {
150161 quote ! {
162+ #gate_rustc_only
151163 impl core:: option:: SpecOptionPartialEq for #name {
152164 #[ inline]
153165 fn eq( l: & Option <Self >, r: & Option <Self >) -> bool {
@@ -173,8 +185,8 @@ impl Parse for Newtype {
173185 Ok ( Self ( quote ! {
174186 #( #attrs) *
175187 #[ 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) ]
178190 #vis struct #name {
179191 private: u32 ,
180192 }
0 commit comments