@@ -9,11 +9,12 @@ use rustc_attr::{
99use rustc_data_structures:: fx:: { FxHashMap , FxHashSet , FxIndexMap } ;
1010use rustc_hir as hir;
1111use rustc_hir:: def:: { DefKind , Res } ;
12- use rustc_hir:: def_id:: { LocalDefId , LocalModDefId , CRATE_DEF_ID } ;
12+ use rustc_hir:: def_id:: { LocalDefId , LocalModDefId , CRATE_DEF_ID , LOCAL_CRATE } ;
1313use rustc_hir:: hir_id:: CRATE_HIR_ID ;
1414use rustc_hir:: intravisit:: { self , Visitor } ;
1515use rustc_hir:: { FieldDef , Item , ItemKind , TraitRef , Ty , TyKind , Variant } ;
1616use rustc_middle:: hir:: nested_filter;
17+ use rustc_middle:: middle:: lib_features:: { FeatureStability , LibFeatures } ;
1718use rustc_middle:: middle:: privacy:: EffectiveVisibilities ;
1819use rustc_middle:: middle:: stability:: { AllowUnstable , DeprecationEntry , Index } ;
1920use rustc_middle:: query:: Providers ;
@@ -978,29 +979,27 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) {
978979 tcx : TyCtxt < ' tcx > ,
979980 remaining_lib_features : & mut FxIndexMap < & Symbol , Span > ,
980981 remaining_implications : & mut FxHashMap < Symbol , Symbol > ,
981- defined_features : & [ ( Symbol , Option < Symbol > ) ] ,
982+ defined_features : & LibFeatures ,
982983 all_implications : & FxHashMap < Symbol , Symbol > ,
983984 ) {
984- for ( feature, since) in defined_features {
985- if let Some ( since) = since
985+ for ( feature, since) in defined_features. to_vec ( ) {
986+ if let FeatureStability :: AcceptedSince ( since) = since
986987 && let Some ( span) = remaining_lib_features. get ( & feature)
987988 {
988989 // Warn if the user has enabled an already-stable lib feature.
989990 if let Some ( implies) = all_implications. get ( & feature) {
990- unnecessary_partially_stable_feature_lint (
991- tcx, * span, * feature, * implies, * since,
992- ) ;
991+ unnecessary_partially_stable_feature_lint ( tcx, * span, feature, * implies, since) ;
993992 } else {
994- unnecessary_stable_feature_lint ( tcx, * span, * feature, * since) ;
993+ unnecessary_stable_feature_lint ( tcx, * span, feature, since) ;
995994 }
996995 }
997- remaining_lib_features. remove ( feature) ;
996+ remaining_lib_features. remove ( & feature) ;
998997
999998 // `feature` is the feature doing the implying, but `implied_by` is the feature with
1000999 // the attribute that establishes this relationship. `implied_by` is guaranteed to be a
10011000 // feature defined in the local crate because `remaining_implications` is only the
10021001 // implications from this crate.
1003- remaining_implications. remove ( feature) ;
1002+ remaining_implications. remove ( & feature) ;
10041003
10051004 if remaining_lib_features. is_empty ( ) && remaining_implications. is_empty ( ) {
10061005 break ;
@@ -1009,12 +1008,11 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) {
10091008 }
10101009
10111010 // All local crate implications need to have the feature that implies it confirmed to exist.
1012- let mut remaining_implications =
1013- tcx. stability_implications ( rustc_hir:: def_id:: LOCAL_CRATE ) . clone ( ) ;
1011+ let mut remaining_implications = tcx. stability_implications ( LOCAL_CRATE ) . clone ( ) ;
10141012
10151013 // We always collect the lib features declared in the current crate, even if there are
10161014 // no unknown features, because the collection also does feature attribute validation.
1017- let local_defined_features = tcx. lib_features ( ( ) ) . to_vec ( ) ;
1015+ let local_defined_features = tcx. lib_features ( LOCAL_CRATE ) ;
10181016 if !remaining_lib_features. is_empty ( ) || !remaining_implications. is_empty ( ) {
10191017 // Loading the implications of all crates is unavoidable to be able to emit the partial
10201018 // stabilization diagnostic, but it can be avoided when there are no
@@ -1028,7 +1026,7 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) {
10281026 tcx,
10291027 & mut remaining_lib_features,
10301028 & mut remaining_implications,
1031- local_defined_features. as_slice ( ) ,
1029+ local_defined_features,
10321030 & all_implications,
10331031 ) ;
10341032
@@ -1040,7 +1038,7 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) {
10401038 tcx,
10411039 & mut remaining_lib_features,
10421040 & mut remaining_implications,
1043- tcx. defined_lib_features ( cnum) . to_vec ( ) . as_slice ( ) ,
1041+ tcx. lib_features ( cnum) ,
10441042 & all_implications,
10451043 ) ;
10461044 }
@@ -1051,13 +1049,12 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) {
10511049 }
10521050
10531051 for ( implied_by, feature) in remaining_implications {
1054- let local_defined_features = tcx. lib_features ( ( ) ) ;
1055- let span = * local_defined_features
1056- . stable
1052+ let local_defined_features = tcx. lib_features ( LOCAL_CRATE ) ;
1053+ let span = local_defined_features
1054+ . stability
10571055 . get ( & feature)
1058- . map ( |( _, span) | span)
1059- . or_else ( || local_defined_features. unstable . get ( & feature) )
1060- . expect ( "feature that implied another does not exist" ) ;
1056+ . expect ( "feature that implied another does not exist" )
1057+ . 1 ;
10611058 tcx. sess . emit_err ( errors:: ImpliedFeatureNotExist { span, feature, implied_by } ) ;
10621059 }
10631060
0 commit comments