@@ -22,6 +22,8 @@ pub struct ConstantDef {
2222 pub value : Lazy < ConstantValue > ,
2323 /// The constant's documentation
2424 pub doc : Lazy < String > ,
25+ /// The suggested replacement because of deprecation
26+ pub deprecation : Option < & ' static str > ,
2527}
2628
2729impl ConstantDef {
@@ -33,6 +35,10 @@ impl ConstantDef {
3335 pub fn doc_frags ( & self ) -> Vec < PrimDocFragment > {
3436 parse_doc_line_fragments ( self . doc ( ) )
3537 }
38+ /// Check if the constant is deprecated
39+ pub fn is_deprecated ( & self ) -> bool {
40+ self . deprecation . is_some ( )
41+ }
3642}
3743
3844/// The value of a shadowable constant
@@ -101,7 +107,16 @@ where
101107}
102108
103109macro_rules! constant {
104- ( $( $( #[ doc = $doc: literal] ) + ( $( #[ $attr: meta] ) * $name: literal, $class: ident, $value: expr) ) ,* $( , ) ?) => {
110+ ( $(
111+ $( #[ doc = $doc: literal] ) +
112+ (
113+ $( #[ $attr: meta] ) *
114+ $name: literal,
115+ $class: ident,
116+ $value: expr
117+ $( , deprecated( $deprecation: literal) ) ?
118+ )
119+ ) ,* $( , ) ?) => {
105120 const COUNT : usize = {
106121 let mut count = 0 ;
107122 $(
@@ -114,6 +129,7 @@ macro_rules! constant {
114129 count
115130 } ;
116131 /// The list of all shadowable constants
132+ #[ allow( path_statements) ]
117133 pub static CONSTANTS : [ ConstantDef ; COUNT ] =
118134 [ $(
119135 $( #[ $attr] ) *
@@ -130,6 +146,7 @@ macro_rules! constant {
130146 s. pop( ) ;
131147 s
132148 } ) ,
149+ deprecation: { None :: <& ' static str > $( ; Some ( $deprecation) ) ? }
133150 } ,
134151 ) * ] ;
135152 } ;
@@ -185,17 +202,17 @@ constant!(
185202 [ 0 , 1 , -1 ] , [ 1 , 0 , -1 ] , [ 0 , -1 , -1 ] , [ -1 , 0 , -1 ]
186203 ] ) ,
187204 /// A string identifying the operating system
188- ( "Os" , System , std:: env:: consts:: OS ) ,
205+ ( "Os" , System , std:: env:: consts:: OS , deprecated ( "Use the os function instead" ) ) ,
189206 /// A string identifying family of the operating system
190- ( "Family" , System , std:: env:: consts:: FAMILY ) ,
207+ ( "Family" , System , std:: env:: consts:: FAMILY , deprecated ( "Use the osfamily function instead" ) ) ,
191208 /// A string identifying the architecture of the CPU
192- ( "Arch" , System , std:: env:: consts:: ARCH ) ,
209+ ( "Arch" , System , std:: env:: consts:: ARCH , deprecated ( "Use the arch function instead" ) ) ,
193210 /// The executable file extension
194- ( "ExeExt" , System , std:: env:: consts:: EXE_EXTENSION ) ,
211+ ( "ExeExt" , System , std:: env:: consts:: EXE_EXTENSION , deprecated ( "Use the exeext function instead" ) ) ,
195212 /// The file extension for shared libraries
196- ( "DllExt" , System , std:: env:: consts:: DLL_EXTENSION ) ,
213+ ( "DllExt" , System , std:: env:: consts:: DLL_EXTENSION , deprecated ( "Use the dllext function instead" ) ) ,
197214 /// The primary path separator character
198- ( "Sep" , System , std:: path:: MAIN_SEPARATOR ) ,
215+ ( "Sep" , System , std:: path:: MAIN_SEPARATOR , deprecated ( "Use the pathsep function instead" ) ) ,
199216 /// The path of the current source file relative to `WorkingDir`
200217 ( "ThisFile" , System , ConstantValue :: ThisFile ) ,
201218 /// The name of the current source file
@@ -205,7 +222,7 @@ constant!(
205222 /// The compile-time working directory
206223 ( "WorkingDir" , System , ConstantValue :: WorkingDir ) ,
207224 /// The number of processors available
208- ( "NumProcs" , System , num_cpus:: get( ) as f64 ) ,
225+ ( "NumProcs" , System , num_cpus:: get( ) as f64 , deprecated ( "Use the numprocs function instead" ) ) ,
209226 /// A boolean `true` value for use in `json`
210227 ( "True" , External , Array :: json_bool( true ) ) ,
211228 /// A boolean `false` value for use in `json`
0 commit comments