@@ -470,6 +470,30 @@ pub fn check_unstable_api_usage<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
470470 tcx. hir . krate ( ) . visit_all_item_likes ( & mut checker. as_deep_visitor ( ) ) ;
471471}
472472
473+ /// Check whether an item marked with `deprecated(since="X")` is currently
474+ /// deprecated (i.e. whether X is not greater than the current rustc version).
475+ pub fn deprecation_in_effect ( since : & str ) -> bool {
476+ fn parse_version ( ver : & str ) -> Vec < u32 > {
477+ // We ignore non-integer components of the version (e.g. "nightly").
478+ ver. split ( |c| c == '.' || c == '-' ) . flat_map ( |s| s. parse ( ) ) . collect ( )
479+ }
480+
481+ if let Some ( rustc) = option_env ! ( "CFG_RELEASE" ) {
482+ let since: Vec < u32 > = parse_version ( since) ;
483+ let rustc: Vec < u32 > = parse_version ( rustc) ;
484+ // We simply treat invalid `since` attributes as relating to a previous
485+ // Rust version, thus always displaying the warning.
486+ if since. len ( ) != 3 {
487+ return true ;
488+ }
489+ since <= rustc
490+ } else {
491+ // By default, a deprecation warning applies to
492+ // the current version of the compiler.
493+ true
494+ }
495+ }
496+
473497struct Checker < ' a , ' tcx : ' a > {
474498 tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
475499}
@@ -559,33 +583,11 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
559583 // Deprecated attributes apply in-crate and cross-crate.
560584 if let Some ( id) = id {
561585 if let Some ( depr_entry) = self . lookup_deprecation_entry ( def_id) {
562- fn deprecation_in_effect ( since : Option < & str > , rustc : Option < & str > ) -> bool {
563- fn parse_version ( ver : & str ) -> Vec < u32 > {
564- // We ignore non-integer components of the version (e.g. "nightly").
565- ver. split ( |c| c == '.' || c == '-' ) . flat_map ( |s| s. parse ( ) ) . collect ( )
566- }
567-
568- if since. is_none ( ) || rustc. is_none ( ) {
569- // By default, a deprecation warning applies to
570- // the current version of the compiler.
571- true
572- } else {
573- let since: Vec < u32 > = parse_version ( since. unwrap ( ) ) ;
574- let rustc: Vec < u32 > = parse_version ( rustc. unwrap ( ) ) ;
575- // We simply treat invalid `since` attributes as relating to a previous
576- // Rust version, thus always displaying the warning.
577- if since. len ( ) != 3 {
578- return true ;
579- }
580- since <= rustc
581- }
582- }
583-
584586 // If the deprecation is scheduled for a future Rust
585587 // version, then we should display no warning message.
586588 let deprecated_in_future_version = if let Some ( sym) = depr_entry. attr . since {
587589 let since = sym. as_str ( ) ;
588- !deprecation_in_effect ( Some ( since. as_ref ( ) ) , option_env ! ( "CFG_RELEASE" ) )
590+ !deprecation_in_effect ( since. as_ref ( ) )
589591 } else {
590592 false
591593 } ;
0 commit comments