Skip to content

Commit cd1a08a

Browse files
committed
Revert "passes: check implied feature exists"
This reverts commit e587299.
1 parent 7dfdd64 commit cd1a08a

File tree

5 files changed

+30
-60
lines changed

5 files changed

+30
-60
lines changed

compiler/rustc_middle/src/middle/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@ pub mod dependency_format;
33
pub mod exported_symbols;
44
pub mod lang_items;
55
pub mod lib_features {
6-
use rustc_data_structures::fx::FxHashMap;
7-
use rustc_span::{symbol::Symbol, Span};
6+
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
7+
use rustc_span::symbol::Symbol;
88

99
#[derive(HashStable, Debug)]
1010
pub struct LibFeatures {
11-
/// A map from feature to stabilisation version.
12-
pub stable: FxHashMap<Symbol, (Symbol, Span)>,
13-
pub unstable: FxHashMap<Symbol, Span>,
11+
// A map from feature to stabilisation version.
12+
pub stable: FxHashMap<Symbol, Symbol>,
13+
pub unstable: FxHashSet<Symbol>,
1414
}
1515

1616
impl LibFeatures {
1717
pub fn to_vec(&self) -> Vec<(Symbol, Option<Symbol>)> {
1818
let mut all_features: Vec<_> = self
1919
.stable
2020
.iter()
21-
.map(|(f, (s, _))| (*f, Some(*s)))
22-
.chain(self.unstable.iter().map(|(f, _)| (*f, None)))
21+
.map(|(f, s)| (*f, Some(*s)))
22+
.chain(self.unstable.iter().map(|f| (*f, None)))
2323
.collect();
2424
all_features.sort_unstable_by(|a, b| a.0.as_str().partial_cmp(b.0.as_str()).unwrap());
2525
all_features

compiler/rustc_passes/src/lib_features.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ impl<'tcx> LibFeatureCollector<'tcx> {
7171

7272
fn collect_feature(&mut self, feature: Symbol, since: Option<Symbol>, span: Span) {
7373
let already_in_stable = self.lib_features.stable.contains_key(&feature);
74-
let already_in_unstable = self.lib_features.unstable.contains_key(&feature);
74+
let already_in_unstable = self.lib_features.unstable.contains(&feature);
7575

7676
match (since, already_in_stable, already_in_unstable) {
7777
(Some(since), _, false) => {
78-
if let Some((prev_since, _)) = self.lib_features.stable.get(&feature) {
78+
if let Some(prev_since) = self.lib_features.stable.get(&feature) {
7979
if *prev_since != since {
8080
self.span_feature_error(
8181
span,
@@ -89,10 +89,10 @@ impl<'tcx> LibFeatureCollector<'tcx> {
8989
}
9090
}
9191

92-
self.lib_features.stable.insert(feature, (since, span));
92+
self.lib_features.stable.insert(feature, since);
9393
}
9494
(None, false, _) => {
95-
self.lib_features.unstable.insert(feature, span);
95+
self.lib_features.unstable.insert(feature);
9696
}
9797
(Some(_), _, true) | (None, true, _) => {
9898
self.span_feature_error(

compiler/rustc_passes/src/stability.rs

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
44
use attr::StabilityLevel;
55
use rustc_attr::{self as attr, ConstStability, Stability, Unstable, UnstableReason};
6-
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
6+
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
77
use rustc_errors::{struct_span_err, Applicability};
88
use rustc_hir as hir;
99
use rustc_hir::def::{DefKind, Res};
@@ -949,52 +949,40 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) {
949949
remaining_lib_features.remove(&sym::libc);
950950
remaining_lib_features.remove(&sym::test);
951951

952-
// We always collect the lib features declared in the current crate, even if there are
953-
// no unknown features, because the collection also does feature attribute validation.
954-
let local_defined_features = tcx.lib_features(());
955-
let mut all_lib_features: FxHashMap<_, _> =
956-
local_defined_features.to_vec().iter().map(|el| *el).collect();
957952
let mut implications = tcx.stability_implications(rustc_hir::def_id::LOCAL_CRATE).clone();
958953
for &cnum in tcx.crates(()) {
959954
implications.extend(tcx.stability_implications(cnum));
960-
all_lib_features.extend(tcx.defined_lib_features(cnum).iter().map(|el| *el));
961-
}
962-
963-
// Check that every feature referenced by an `implied_by` exists (for features defined in the
964-
// local crate).
965-
for (implied_by, feature) in tcx.stability_implications(rustc_hir::def_id::LOCAL_CRATE) {
966-
// Only `implied_by` needs to be checked, `feature` is guaranteed to exist.
967-
if !all_lib_features.contains_key(implied_by) {
968-
let span = local_defined_features
969-
.stable
970-
.get(feature)
971-
.map(|(_, span)| span)
972-
.or_else(|| local_defined_features.unstable.get(feature))
973-
.expect("feature that implied another does not exist");
974-
tcx.sess
975-
.struct_span_err(
976-
*span,
977-
format!("feature `{implied_by}` implying `{feature}` does not exist"),
978-
)
979-
.emit();
980-
}
981955
}
982956

983-
if !remaining_lib_features.is_empty() {
984-
for (feature, since) in all_lib_features.iter() {
957+
let check_features = |remaining_lib_features: &mut FxIndexMap<_, _>, defined_features: &[_]| {
958+
for &(feature, since) in defined_features {
985959
if let Some(since) = since && let Some(span) = remaining_lib_features.get(&feature) {
986960
// Warn if the user has enabled an already-stable lib feature.
987961
if let Some(implies) = implications.get(&feature) {
988-
unnecessary_partially_stable_feature_lint(tcx, *span, *feature, *implies, *since);
962+
unnecessary_partially_stable_feature_lint(tcx, *span, feature, *implies, since);
989963
} else {
990-
unnecessary_stable_feature_lint(tcx, *span, *feature, *since);
964+
unnecessary_stable_feature_lint(tcx, *span, feature, since);
991965
}
992966
}
993967
remaining_lib_features.remove(&feature);
994968
if remaining_lib_features.is_empty() {
995969
break;
996970
}
997971
}
972+
};
973+
974+
// We always collect the lib features declared in the current crate, even if there are
975+
// no unknown features, because the collection also does feature attribute validation.
976+
let local_defined_features = tcx.lib_features(()).to_vec();
977+
if !remaining_lib_features.is_empty() {
978+
check_features(&mut remaining_lib_features, &local_defined_features);
979+
980+
for &cnum in tcx.crates(()) {
981+
if remaining_lib_features.is_empty() {
982+
break;
983+
}
984+
check_features(&mut remaining_lib_features, tcx.defined_lib_features(cnum));
985+
}
998986
}
999987

1000988
for (feature, span) in remaining_lib_features {

src/test/ui/stability-attribute/stability-attribute-implies-missing.rs

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/test/ui/stability-attribute/stability-attribute-implies-missing.stderr

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)