From cd1a08ad7175417bb53137559411672f620a9758 Mon Sep 17 00:00:00 2001 From: David Wood Date: Fri, 29 Jul 2022 13:46:01 +0100 Subject: [PATCH 1/6] Revert "passes: check implied feature exists" This reverts commit e5872990d13abb088397e23b226439b1b4926b91. --- compiler/rustc_middle/src/middle/mod.rs | 14 +++--- compiler/rustc_passes/src/lib_features.rs | 8 +-- compiler/rustc_passes/src/stability.rs | 50 +++++++------------ .../stability-attribute-implies-missing.rs | 10 ---- ...stability-attribute-implies-missing.stderr | 8 --- 5 files changed, 30 insertions(+), 60 deletions(-) delete mode 100644 src/test/ui/stability-attribute/stability-attribute-implies-missing.rs delete mode 100644 src/test/ui/stability-attribute/stability-attribute-implies-missing.stderr diff --git a/compiler/rustc_middle/src/middle/mod.rs b/compiler/rustc_middle/src/middle/mod.rs index 8dc68b1f5a820..fc35cafcc77a1 100644 --- a/compiler/rustc_middle/src/middle/mod.rs +++ b/compiler/rustc_middle/src/middle/mod.rs @@ -3,14 +3,14 @@ pub mod dependency_format; pub mod exported_symbols; pub mod lang_items; pub mod lib_features { - use rustc_data_structures::fx::FxHashMap; - use rustc_span::{symbol::Symbol, Span}; + use rustc_data_structures::fx::{FxHashMap, FxHashSet}; + use rustc_span::symbol::Symbol; #[derive(HashStable, Debug)] pub struct LibFeatures { - /// A map from feature to stabilisation version. - pub stable: FxHashMap, - pub unstable: FxHashMap, + // A map from feature to stabilisation version. + pub stable: FxHashMap, + pub unstable: FxHashSet, } impl LibFeatures { @@ -18,8 +18,8 @@ pub mod lib_features { let mut all_features: Vec<_> = self .stable .iter() - .map(|(f, (s, _))| (*f, Some(*s))) - .chain(self.unstable.iter().map(|(f, _)| (*f, None))) + .map(|(f, s)| (*f, Some(*s))) + .chain(self.unstable.iter().map(|f| (*f, None))) .collect(); all_features.sort_unstable_by(|a, b| a.0.as_str().partial_cmp(b.0.as_str()).unwrap()); all_features diff --git a/compiler/rustc_passes/src/lib_features.rs b/compiler/rustc_passes/src/lib_features.rs index e05994f13e4d9..97ae8e6f3259c 100644 --- a/compiler/rustc_passes/src/lib_features.rs +++ b/compiler/rustc_passes/src/lib_features.rs @@ -71,11 +71,11 @@ impl<'tcx> LibFeatureCollector<'tcx> { fn collect_feature(&mut self, feature: Symbol, since: Option, span: Span) { let already_in_stable = self.lib_features.stable.contains_key(&feature); - let already_in_unstable = self.lib_features.unstable.contains_key(&feature); + let already_in_unstable = self.lib_features.unstable.contains(&feature); match (since, already_in_stable, already_in_unstable) { (Some(since), _, false) => { - if let Some((prev_since, _)) = self.lib_features.stable.get(&feature) { + if let Some(prev_since) = self.lib_features.stable.get(&feature) { if *prev_since != since { self.span_feature_error( span, @@ -89,10 +89,10 @@ impl<'tcx> LibFeatureCollector<'tcx> { } } - self.lib_features.stable.insert(feature, (since, span)); + self.lib_features.stable.insert(feature, since); } (None, false, _) => { - self.lib_features.unstable.insert(feature, span); + self.lib_features.unstable.insert(feature); } (Some(_), _, true) | (None, true, _) => { self.span_feature_error( diff --git a/compiler/rustc_passes/src/stability.rs b/compiler/rustc_passes/src/stability.rs index ca6a2ac3db34c..4c2dcf3c086e6 100644 --- a/compiler/rustc_passes/src/stability.rs +++ b/compiler/rustc_passes/src/stability.rs @@ -3,7 +3,7 @@ use attr::StabilityLevel; use rustc_attr::{self as attr, ConstStability, Stability, Unstable, UnstableReason}; -use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap}; +use rustc_data_structures::fx::{FxHashSet, FxIndexMap}; use rustc_errors::{struct_span_err, Applicability}; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; @@ -949,45 +949,19 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) { remaining_lib_features.remove(&sym::libc); remaining_lib_features.remove(&sym::test); - // We always collect the lib features declared in the current crate, even if there are - // no unknown features, because the collection also does feature attribute validation. - let local_defined_features = tcx.lib_features(()); - let mut all_lib_features: FxHashMap<_, _> = - local_defined_features.to_vec().iter().map(|el| *el).collect(); let mut implications = tcx.stability_implications(rustc_hir::def_id::LOCAL_CRATE).clone(); for &cnum in tcx.crates(()) { implications.extend(tcx.stability_implications(cnum)); - all_lib_features.extend(tcx.defined_lib_features(cnum).iter().map(|el| *el)); - } - - // Check that every feature referenced by an `implied_by` exists (for features defined in the - // local crate). - for (implied_by, feature) in tcx.stability_implications(rustc_hir::def_id::LOCAL_CRATE) { - // Only `implied_by` needs to be checked, `feature` is guaranteed to exist. - if !all_lib_features.contains_key(implied_by) { - let span = local_defined_features - .stable - .get(feature) - .map(|(_, span)| span) - .or_else(|| local_defined_features.unstable.get(feature)) - .expect("feature that implied another does not exist"); - tcx.sess - .struct_span_err( - *span, - format!("feature `{implied_by}` implying `{feature}` does not exist"), - ) - .emit(); - } } - if !remaining_lib_features.is_empty() { - for (feature, since) in all_lib_features.iter() { + let check_features = |remaining_lib_features: &mut FxIndexMap<_, _>, defined_features: &[_]| { + for &(feature, since) in defined_features { if let Some(since) = since && let Some(span) = remaining_lib_features.get(&feature) { // Warn if the user has enabled an already-stable lib feature. if let Some(implies) = implications.get(&feature) { - unnecessary_partially_stable_feature_lint(tcx, *span, *feature, *implies, *since); + unnecessary_partially_stable_feature_lint(tcx, *span, feature, *implies, since); } else { - unnecessary_stable_feature_lint(tcx, *span, *feature, *since); + unnecessary_stable_feature_lint(tcx, *span, feature, since); } } remaining_lib_features.remove(&feature); @@ -995,6 +969,20 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) { break; } } + }; + + // We always collect the lib features declared in the current crate, even if there are + // no unknown features, because the collection also does feature attribute validation. + let local_defined_features = tcx.lib_features(()).to_vec(); + if !remaining_lib_features.is_empty() { + check_features(&mut remaining_lib_features, &local_defined_features); + + for &cnum in tcx.crates(()) { + if remaining_lib_features.is_empty() { + break; + } + check_features(&mut remaining_lib_features, tcx.defined_lib_features(cnum)); + } } for (feature, span) in remaining_lib_features { diff --git a/src/test/ui/stability-attribute/stability-attribute-implies-missing.rs b/src/test/ui/stability-attribute/stability-attribute-implies-missing.rs deleted file mode 100644 index 613878536721b..0000000000000 --- a/src/test/ui/stability-attribute/stability-attribute-implies-missing.rs +++ /dev/null @@ -1,10 +0,0 @@ -#![feature(staged_api)] -#![stable(feature = "stability_attribute_implies", since = "1.0.0")] - -// Tests that `implied_by = "bar"` results in an error being emitted if `bar` does not exist. - -#[unstable(feature = "foobar", issue = "1", implied_by = "bar")] -//~^ ERROR feature `bar` implying `foobar` does not exist -pub fn foobar() {} - -fn main() {} diff --git a/src/test/ui/stability-attribute/stability-attribute-implies-missing.stderr b/src/test/ui/stability-attribute/stability-attribute-implies-missing.stderr deleted file mode 100644 index ff1856f1763f9..0000000000000 --- a/src/test/ui/stability-attribute/stability-attribute-implies-missing.stderr +++ /dev/null @@ -1,8 +0,0 @@ -error: feature `bar` implying `foobar` does not exist - --> $DIR/stability-attribute-implies-missing.rs:6:1 - | -LL | #[unstable(feature = "foobar", issue = "1", implied_by = "bar")] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to previous error - From 3e6fa0c8a97cf060f36bb65e1ada768333784ef6 Mon Sep 17 00:00:00 2001 From: David Wood Date: Fri, 29 Jul 2022 13:47:04 +0100 Subject: [PATCH 2/6] Revert "passes: improved partial stabilization diagnostic" This reverts commit 6246d66c6da3064f658831c0ed8162df169a001e. --- compiler/rustc_metadata/src/rmeta/decoder.rs | 7 --- .../src/rmeta/decoder/cstore_impl.rs | 3 - compiler/rustc_metadata/src/rmeta/encoder.rs | 15 ----- compiler/rustc_metadata/src/rmeta/mod.rs | 1 - compiler/rustc_middle/src/middle/stability.rs | 13 ----- compiler/rustc_middle/src/query/mod.rs | 8 +-- compiler/rustc_passes/src/stability.rs | 58 +++---------------- ...tability-attribute-implies-using-stable.rs | 2 +- ...lity-attribute-implies-using-stable.stderr | 10 +--- ...bility-attribute-implies-using-unstable.rs | 2 +- ...ty-attribute-implies-using-unstable.stderr | 10 +--- 11 files changed, 14 insertions(+), 115 deletions(-) diff --git a/compiler/rustc_metadata/src/rmeta/decoder.rs b/compiler/rustc_metadata/src/rmeta/decoder.rs index 8fa703a776075..b43bc26b0d72e 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder.rs @@ -951,13 +951,6 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { tcx.arena.alloc_from_iter(self.root.lib_features.decode(self)) } - /// Iterates over the stability implications in the given crate (when a `#[unstable]` attribute - /// has an `implied_by` meta item, then the mapping from the implied feature to the actual - /// feature is a stability implication). - fn get_stability_implications(self, tcx: TyCtxt<'tcx>) -> &'tcx [(Symbol, Symbol)] { - tcx.arena.alloc_from_iter(self.root.stability_implications.decode(self)) - } - /// Iterates over the language items in the given crate. fn get_lang_items(self, tcx: TyCtxt<'tcx>) -> &'tcx [(DefId, usize)] { tcx.arena.alloc_from_iter( diff --git a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs index 6bf237b8ed5df..895cd5db49cb3 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs @@ -291,9 +291,6 @@ provide! { <'tcx> tcx, def_id, other, cdata, tcx.arena.alloc_slice(&result) } defined_lib_features => { cdata.get_lib_features(tcx) } - stability_implications => { - cdata.get_stability_implications(tcx).iter().copied().collect() - } is_intrinsic => { cdata.get_is_intrinsic(def_id.index) } defined_lang_items => { cdata.get_lang_items(tcx) } diagnostic_items => { cdata.get_diagnostic_items() } diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index 50d983754e89c..8e97300977723 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -538,11 +538,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { let lib_features = self.encode_lib_features(); let lib_feature_bytes = self.position() - i; - // Encode the stability implications. - i = self.position(); - let stability_implications = self.encode_stability_implications(); - let stability_implications_bytes = self.position() - i; - // Encode the language items. i = self.position(); let lang_items = self.encode_lang_items(); @@ -691,7 +686,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { crate_deps, dylib_dependency_formats, lib_features, - stability_implications, lang_items, diagnostic_items, lang_items_missing, @@ -716,7 +710,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { let computed_total_bytes = preamble_bytes + dep_bytes + lib_feature_bytes - + stability_implications_bytes + lang_item_bytes + diagnostic_item_bytes + native_lib_bytes @@ -768,7 +761,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { p("preamble", preamble_bytes); p("dep", dep_bytes); p("lib feature", lib_feature_bytes); - p("stability_implications", stability_implications_bytes); p("lang item", lang_item_bytes); p("diagnostic item", diagnostic_item_bytes); p("native lib", native_lib_bytes); @@ -1785,13 +1777,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { self.lazy_array(lib_features.to_vec()) } - fn encode_stability_implications(&mut self) -> LazyArray<(Symbol, Symbol)> { - empty_proc_macro!(self); - let tcx = self.tcx; - let implications = tcx.stability_implications(LOCAL_CRATE); - self.lazy_array(implications.iter().map(|(k, v)| (*k, *v))) - } - fn encode_diagnostic_items(&mut self) -> LazyArray<(Symbol, DefIndex)> { empty_proc_macro!(self); let tcx = self.tcx; diff --git a/compiler/rustc_metadata/src/rmeta/mod.rs b/compiler/rustc_metadata/src/rmeta/mod.rs index 0f291f9264777..af1c09f4ae87a 100644 --- a/compiler/rustc_metadata/src/rmeta/mod.rs +++ b/compiler/rustc_metadata/src/rmeta/mod.rs @@ -226,7 +226,6 @@ pub(crate) struct CrateRoot { crate_deps: LazyArray, dylib_dependency_formats: LazyArray>, lib_features: LazyArray<(Symbol, Option)>, - stability_implications: LazyArray<(Symbol, Symbol)>, lang_items: LazyArray<(DefIndex, usize)>, lang_items_missing: LazyArray, diagnostic_items: LazyArray<(Symbol, DefIndex)>, diff --git a/compiler/rustc_middle/src/middle/stability.rs b/compiler/rustc_middle/src/middle/stability.rs index 414912dd0f7d8..3544710a027bd 100644 --- a/compiler/rustc_middle/src/middle/stability.rs +++ b/compiler/rustc_middle/src/middle/stability.rs @@ -62,19 +62,6 @@ pub struct Index { pub stab_map: FxHashMap, pub const_stab_map: FxHashMap, pub depr_map: FxHashMap, - /// Mapping from feature name to feature name based on the `implied_by` field of `#[unstable]` - /// attributes. If a `#[unstable(feature = "implier", implied_by = "impliee")]` attribute - /// exists, then this map will have a `impliee -> implier` entry. - /// - /// This mapping is necessary unless both the `#[stable]` and `#[unstable]` attributes should - /// specify their implications (both `implies` and `implied_by`). If only one of the two - /// attributes do (as in the current implementation, `implied_by` in `#[unstable]`), then this - /// mapping is necessary for diagnostics. When a "unnecessary feature attribute" error is - /// reported, only the `#[stable]` attribute information is available, so the map is necessary - /// to know that the feature implies another feature. If it were reversed, and the `#[stable]` - /// attribute had an `implies` meta item, then a map would be necessary when avoiding a "use of - /// unstable feature" error for a feature that was implied. - pub implications: FxHashMap, } impl Index { diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index 466a0fc25f7d1..0581ef41f66c2 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -1634,15 +1634,11 @@ rustc_queries! { storage(ArenaCacheSelector<'tcx>) desc { "calculating the lib features map" } } - query defined_lib_features(_: CrateNum) -> &'tcx [(Symbol, Option)] { + query defined_lib_features(_: CrateNum) + -> &'tcx [(Symbol, Option)] { desc { "calculating the lib features defined in a crate" } separate_provide_extern } - query stability_implications(_: CrateNum) -> FxHashMap { - storage(ArenaCacheSelector<'tcx>) - desc { "calculating the implications between `#[unstable]` features defined in a crate" } - separate_provide_extern - } /// Whether the function is an intrinsic query is_intrinsic(def_id: DefId) -> bool { desc { |tcx| "is_intrinsic({})", tcx.def_path_str(def_id) } diff --git a/compiler/rustc_passes/src/stability.rs b/compiler/rustc_passes/src/stability.rs index 4c2dcf3c086e6..63e981071d0de 100644 --- a/compiler/rustc_passes/src/stability.rs +++ b/compiler/rustc_passes/src/stability.rs @@ -2,9 +2,9 @@ //! propagating default levels lexically from parent to children ast nodes. use attr::StabilityLevel; -use rustc_attr::{self as attr, ConstStability, Stability, Unstable, UnstableReason}; +use rustc_attr::{self as attr, ConstStability, Stability, UnstableReason}; use rustc_data_structures::fx::{FxHashSet, FxIndexMap}; -use rustc_errors::{struct_span_err, Applicability}; +use rustc_errors::struct_span_err; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID}; @@ -265,10 +265,6 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> { } } - if let Stability { level: Unstable { implied_by: Some(implied_by), .. }, feature } = stab { - self.index.implications.insert(implied_by, feature); - } - self.index.stab_map.insert(def_id, stab); stab }); @@ -614,7 +610,6 @@ fn stability_index(tcx: TyCtxt<'_>, (): ()) -> Index { stab_map: Default::default(), const_stab_map: Default::default(), depr_map: Default::default(), - implications: Default::default(), }; { @@ -670,7 +665,6 @@ pub(crate) fn provide(providers: &mut Providers) { *providers = Providers { check_mod_unstable_api_usage, stability_index, - stability_implications: |tcx, _| tcx.stability().implications.clone(), lookup_stability: |tcx, id| tcx.stability().local_stability(id.expect_local()), lookup_const_stability: |tcx, id| tcx.stability().local_const_stability(id.expect_local()), lookup_deprecation_entry: |tcx, id| { @@ -949,18 +943,11 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) { remaining_lib_features.remove(&sym::libc); remaining_lib_features.remove(&sym::test); - let mut implications = tcx.stability_implications(rustc_hir::def_id::LOCAL_CRATE).clone(); - for &cnum in tcx.crates(()) { - implications.extend(tcx.stability_implications(cnum)); - } - let check_features = |remaining_lib_features: &mut FxIndexMap<_, _>, defined_features: &[_]| { for &(feature, since) in defined_features { - if let Some(since) = since && let Some(span) = remaining_lib_features.get(&feature) { - // Warn if the user has enabled an already-stable lib feature. - if let Some(implies) = implications.get(&feature) { - unnecessary_partially_stable_feature_lint(tcx, *span, feature, *implies, since); - } else { + if let Some(since) = since { + if let Some(span) = remaining_lib_features.get(&feature) { + // Warn if the user has enabled an already-stable lib feature. unnecessary_stable_feature_lint(tcx, *span, feature, since); } } @@ -993,41 +980,12 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) { // don't lint about unused features. We should re-enable this one day! } -fn unnecessary_partially_stable_feature_lint( - tcx: TyCtxt<'_>, - span: Span, - feature: Symbol, - implies: Symbol, - since: Symbol, -) { - tcx.struct_span_lint_hir(lint::builtin::STABLE_FEATURES, hir::CRATE_HIR_ID, span, |lint| { - lint.build(&format!( - "the feature `{feature}` has been partially stabilized since {since} and is succeeded \ - by the feature `{implies}`" - )) - .span_suggestion( - span, - &format!( - "if you are using features which are still unstable, change to using `{implies}`" - ), - implies, - Applicability::MaybeIncorrect, - ) - .span_suggestion( - tcx.sess.source_map().span_extend_to_line(span), - "if you are using features which are now stable, remove this line", - "", - Applicability::MaybeIncorrect, - ) - .emit(); - }); -} - fn unnecessary_stable_feature_lint(tcx: TyCtxt<'_>, span: Span, feature: Symbol, since: Symbol) { tcx.struct_span_lint_hir(lint::builtin::STABLE_FEATURES, hir::CRATE_HIR_ID, span, |lint| { lint.build(&format!( - "the feature `{feature}` has been stable since {since} and no longer requires an \ - attribute to enable", + "the feature `{}` has been stable since {} and no longer requires \ + an attribute to enable", + feature, since )) .emit(); }); diff --git a/src/test/ui/stability-attribute/stability-attribute-implies-using-stable.rs b/src/test/ui/stability-attribute/stability-attribute-implies-using-stable.rs index 1a2d8e271de04..527639ec70b76 100644 --- a/src/test/ui/stability-attribute/stability-attribute-implies-using-stable.rs +++ b/src/test/ui/stability-attribute/stability-attribute-implies-using-stable.rs @@ -1,7 +1,7 @@ // aux-build:stability-attribute-implies.rs #![deny(stable_features)] #![feature(foo)] -//~^ ERROR the feature `foo` has been partially stabilized since 1.62.0 and is succeeded by the feature `foobar` +//~^ ERROR the feature `foo` has been stable since 1.62.0 and no longer requires an attribute to enable // Tests that the use of `implied_by` in the `#[unstable]` attribute results in a diagnostic // mentioning partial stabilization, and that given the implied unstable feature is unused (there diff --git a/src/test/ui/stability-attribute/stability-attribute-implies-using-stable.stderr b/src/test/ui/stability-attribute/stability-attribute-implies-using-stable.stderr index c9b3f07cc70b1..c8767e85a684a 100644 --- a/src/test/ui/stability-attribute/stability-attribute-implies-using-stable.stderr +++ b/src/test/ui/stability-attribute/stability-attribute-implies-using-stable.stderr @@ -1,4 +1,4 @@ -error: the feature `foo` has been partially stabilized since 1.62.0 and is succeeded by the feature `foobar` +error: the feature `foo` has been stable since 1.62.0 and no longer requires an attribute to enable --> $DIR/stability-attribute-implies-using-stable.rs:3:12 | LL | #![feature(foo)] @@ -9,14 +9,6 @@ note: the lint level is defined here | LL | #![deny(stable_features)] | ^^^^^^^^^^^^^^^ -help: if you are using features which are still unstable, change to using `foobar` - | -LL | #![feature(foobar)] - | ~~~~~~ -help: if you are using features which are now stable, remove this line - | -LL - #![feature(foo)] - | error: aborting due to previous error diff --git a/src/test/ui/stability-attribute/stability-attribute-implies-using-unstable.rs b/src/test/ui/stability-attribute/stability-attribute-implies-using-unstable.rs index 3c73c5abf3b54..d6ad4d3510e7e 100644 --- a/src/test/ui/stability-attribute/stability-attribute-implies-using-unstable.rs +++ b/src/test/ui/stability-attribute/stability-attribute-implies-using-unstable.rs @@ -1,7 +1,7 @@ // aux-build:stability-attribute-implies.rs #![deny(stable_features)] #![feature(foo)] -//~^ ERROR the feature `foo` has been partially stabilized since 1.62.0 and is succeeded by the feature `foobar` +//~^ ERROR the feature `foo` has been stable since 1.62.0 and no longer requires an attribute to enable // Tests that the use of `implied_by` in the `#[unstable]` attribute results in a diagnostic // mentioning partial stabilization and that given the implied unstable feature is used (there is a diff --git a/src/test/ui/stability-attribute/stability-attribute-implies-using-unstable.stderr b/src/test/ui/stability-attribute/stability-attribute-implies-using-unstable.stderr index 9a5c7ef5a4762..35cbac6035ceb 100644 --- a/src/test/ui/stability-attribute/stability-attribute-implies-using-unstable.stderr +++ b/src/test/ui/stability-attribute/stability-attribute-implies-using-unstable.stderr @@ -1,4 +1,4 @@ -error: the feature `foo` has been partially stabilized since 1.62.0 and is succeeded by the feature `foobar` +error: the feature `foo` has been stable since 1.62.0 and no longer requires an attribute to enable --> $DIR/stability-attribute-implies-using-unstable.rs:3:12 | LL | #![feature(foo)] @@ -9,14 +9,6 @@ note: the lint level is defined here | LL | #![deny(stable_features)] | ^^^^^^^^^^^^^^^ -help: if you are using features which are still unstable, change to using `foobar` - | -LL | #![feature(foobar)] - | ~~~~~~ -help: if you are using features which are now stable, remove this line - | -LL - #![feature(foo)] - | error: aborting due to previous error From 321f1f7734f5c37fa60103ab994280fc07196275 Mon Sep 17 00:00:00 2001 From: David Wood Date: Fri, 29 Jul 2022 13:47:06 +0100 Subject: [PATCH 3/6] Revert "span: add `span_extend_to_line` helper" This reverts commit 97edb9f336e98c0597210092e2e0ef0ee1576e24. --- compiler/rustc_span/src/source_map.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/compiler/rustc_span/src/source_map.rs b/compiler/rustc_span/src/source_map.rs index 28381157d50a9..1ec925a17924e 100644 --- a/compiler/rustc_span/src/source_map.rs +++ b/compiler/rustc_span/src/source_map.rs @@ -734,11 +734,6 @@ impl SourceMap { sp } - /// Extends the given `Span` to contain the entire line it is on. - pub fn span_extend_to_line(&self, sp: Span) -> Span { - self.span_extend_to_prev_char(self.span_extend_to_next_char(sp, '\n', true), '\n', true) - } - /// Given a `Span`, tries to get a shorter span ending before the first occurrence of `char` /// `c`. pub fn span_until_char(&self, sp: Span, c: char) -> Span { From 889080d0036c57c7a78834e4c249221194c36b5b Mon Sep 17 00:00:00 2001 From: David Wood Date: Fri, 29 Jul 2022 13:48:03 +0100 Subject: [PATCH 4/6] Revert "middle: add `implies_by` to `#[unstable]`" This reverts commit 224aec213d62aa11758c864c871c341b7e7e7681. --- compiler/rustc_attr/src/builtin.rs | 27 ------------------- compiler/rustc_middle/src/middle/stability.rs | 11 +------- compiler/rustc_passes/src/stability.rs | 1 - compiler/rustc_resolve/src/macros.rs | 11 ++------ compiler/rustc_span/src/symbol.rs | 1 - .../auxiliary/stability-attribute-implies.rs | 8 ------ .../stability-attribute-implies-no-feature.rs | 13 --------- ...bility-attribute-implies-no-feature.stderr | 21 --------------- ...tability-attribute-implies-using-stable.rs | 15 ----------- ...lity-attribute-implies-using-stable.stderr | 14 ---------- ...bility-attribute-implies-using-unstable.rs | 17 ------------ ...ty-attribute-implies-using-unstable.stderr | 14 ---------- 12 files changed, 3 insertions(+), 150 deletions(-) delete mode 100644 src/test/ui/stability-attribute/auxiliary/stability-attribute-implies.rs delete mode 100644 src/test/ui/stability-attribute/stability-attribute-implies-no-feature.rs delete mode 100644 src/test/ui/stability-attribute/stability-attribute-implies-no-feature.stderr delete mode 100644 src/test/ui/stability-attribute/stability-attribute-implies-using-stable.rs delete mode 100644 src/test/ui/stability-attribute/stability-attribute-implies-using-stable.stderr delete mode 100644 src/test/ui/stability-attribute/stability-attribute-implies-using-unstable.rs delete mode 100644 src/test/ui/stability-attribute/stability-attribute-implies-using-unstable.stderr diff --git a/compiler/rustc_attr/src/builtin.rs b/compiler/rustc_attr/src/builtin.rs index 10a9cfb626e63..b8ecba27a8540 100644 --- a/compiler/rustc_attr/src/builtin.rs +++ b/compiler/rustc_attr/src/builtin.rs @@ -142,26 +142,6 @@ pub enum StabilityLevel { /// Relevant `rust-lang/rust` issue. issue: Option, is_soft: bool, - /// If part of a feature is stabilized and a new feature is added for the remaining parts, - /// then the `implied_by` attribute is used to indicate which now-stable feature previously - /// contained a item. - /// - /// ```pseudo-Rust - /// #[unstable(feature = "foo", issue = "...")] - /// fn foo() {} - /// #[unstable(feature = "foo", issue = "...")] - /// fn foobar() {} - /// ``` - /// - /// ...becomes... - /// - /// ```pseudo-Rust - /// #[stable(feature = "foo", since = "1.XX.X")] - /// fn foo() {} - /// #[unstable(feature = "foobar", issue = "...", implied_by = "foo")] - /// fn foobar() {} - /// ``` - implied_by: Option, }, /// `#[stable]` Stable { @@ -302,7 +282,6 @@ where let mut issue = None; let mut issue_num = None; let mut is_soft = false; - let mut implied_by = None; for meta in metas { let Some(mi) = meta.meta_item() else { handle_errors( @@ -368,11 +347,6 @@ where } is_soft = true; } - sym::implied_by => { - if !get(mi, &mut implied_by) { - continue 'outer; - } - } _ => { handle_errors( &sess.parse_sess, @@ -401,7 +375,6 @@ where reason: UnstableReason::from_opt_reason(reason), issue: issue_num, is_soft, - implied_by, }; if sym::unstable == meta_name { stab = Some((Stability { level, feature }, attr.span)); diff --git a/compiler/rustc_middle/src/middle/stability.rs b/compiler/rustc_middle/src/middle/stability.rs index 3544710a027bd..e90de2f0cb93b 100644 --- a/compiler/rustc_middle/src/middle/stability.rs +++ b/compiler/rustc_middle/src/middle/stability.rs @@ -423,9 +423,7 @@ impl<'tcx> TyCtxt<'tcx> { match stability { Some(Stability { - level: attr::Unstable { reason, issue, is_soft, implied_by }, - feature, - .. + level: attr::Unstable { reason, issue, is_soft }, feature, .. }) => { if span.allows_unstable(feature) { debug!("stability: skipping span={:?} since it is internal", span); @@ -435,13 +433,6 @@ impl<'tcx> TyCtxt<'tcx> { return EvalResult::Allow; } - // If this item was previously part of a now-stabilized feature which is still - // active (i.e. the user hasn't removed the attribute for the stabilized feature - // yet) then allow use of this item. - if let Some(implied_by) = implied_by && self.features().active(implied_by) { - return EvalResult::Allow; - } - // When we're compiling the compiler itself we may pull in // crates from crates.io, but those crates may depend on other // crates also pulled in from crates.io. We want to ideally be diff --git a/compiler/rustc_passes/src/stability.rs b/compiler/rustc_passes/src/stability.rs index 63e981071d0de..796ae92346dbf 100644 --- a/compiler/rustc_passes/src/stability.rs +++ b/compiler/rustc_passes/src/stability.rs @@ -634,7 +634,6 @@ fn stability_index(tcx: TyCtxt<'_>, (): ()) -> Index { reason: UnstableReason::Default, issue: NonZeroU32::new(27812), is_soft: false, - implied_by: None, }, feature: sym::rustc_private, }; diff --git a/compiler/rustc_resolve/src/macros.rs b/compiler/rustc_resolve/src/macros.rs index 070fb9c721b40..ed72eb0a0e378 100644 --- a/compiler/rustc_resolve/src/macros.rs +++ b/compiler/rustc_resolve/src/macros.rs @@ -796,16 +796,9 @@ impl<'a> Resolver<'a> { ) { let span = path.span; if let Some(stability) = &ext.stability { - if let StabilityLevel::Unstable { reason, issue, is_soft, implied_by } = stability.level - { + if let StabilityLevel::Unstable { reason, issue, is_soft } = stability.level { let feature = stability.feature; - - let is_allowed = |feature| { - self.active_features.contains(&feature) || span.allows_unstable(feature) - }; - let allowed_by_implication = - implied_by.map(|feature| is_allowed(feature)).unwrap_or(false); - if !is_allowed(feature) && !allowed_by_implication { + if !self.active_features.contains(&feature) && !span.allows_unstable(feature) { let lint_buffer = &mut self.lint_buffer; let soft_handler = |lint, span, msg: &_| lint_buffer.buffer_lint(lint, node_id, span, msg); diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 060e7a7b90aee..85a1899cc60ca 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -800,7 +800,6 @@ symbols! { impl_lint_pass, impl_macros, impl_trait_in_bindings, - implied_by, import, import_shadowing, imported_main, diff --git a/src/test/ui/stability-attribute/auxiliary/stability-attribute-implies.rs b/src/test/ui/stability-attribute/auxiliary/stability-attribute-implies.rs deleted file mode 100644 index 468be1bc14450..0000000000000 --- a/src/test/ui/stability-attribute/auxiliary/stability-attribute-implies.rs +++ /dev/null @@ -1,8 +0,0 @@ -#![feature(staged_api)] -#![stable(feature = "stability_attribute_implies", since = "1.0.0")] - -#[stable(feature = "foo", since = "1.62.0")] -pub fn foo() {} - -#[unstable(feature = "foobar", issue = "1", implied_by = "foo")] -pub fn foobar() {} diff --git a/src/test/ui/stability-attribute/stability-attribute-implies-no-feature.rs b/src/test/ui/stability-attribute/stability-attribute-implies-no-feature.rs deleted file mode 100644 index 947f9f73eff11..0000000000000 --- a/src/test/ui/stability-attribute/stability-attribute-implies-no-feature.rs +++ /dev/null @@ -1,13 +0,0 @@ -// aux-build:stability-attribute-implies.rs - -// Tests that despite the `foobar` feature being implied by now-stable feature `foo`, if `foobar` -// isn't allowed in this crate then an error will be emitted. - -extern crate stability_attribute_implies; -use stability_attribute_implies::{foo, foobar}; -//~^ ERROR use of unstable library feature 'foobar' - -fn main() { - foo(); // no error - stable - foobar(); //~ ERROR use of unstable library feature 'foobar' -} diff --git a/src/test/ui/stability-attribute/stability-attribute-implies-no-feature.stderr b/src/test/ui/stability-attribute/stability-attribute-implies-no-feature.stderr deleted file mode 100644 index c2331f6766c4f..0000000000000 --- a/src/test/ui/stability-attribute/stability-attribute-implies-no-feature.stderr +++ /dev/null @@ -1,21 +0,0 @@ -error[E0658]: use of unstable library feature 'foobar' - --> $DIR/stability-attribute-implies-no-feature.rs:7:40 - | -LL | use stability_attribute_implies::{foo, foobar}; - | ^^^^^^ - | - = note: see issue #1 for more information - = help: add `#![feature(foobar)]` to the crate attributes to enable - -error[E0658]: use of unstable library feature 'foobar' - --> $DIR/stability-attribute-implies-no-feature.rs:12:5 - | -LL | foobar(); - | ^^^^^^ - | - = note: see issue #1 for more information - = help: add `#![feature(foobar)]` to the crate attributes to enable - -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/stability-attribute/stability-attribute-implies-using-stable.rs b/src/test/ui/stability-attribute/stability-attribute-implies-using-stable.rs deleted file mode 100644 index 527639ec70b76..0000000000000 --- a/src/test/ui/stability-attribute/stability-attribute-implies-using-stable.rs +++ /dev/null @@ -1,15 +0,0 @@ -// aux-build:stability-attribute-implies.rs -#![deny(stable_features)] -#![feature(foo)] -//~^ ERROR the feature `foo` has been stable since 1.62.0 and no longer requires an attribute to enable - -// Tests that the use of `implied_by` in the `#[unstable]` attribute results in a diagnostic -// mentioning partial stabilization, and that given the implied unstable feature is unused (there -// is no `foobar` call), that the compiler suggests removing the flag. - -extern crate stability_attribute_implies; -use stability_attribute_implies::foo; - -fn main() { - foo(); -} diff --git a/src/test/ui/stability-attribute/stability-attribute-implies-using-stable.stderr b/src/test/ui/stability-attribute/stability-attribute-implies-using-stable.stderr deleted file mode 100644 index c8767e85a684a..0000000000000 --- a/src/test/ui/stability-attribute/stability-attribute-implies-using-stable.stderr +++ /dev/null @@ -1,14 +0,0 @@ -error: the feature `foo` has been stable since 1.62.0 and no longer requires an attribute to enable - --> $DIR/stability-attribute-implies-using-stable.rs:3:12 - | -LL | #![feature(foo)] - | ^^^ - | -note: the lint level is defined here - --> $DIR/stability-attribute-implies-using-stable.rs:2:9 - | -LL | #![deny(stable_features)] - | ^^^^^^^^^^^^^^^ - -error: aborting due to previous error - diff --git a/src/test/ui/stability-attribute/stability-attribute-implies-using-unstable.rs b/src/test/ui/stability-attribute/stability-attribute-implies-using-unstable.rs deleted file mode 100644 index d6ad4d3510e7e..0000000000000 --- a/src/test/ui/stability-attribute/stability-attribute-implies-using-unstable.rs +++ /dev/null @@ -1,17 +0,0 @@ -// aux-build:stability-attribute-implies.rs -#![deny(stable_features)] -#![feature(foo)] -//~^ ERROR the feature `foo` has been stable since 1.62.0 and no longer requires an attribute to enable - -// Tests that the use of `implied_by` in the `#[unstable]` attribute results in a diagnostic -// mentioning partial stabilization and that given the implied unstable feature is used (there is a -// `foobar` call), that the compiler suggests changing to that feature and doesn't error about its -// use. - -extern crate stability_attribute_implies; -use stability_attribute_implies::{foo, foobar}; - -fn main() { - foo(); - foobar(); // no error! -} diff --git a/src/test/ui/stability-attribute/stability-attribute-implies-using-unstable.stderr b/src/test/ui/stability-attribute/stability-attribute-implies-using-unstable.stderr deleted file mode 100644 index 35cbac6035ceb..0000000000000 --- a/src/test/ui/stability-attribute/stability-attribute-implies-using-unstable.stderr +++ /dev/null @@ -1,14 +0,0 @@ -error: the feature `foo` has been stable since 1.62.0 and no longer requires an attribute to enable - --> $DIR/stability-attribute-implies-using-unstable.rs:3:12 - | -LL | #![feature(foo)] - | ^^^ - | -note: the lint level is defined here - --> $DIR/stability-attribute-implies-using-unstable.rs:2:9 - | -LL | #![deny(stable_features)] - | ^^^^^^^^^^^^^^^ - -error: aborting due to previous error - From 9cdef5a36275082c0c0a1ea868a9dee654950b88 Mon Sep 17 00:00:00 2001 From: David Wood Date: Fri, 29 Jul 2022 13:48:04 +0100 Subject: [PATCH 5/6] Revert "attr: fix expected meta-item for `#[stable]`" This reverts commit a1d5af24ece7d35d6f23a2782df5ffdaa132dd82. --- compiler/rustc_attr/src/builtin.rs | 2 +- .../ui/stability-attribute/stability-attribute-sanity-2.stderr | 2 +- .../ui/stability-attribute/stability-attribute-sanity.stderr | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_attr/src/builtin.rs b/compiler/rustc_attr/src/builtin.rs index b8ecba27a8540..2b99791548e60 100644 --- a/compiler/rustc_attr/src/builtin.rs +++ b/compiler/rustc_attr/src/builtin.rs @@ -434,7 +434,7 @@ where meta.span(), AttrError::UnknownMetaItem( pprust::path_to_string(&mi.path), - &["feature", "since"], + &["since", "note"], ), ); continue 'outer; diff --git a/src/test/ui/stability-attribute/stability-attribute-sanity-2.stderr b/src/test/ui/stability-attribute/stability-attribute-sanity-2.stderr index 8dbcc6c97efd5..bd7b88da1584d 100644 --- a/src/test/ui/stability-attribute/stability-attribute-sanity-2.stderr +++ b/src/test/ui/stability-attribute/stability-attribute-sanity-2.stderr @@ -8,7 +8,7 @@ error[E0541]: unknown meta item 'sinse' --> $DIR/stability-attribute-sanity-2.rs:10:25 | LL | #[stable(feature = "a", sinse = "1.0.0")] - | ^^^^^^^^^^^^^^^ expected one of `feature`, `since` + | ^^^^^^^^^^^^^^^ expected one of `since`, `note` error[E0545]: `issue` must be a non-zero numeric string or "none" --> $DIR/stability-attribute-sanity-2.rs:13:27 diff --git a/src/test/ui/stability-attribute/stability-attribute-sanity.stderr b/src/test/ui/stability-attribute/stability-attribute-sanity.stderr index 079230b2a3160..fcb1eefddbcef 100644 --- a/src/test/ui/stability-attribute/stability-attribute-sanity.stderr +++ b/src/test/ui/stability-attribute/stability-attribute-sanity.stderr @@ -14,7 +14,7 @@ error[E0541]: unknown meta item 'reason' --> $DIR/stability-attribute-sanity.rs:8:42 | LL | #[stable(feature = "a", since = "b", reason)] - | ^^^^^^ expected one of `feature`, `since` + | ^^^^^^ expected one of `since`, `note` error[E0539]: incorrect meta item --> $DIR/stability-attribute-sanity.rs:11:29 From 4078ee403956bdba10411b2c55cc85a58a8e7670 Mon Sep 17 00:00:00 2001 From: David Wood Date: Fri, 29 Jul 2022 13:49:03 +0100 Subject: [PATCH 6/6] Revert "attr/passes: comment -> doc comment" This reverts commit 6f0b8f1a4b8f126f4e762655f927e22bf971513e. --- compiler/rustc_attr/src/builtin.rs | 19 +++---------------- compiler/rustc_passes/src/lib_features.rs | 10 +++++----- compiler/rustc_passes/src/stability.rs | 16 ++++++++-------- 3 files changed, 16 insertions(+), 29 deletions(-) diff --git a/compiler/rustc_attr/src/builtin.rs b/compiler/rustc_attr/src/builtin.rs index 2b99791548e60..291dbef3b8bfc 100644 --- a/compiler/rustc_attr/src/builtin.rs +++ b/compiler/rustc_attr/src/builtin.rs @@ -135,22 +135,9 @@ impl ConstStability { #[derive(Encodable, Decodable, PartialEq, Copy, Clone, Debug, Eq, Hash)] #[derive(HashStable_Generic)] pub enum StabilityLevel { - /// `#[unstable]` - Unstable { - /// Reason for the current stability level. - reason: UnstableReason, - /// Relevant `rust-lang/rust` issue. - issue: Option, - is_soft: bool, - }, - /// `#[stable]` - Stable { - /// Rust release which stabilized this feature. - since: Symbol, - /// Is this item allowed to be referred to on stable, despite being contained in unstable - /// modules? - allowed_through_unstable_modules: bool, - }, + // Reason for the current stability level and the relevant rust-lang issue + Unstable { reason: UnstableReason, issue: Option, is_soft: bool }, + Stable { since: Symbol, allowed_through_unstable_modules: bool }, } impl StabilityLevel { diff --git a/compiler/rustc_passes/src/lib_features.rs b/compiler/rustc_passes/src/lib_features.rs index 97ae8e6f3259c..26bfa4737a752 100644 --- a/compiler/rustc_passes/src/lib_features.rs +++ b/compiler/rustc_passes/src/lib_features.rs @@ -1,8 +1,8 @@ -//! Detecting lib features (i.e., features that are not lang features). -//! -//! These are declared using stability attributes (e.g., `#[stable (..)]` and `#[unstable (..)]`), -//! but are not declared in one single location (unlike lang features), which means we need to -//! collect them instead. +// Detecting lib features (i.e., features that are not lang features). +// +// These are declared using stability attributes (e.g., `#[stable (..)]` +// and `#[unstable (..)]`), but are not declared in one single location +// (unlike lang features), which means we need to collect them instead. use rustc_ast::{Attribute, MetaItemKind}; use rustc_errors::struct_span_err; diff --git a/compiler/rustc_passes/src/stability.rs b/compiler/rustc_passes/src/stability.rs index 796ae92346dbf..feedd60f4df87 100644 --- a/compiler/rustc_passes/src/stability.rs +++ b/compiler/rustc_passes/src/stability.rs @@ -29,13 +29,13 @@ use std::num::NonZeroU32; #[derive(PartialEq)] enum AnnotationKind { - /// Annotation is required if not inherited from unstable parents. + // Annotation is required if not inherited from unstable parents Required, - /// Annotation is useless, reject it. + // Annotation is useless, reject it Prohibited, - /// Deprecation annotation is useless, reject it. (Stability attribute is still required.) + // Deprecation annotation is useless, reject it. (Stability attribute is still required.) DeprecationProhibited, - /// Annotation itself is useless, but it can be propagated to children. + // Annotation itself is useless, but it can be propagated to children Container, } @@ -83,7 +83,7 @@ impl InheritStability { } } -/// A private tree-walker for producing an `Index`. +// A private tree-walker for producing an Index. struct Annotator<'a, 'tcx> { tcx: TyCtxt<'tcx>, index: &'a mut Index, @@ -94,9 +94,9 @@ struct Annotator<'a, 'tcx> { } impl<'a, 'tcx> Annotator<'a, 'tcx> { - /// Determine the stability for a node based on its attributes and inherited stability. The - /// stability is recorded in the index and used as the parent. If the node is a function, - /// `fn_sig` is its signature. + // Determine the stability for a node based on its attributes and inherited + // stability. The stability is recorded in the index and used as the parent. + // If the node is a function, `fn_sig` is its signature fn annotate( &mut self, def_id: LocalDefId,