@@ -9,11 +9,12 @@ use rustc_attr::{
9
9
use rustc_data_structures:: fx:: { FxHashMap , FxHashSet , FxIndexMap } ;
10
10
use rustc_hir as hir;
11
11
use 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 } ;
13
13
use rustc_hir:: hir_id:: CRATE_HIR_ID ;
14
14
use rustc_hir:: intravisit:: { self , Visitor } ;
15
15
use rustc_hir:: { FieldDef , Item , ItemKind , TraitRef , Ty , TyKind , Variant } ;
16
16
use rustc_middle:: hir:: nested_filter;
17
+ use rustc_middle:: middle:: lib_features:: { FeatureStability , LibFeatures } ;
17
18
use rustc_middle:: middle:: privacy:: EffectiveVisibilities ;
18
19
use rustc_middle:: middle:: stability:: { AllowUnstable , DeprecationEntry , Index } ;
19
20
use rustc_middle:: query:: Providers ;
@@ -978,29 +979,27 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) {
978
979
tcx : TyCtxt < ' tcx > ,
979
980
remaining_lib_features : & mut FxIndexMap < & Symbol , Span > ,
980
981
remaining_implications : & mut FxHashMap < Symbol , Symbol > ,
981
- defined_features : & [ ( Symbol , Option < Symbol > ) ] ,
982
+ defined_features : & LibFeatures ,
982
983
all_implications : & FxHashMap < Symbol , Symbol > ,
983
984
) {
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
986
987
&& let Some ( span) = remaining_lib_features. get ( & feature)
987
988
{
988
989
// Warn if the user has enabled an already-stable lib feature.
989
990
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) ;
993
992
} else {
994
- unnecessary_stable_feature_lint ( tcx, * span, * feature, * since) ;
993
+ unnecessary_stable_feature_lint ( tcx, * span, feature, since) ;
995
994
}
996
995
}
997
- remaining_lib_features. remove ( feature) ;
996
+ remaining_lib_features. remove ( & feature) ;
998
997
999
998
// `feature` is the feature doing the implying, but `implied_by` is the feature with
1000
999
// the attribute that establishes this relationship. `implied_by` is guaranteed to be a
1001
1000
// feature defined in the local crate because `remaining_implications` is only the
1002
1001
// implications from this crate.
1003
- remaining_implications. remove ( feature) ;
1002
+ remaining_implications. remove ( & feature) ;
1004
1003
1005
1004
if remaining_lib_features. is_empty ( ) && remaining_implications. is_empty ( ) {
1006
1005
break ;
@@ -1009,12 +1008,11 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) {
1009
1008
}
1010
1009
1011
1010
// 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 ( ) ;
1014
1012
1015
1013
// We always collect the lib features declared in the current crate, even if there are
1016
1014
// 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 ) ;
1018
1016
if !remaining_lib_features. is_empty ( ) || !remaining_implications. is_empty ( ) {
1019
1017
// Loading the implications of all crates is unavoidable to be able to emit the partial
1020
1018
// stabilization diagnostic, but it can be avoided when there are no
@@ -1028,7 +1026,7 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) {
1028
1026
tcx,
1029
1027
& mut remaining_lib_features,
1030
1028
& mut remaining_implications,
1031
- local_defined_features. as_slice ( ) ,
1029
+ local_defined_features,
1032
1030
& all_implications,
1033
1031
) ;
1034
1032
@@ -1040,7 +1038,7 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) {
1040
1038
tcx,
1041
1039
& mut remaining_lib_features,
1042
1040
& mut remaining_implications,
1043
- tcx. defined_lib_features ( cnum) . to_vec ( ) . as_slice ( ) ,
1041
+ tcx. lib_features ( cnum) ,
1044
1042
& all_implications,
1045
1043
) ;
1046
1044
}
@@ -1051,13 +1049,12 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) {
1051
1049
}
1052
1050
1053
1051
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
1057
1055
. 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 ;
1061
1058
tcx. sess . emit_err ( errors:: ImpliedFeatureNotExist { span, feature, implied_by } ) ;
1062
1059
}
1063
1060
0 commit comments