13
13
14
14
pub use self :: StabilityLevel :: * ;
15
15
16
- use lint;
16
+ use lint:: { self , Lint } ;
17
17
use hir:: { self , Item , Generics , StructField , Variant , HirId } ;
18
18
use hir:: def:: Def ;
19
19
use hir:: def_id:: { CrateNum , CRATE_DEF_INDEX , DefId , LOCAL_CRATE } ;
@@ -562,18 +562,20 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
562
562
return EvalResult :: Allow ;
563
563
}
564
564
565
- let lint_deprecated = |def_id : DefId , id : NodeId , note : Option < Symbol > | {
566
- let path = self . item_path_str ( def_id) ;
567
-
565
+ let lint_deprecated = |def_id : DefId ,
566
+ id : NodeId ,
567
+ note : Option < Symbol > ,
568
+ message : & str ,
569
+ lint : & ' static Lint | {
568
570
let msg = if let Some ( note) = note {
569
- format ! ( "use of deprecated item '{}' : {}" , path , note)
571
+ format ! ( "{} : {}" , message , note)
570
572
} else {
571
- format ! ( "use of deprecated item '{}' " , path )
573
+ format ! ( "{} " , message )
572
574
} ;
573
575
574
- self . lint_node ( lint:: builtin :: DEPRECATED , id, span, & msg) ;
576
+ self . lint_node ( lint, id, span, & msg) ;
575
577
if id == ast:: DUMMY_NODE_ID {
576
- span_bug ! ( span, "emitted a deprecated lint with dummy node id: {:?}" , def_id) ;
578
+ span_bug ! ( span, "emitted a {} lint with dummy node id: {:?}" , lint . name , def_id) ;
577
579
}
578
580
} ;
579
581
@@ -584,17 +586,39 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
584
586
// version, then we should display no warning message.
585
587
let deprecated_in_future_version = if let Some ( sym) = depr_entry. attr . since {
586
588
let since = sym. as_str ( ) ;
587
- !deprecation_in_effect ( & since)
589
+ if !deprecation_in_effect ( & since) {
590
+ Some ( since)
591
+ } else {
592
+ None
593
+ }
588
594
} else {
589
- false
595
+ None
590
596
} ;
591
597
592
598
let parent_def_id = self . hir ( ) . local_def_id ( self . hir ( ) . get_parent ( id) ) ;
593
- let skip = deprecated_in_future_version ||
594
- self . lookup_deprecation_entry ( parent_def_id)
599
+ let skip = self . lookup_deprecation_entry ( parent_def_id)
595
600
. map_or ( false , |parent_depr| parent_depr. same_origin ( & depr_entry) ) ;
596
- if !skip {
597
- lint_deprecated ( def_id, id, depr_entry. attr . note ) ;
601
+
602
+ if let Some ( since) = deprecated_in_future_version {
603
+ let path = self . item_path_str ( def_id) ;
604
+ let message = format ! ( "use of item '{}' \
605
+ that will be deprecated in future version {}",
606
+ path,
607
+ since) ;
608
+
609
+ lint_deprecated ( def_id,
610
+ id,
611
+ depr_entry. attr . note ,
612
+ & message,
613
+ lint:: builtin:: DEPRECATED_IN_FUTURE ) ;
614
+ } else if !skip {
615
+ let path = self . item_path_str ( def_id) ;
616
+ let message = format ! ( "use of deprecated item '{}'" , path) ;
617
+ lint_deprecated ( def_id,
618
+ id,
619
+ depr_entry. attr . note ,
620
+ & message,
621
+ lint:: builtin:: DEPRECATED ) ;
598
622
}
599
623
} ;
600
624
}
@@ -614,8 +638,24 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
614
638
if let Some ( & Stability { rustc_depr : Some ( attr:: RustcDeprecation { reason, since } ) , ..} )
615
639
= stability {
616
640
if let Some ( id) = id {
641
+ let path = self . item_path_str ( def_id) ;
617
642
if deprecation_in_effect ( & since. as_str ( ) ) {
618
- lint_deprecated ( def_id, id, Some ( reason) ) ;
643
+ let message = format ! ( "use of deprecated item '{}'" , path) ;
644
+ lint_deprecated ( def_id,
645
+ id,
646
+ Some ( reason) ,
647
+ & message,
648
+ lint:: builtin:: DEPRECATED ) ;
649
+ } else {
650
+ let message = format ! ( "use of item '{}' \
651
+ that will be deprecated in future version {}",
652
+ path,
653
+ since) ;
654
+ lint_deprecated ( def_id,
655
+ id,
656
+ Some ( reason) ,
657
+ & message,
658
+ lint:: builtin:: DEPRECATED_IN_FUTURE ) ;
619
659
}
620
660
}
621
661
}
0 commit comments