@@ -10,10 +10,9 @@ use rustc_session::config::ExpectedValues;
1010use  rustc_session:: lint:: builtin:: UNEXPECTED_CFGS ; 
1111use  rustc_session:: lint:: BuiltinLintDiagnostics ; 
1212use  rustc_session:: parse:: { feature_err,  ParseSess } ; 
13- use  rustc_session:: Session ; 
13+ use  rustc_session:: { RustcVersion ,   Session } ; 
1414use  rustc_span:: hygiene:: Transparency ; 
1515use  rustc_span:: { symbol:: sym,  symbol:: Symbol ,  Span } ; 
16- use  std:: fmt:: { self ,  Display } ; 
1716use  std:: num:: NonZeroU32 ; 
1817
1918use  crate :: session_diagnostics:: { self ,  IncorrectReprFormatGenericCause } ; 
@@ -24,8 +23,6 @@ use crate::session_diagnostics::{self, IncorrectReprFormatGenericCause};
2423/// For more, see [this pull request](https://github.com/rust-lang/rust/pull/100591). 
2524pub  const  VERSION_PLACEHOLDER :  & str  = "CURRENT_RUSTC_VERSION" ; 
2625
27- pub  const  CURRENT_RUSTC_VERSION :  & str  = env ! ( "CFG_RELEASE" ) ; 
28- 
2926pub  fn  is_builtin_attr ( attr :  & Attribute )  -> bool  { 
3027    attr. is_doc_comment ( )  || attr. ident ( ) . is_some_and ( |ident| is_builtin_attr_name ( ident. name ) ) 
3128} 
@@ -153,7 +150,7 @@ pub enum StabilityLevel {
153150#[ derive( Encodable ,  Decodable ,  PartialEq ,  Copy ,  Clone ,  Debug ,  Eq ,  Hash ) ]  
154151#[ derive( HashStable_Generic ) ]  
155152pub  enum  Since  { 
156-     Version ( Version ) , 
153+     Version ( RustcVersion ) , 
157154    /// Stabilized in the upcoming version, whatever number that is. 
158155Current , 
159156    /// Failed to parse a stabilization version. 
@@ -382,7 +379,7 @@ fn parse_stability(sess: &Session, attr: &Attribute) -> Option<(Symbol, Stabilit
382379    let  since = if  let  Some ( since)  = since { 
383380        if  since. as_str ( )  == VERSION_PLACEHOLDER  { 
384381            Since :: Current 
385-         }  else  if  let  Some ( version)  = parse_version ( since. as_str ( ) ,   false )  { 
382+         }  else  if  let  Some ( version)  = parse_version ( since)  { 
386383            Since :: Version ( version) 
387384        }  else  { 
388385            sess. emit_err ( session_diagnostics:: InvalidSince  {  span :  attr. span  } ) ; 
@@ -567,31 +564,20 @@ fn gate_cfg(gated_cfg: &GatedCfg, cfg_span: Span, sess: &ParseSess, features: &F
567564    } 
568565} 
569566
570- #[ derive( Encodable ,  Decodable ,  Copy ,  Clone ,  Debug ,  PartialEq ,  Eq ,  PartialOrd ,  Ord ,  Hash ) ]  
571- #[ derive( HashStable_Generic ) ]  
572- pub  struct  Version  { 
573-     pub  major :  u16 , 
574-     pub  minor :  u16 , 
575-     pub  patch :  u16 , 
576- } 
577- 
578- fn  parse_version ( s :  & str ,  allow_appendix :  bool )  -> Option < Version >  { 
579-     let  mut  components = s. split ( '-' ) ; 
567+ /// Parse a rustc version number written inside string literal in an attribute, 
568+ /// like appears in `since = "1.0.0"`. Suffixes like "-dev" and "-nightly" are 
569+ /// not accepted in this position, unlike when parsing CFG_RELEASE. 
570+ fn  parse_version ( s :  Symbol )  -> Option < RustcVersion >  { 
571+     let  mut  components = s. as_str ( ) . split ( '-' ) ; 
580572    let  d = components. next ( ) ?; 
581-     if  !allow_appendix &&  components. next ( ) . is_some ( )  { 
573+     if  components. next ( ) . is_some ( )  { 
582574        return  None ; 
583575    } 
584576    let  mut  digits = d. splitn ( 3 ,  '.' ) ; 
585577    let  major = digits. next ( ) ?. parse ( ) . ok ( ) ?; 
586578    let  minor = digits. next ( ) ?. parse ( ) . ok ( ) ?; 
587579    let  patch = digits. next ( ) . unwrap_or ( "0" ) . parse ( ) . ok ( ) ?; 
588-     Some ( Version  {  major,  minor,  patch } ) 
589- } 
590- 
591- impl  Display  for  Version  { 
592-     fn  fmt ( & self ,  formatter :  & mut  fmt:: Formatter < ' _ > )  -> fmt:: Result  { 
593-         write ! ( formatter,  "{}.{}.{}" ,  self . major,  self . minor,  self . patch) 
594-     } 
580+     Some ( RustcVersion  {  major,  minor,  patch } ) 
595581} 
596582
597583/// Evaluate a cfg-like condition (with `any` and `all`), using `eval` to 
@@ -623,17 +609,16 @@ pub fn eval_condition(
623609                    return  false ; 
624610                } 
625611            } ; 
626-             let  Some ( min_version)  = parse_version ( min_version. as_str ( ) ,   false )  else  { 
612+             let  Some ( min_version)  = parse_version ( * min_version)  else  { 
627613                sess. emit_warning ( session_diagnostics:: UnknownVersionLiteral  {  span :  * span } ) ; 
628614                return  false ; 
629615            } ; 
630-             let  rustc_version = parse_version ( CURRENT_RUSTC_VERSION ,  true ) . unwrap ( ) ; 
631616
632617            // See https://github.com/rust-lang/rust/issues/64796#issuecomment-640851454 for details 
633618            if  sess. assume_incomplete_release  { 
634-                 rustc_version  > min_version
619+                 RustcVersion :: CURRENT  > min_version
635620            }  else  { 
636-                 rustc_version  >= min_version
621+                 RustcVersion :: CURRENT  >= min_version
637622            } 
638623        } 
639624        ast:: MetaItemKind :: List ( mis)  => { 
0 commit comments