@@ -559,9 +559,41 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
559
559
// Deprecated attributes apply in-crate and cross-crate.
560
560
if let Some ( id) = id {
561
561
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
+
584
+ // If the deprecation is scheduled for a future Rust
585
+ // version, then we should display no warning message.
586
+ let deprecated_in_future_version = if let Some ( sym) = depr_entry. attr . since {
587
+ let since = sym. as_str ( ) ;
588
+ !deprecation_in_effect ( Some ( since. as_ref ( ) ) , option_env ! ( "CFG_RELEASE" ) )
589
+ } else {
590
+ false
591
+ } ;
592
+
562
593
let parent_def_id = self . hir . local_def_id ( self . hir . get_parent ( id) ) ;
563
- let skip = self . lookup_deprecation_entry ( parent_def_id)
564
- . map_or ( false , |parent_depr| parent_depr. same_origin ( & depr_entry) ) ;
594
+ let skip = deprecated_in_future_version ||
595
+ self . lookup_deprecation_entry ( parent_def_id)
596
+ . map_or ( false , |parent_depr| parent_depr. same_origin ( & depr_entry) ) ;
565
597
if !skip {
566
598
lint_deprecated ( def_id, id, depr_entry. attr . note ) ;
567
599
}
0 commit comments