@@ -36,6 +36,7 @@ enum AttrError {
36
36
MultipleItem ( String ) ,
37
37
UnknownMetaItem ( String , & ' static [ & ' static str ] ) ,
38
38
MissingSince ,
39
+ InvalidSince ,
39
40
NonIdentFeature ,
40
41
MissingFeature ,
41
42
MultipleStabilityLevels ,
@@ -58,6 +59,7 @@ fn handle_errors(sess: &ParseSess, span: Span, error: AttrError) -> ErrorGuarant
58
59
sess. emit_err ( session_diagnostics:: UnknownMetaItem { span, item, expected } )
59
60
}
60
61
AttrError :: MissingSince => sess. emit_err ( session_diagnostics:: MissingSince { span } ) ,
62
+ AttrError :: InvalidSince => sess. emit_err ( session_diagnostics:: InvalidSince { span } ) ,
61
63
AttrError :: NonIdentFeature => sess. emit_err ( session_diagnostics:: NonIdentFeature { span } ) ,
62
64
AttrError :: MissingFeature => sess. emit_err ( session_diagnostics:: MissingFeature { span } ) ,
63
65
AttrError :: MultipleStabilityLevels => {
@@ -400,12 +402,6 @@ fn parse_stability(sess: &Session, attr: &Attribute) -> Option<(Symbol, Stabilit
400
402
}
401
403
}
402
404
403
- if let Some ( s) = since
404
- && s. as_str ( ) == VERSION_PLACEHOLDER
405
- {
406
- since = Some ( rust_version_symbol ( ) ) ;
407
- }
408
-
409
405
let feature = match feature {
410
406
Some ( feature) if rustc_lexer:: is_ident ( feature. as_str ( ) ) => Ok ( feature) ,
411
407
Some ( _bad_feature) => {
@@ -414,8 +410,17 @@ fn parse_stability(sess: &Session, attr: &Attribute) -> Option<(Symbol, Stabilit
414
410
None => Err ( handle_errors ( & sess. parse_sess , attr. span , AttrError :: MissingFeature ) ) ,
415
411
} ;
416
412
417
- let since =
418
- since. ok_or_else ( || handle_errors ( & sess. parse_sess , attr. span , AttrError :: MissingSince ) ) ;
413
+ let since = if let Some ( since) = since {
414
+ if since. as_str ( ) == VERSION_PLACEHOLDER {
415
+ Ok ( rust_version_symbol ( ) )
416
+ } else if parse_version ( since. as_str ( ) , false ) . is_some ( ) {
417
+ Ok ( since)
418
+ } else {
419
+ Err ( handle_errors ( & sess. parse_sess , attr. span , AttrError :: InvalidSince ) )
420
+ }
421
+ } else {
422
+ Err ( handle_errors ( & sess. parse_sess , attr. span , AttrError :: MissingSince ) )
423
+ } ;
419
424
420
425
match ( feature, since) {
421
426
( Ok ( feature) , Ok ( since) ) => {
0 commit comments