diff --git a/compiler/rustc_attr_data_structures/src/stability.rs b/compiler/rustc_attr_data_structures/src/stability.rs index c0ca08a60f8b3..218e771c745a8 100644 --- a/compiler/rustc_attr_data_structures/src/stability.rs +++ b/compiler/rustc_attr_data_structures/src/stability.rs @@ -132,6 +132,7 @@ pub enum StabilityLevel { /// fn foobar() {} /// ``` implied_by: Option, + old_name: Option, }, /// `#[stable]` Stable { diff --git a/compiler/rustc_attr_parsing/src/attributes/stability.rs b/compiler/rustc_attr_parsing/src/attributes/stability.rs index ce69a54513d2c..49c042532ff87 100644 --- a/compiler/rustc_attr_parsing/src/attributes/stability.rs +++ b/compiler/rustc_attr_parsing/src/attributes/stability.rs @@ -299,6 +299,7 @@ pub(crate) fn parse_unstability( let mut issue_num = None; let mut is_soft = false; let mut implied_by = None; + let mut old_name = None; for param in args.list()?.mixed() { let Some(param) = param.meta_item() else { cx.emit_err(session_diagnostics::UnsupportedLiteral { @@ -346,11 +347,12 @@ pub(crate) fn parse_unstability( Some(sym::implied_by) => { insert_value_into_option_or_error(cx, ¶m, &mut implied_by)? } + Some(sym::old_name) => insert_value_into_option_or_error(cx, ¶m, &mut old_name)?, _ => { cx.emit_err(session_diagnostics::UnknownMetaItem { span: param.span(), item: param.path().to_string(), - expected: &["feature", "reason", "issue", "soft", "implied_by"], + expected: &["feature", "reason", "issue", "soft", "implied_by", "old_name"], }); return None; } @@ -375,6 +377,7 @@ pub(crate) fn parse_unstability( issue: issue_num, is_soft, implied_by, + old_name, }; Some((feature, level)) } diff --git a/compiler/rustc_middle/src/middle/mod.rs b/compiler/rustc_middle/src/middle/mod.rs index 4587dcaddc487..6ca1e6207042a 100644 --- a/compiler/rustc_middle/src/middle/mod.rs +++ b/compiler/rustc_middle/src/middle/mod.rs @@ -12,7 +12,7 @@ pub mod lib_features { #[derive(HashStable, TyEncodable, TyDecodable)] pub enum FeatureStability { AcceptedSince(Symbol), - Unstable, + Unstable { old_name: Option }, } #[derive(HashStable, Debug, Default)] diff --git a/compiler/rustc_middle/src/middle/stability.rs b/compiler/rustc_middle/src/middle/stability.rs index 454ab8c107f0a..ab6a65ed52634 100644 --- a/compiler/rustc_middle/src/middle/stability.rs +++ b/compiler/rustc_middle/src/middle/stability.rs @@ -411,7 +411,7 @@ impl<'tcx> TyCtxt<'tcx> { match stability { Some(Stability { - level: attrs::StabilityLevel::Unstable { reason, issue, is_soft, implied_by }, + level: attrs::StabilityLevel::Unstable { reason, issue, is_soft, implied_by, .. }, feature, .. }) => { diff --git a/compiler/rustc_passes/messages.ftl b/compiler/rustc_passes/messages.ftl index 983e562cdf3ce..6ff454a18e140 100644 --- a/compiler/rustc_passes/messages.ftl +++ b/compiler/rustc_passes/messages.ftl @@ -748,6 +748,9 @@ passes_unknown_external_lang_item = passes_unknown_feature = unknown feature `{$feature}` +passes_unknown_feature_alias = + feature `{$alias}` has been renamed to `{$feature}` + passes_unknown_lang_item = definition of an unknown lang item: `{$name}` .label = definition of unknown lang item `{$name}` diff --git a/compiler/rustc_passes/src/errors.rs b/compiler/rustc_passes/src/errors.rs index b995781719b6c..c48a7d84ffc1c 100644 --- a/compiler/rustc_passes/src/errors.rs +++ b/compiler/rustc_passes/src/errors.rs @@ -1560,6 +1560,15 @@ pub(crate) struct UnknownFeature { pub feature: Symbol, } +#[derive(Diagnostic)] +#[diag(passes_unknown_feature_alias, code = E0635)] +pub(crate) struct RenamedFeature { + #[primary_span] + pub span: Span, + pub feature: Symbol, + pub alias: Symbol, +} + #[derive(Diagnostic)] #[diag(passes_implied_feature_not_exist)] pub(crate) struct ImpliedFeatureNotExist { diff --git a/compiler/rustc_passes/src/lib_features.rs b/compiler/rustc_passes/src/lib_features.rs index b3e6ee9512c85..127e0df133215 100644 --- a/compiler/rustc_passes/src/lib_features.rs +++ b/compiler/rustc_passes/src/lib_features.rs @@ -40,7 +40,7 @@ impl<'tcx> LibFeatureCollector<'tcx> { }; let feature_stability = match level { - StabilityLevel::Unstable { .. } => FeatureStability::Unstable, + StabilityLevel::Unstable { old_name, .. } => FeatureStability::Unstable { old_name }, StabilityLevel::Stable { since, .. } => FeatureStability::AcceptedSince(match since { StableSince::Version(v) => Symbol::intern(&v.to_string()), StableSince::Current => sym::env_CFG_RELEASE, @@ -71,7 +71,7 @@ impl<'tcx> LibFeatureCollector<'tcx> { }); } } - (FeatureStability::AcceptedSince(_), Some((FeatureStability::Unstable, _))) => { + (FeatureStability::AcceptedSince(_), Some((FeatureStability::Unstable { .. }, _))) => { self.tcx.dcx().emit_err(FeaturePreviouslyDeclared { span, feature, @@ -79,7 +79,7 @@ impl<'tcx> LibFeatureCollector<'tcx> { prev_declared: "unstable", }); } - (FeatureStability::Unstable, Some((FeatureStability::AcceptedSince(_), _))) => { + (FeatureStability::Unstable { .. }, Some((FeatureStability::AcceptedSince(_), _))) => { self.tcx.dcx().emit_err(FeaturePreviouslyDeclared { span, feature, @@ -88,7 +88,7 @@ impl<'tcx> LibFeatureCollector<'tcx> { }); } // duplicate `unstable` feature is ok. - (FeatureStability::Unstable, Some((FeatureStability::Unstable, _))) => {} + (FeatureStability::Unstable { .. }, Some((FeatureStability::Unstable { .. }, _))) => {} } } } diff --git a/compiler/rustc_passes/src/stability.rs b/compiler/rustc_passes/src/stability.rs index 45e26c8999a9f..56d9f5bf78577 100644 --- a/compiler/rustc_passes/src/stability.rs +++ b/compiler/rustc_passes/src/stability.rs @@ -718,6 +718,7 @@ fn stability_index(tcx: TyCtxt<'_>, (): ()) -> Index { issue: NonZero::new(27812), is_soft: false, implied_by: None, + old_name: None, }, feature: sym::rustc_private, }; @@ -1161,8 +1162,8 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) { defined_features: &LibFeatures, all_implications: &UnordMap, ) { - for (feature, since) in defined_features.to_sorted_vec() { - if let FeatureStability::AcceptedSince(since) = since + for (feature, stability) in defined_features.to_sorted_vec() { + if let FeatureStability::AcceptedSince(since) = stability && let Some(span) = remaining_lib_features.get(&feature) { // Warn if the user has enabled an already-stable lib feature. @@ -1181,6 +1182,12 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) { // implications from this crate. remaining_implications.remove(&feature); + if let FeatureStability::Unstable { old_name: Some(alias) } = stability { + if let Some(span) = remaining_lib_features.swap_remove(&alias) { + tcx.dcx().emit_err(errors::RenamedFeature { span, feature, alias }); + } + } + if remaining_lib_features.is_empty() && remaining_implications.is_empty() { break; } diff --git a/compiler/rustc_resolve/src/macros.rs b/compiler/rustc_resolve/src/macros.rs index ee905065b966b..79a60b5a455b4 100644 --- a/compiler/rustc_resolve/src/macros.rs +++ b/compiler/rustc_resolve/src/macros.rs @@ -974,7 +974,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { ) { 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, implied_by, .. } = + stability.level { let feature = stability.feature; diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 4e842a8f93a8f..01e1cf67b1850 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -1496,6 +1496,7 @@ symbols! { offset_of_nested, offset_of_slice, ok_or_else, + old_name, omit_gdb_pretty_printer_section, on, on_unimplemented, diff --git a/library/core/src/ops/control_flow.rs b/library/core/src/ops/control_flow.rs index ef7e6f9c2f491..26661b20c12d6 100644 --- a/library/core/src/ops/control_flow.rs +++ b/library/core/src/ops/control_flow.rs @@ -98,7 +98,7 @@ pub enum ControlFlow { // is a no-op conversion in the `Try` implementation. } -#[unstable(feature = "try_trait_v2", issue = "84277")] +#[unstable(feature = "try_trait_v2", issue = "84277", old_name = "try_trait")] impl ops::Try for ControlFlow { type Output = C; type Residual = ControlFlow; @@ -117,7 +117,7 @@ impl ops::Try for ControlFlow { } } -#[unstable(feature = "try_trait_v2", issue = "84277")] +#[unstable(feature = "try_trait_v2", issue = "84277", old_name = "try_trait")] // Note: manually specifying the residual type instead of using the default to work around // https://github.com/rust-lang/rust/issues/99940 impl ops::FromResidual> for ControlFlow { diff --git a/library/core/src/ops/mod.rs b/library/core/src/ops/mod.rs index 1658f0e5a3692..87dd873fdb57d 100644 --- a/library/core/src/ops/mod.rs +++ b/library/core/src/ops/mod.rs @@ -194,7 +194,7 @@ pub use self::try_trait::Residual; #[unstable(feature = "try_trait_v2_yeet", issue = "96374")] pub use self::try_trait::Yeet; pub(crate) use self::try_trait::{ChangeOutputType, NeverShortCircuit}; -#[unstable(feature = "try_trait_v2", issue = "84277")] +#[unstable(feature = "try_trait_v2", issue = "84277", old_name = "try_trait")] pub use self::try_trait::{FromResidual, Try}; #[unstable(feature = "coerce_unsized", issue = "18598")] pub use self::unsize::CoerceUnsized; diff --git a/library/core/src/ops/try_trait.rs b/library/core/src/ops/try_trait.rs index bac8ffb074ba8..aebbddb4f1c07 100644 --- a/library/core/src/ops/try_trait.rs +++ b/library/core/src/ops/try_trait.rs @@ -112,7 +112,7 @@ use crate::ops::ControlFlow; /// R::from_output(accum) /// } /// ``` -#[unstable(feature = "try_trait_v2", issue = "84277")] +#[unstable(feature = "try_trait_v2", issue = "84277", old_name = "try_trait")] #[rustc_on_unimplemented( on( all(from_desugaring = "TryBlock"), @@ -130,7 +130,7 @@ use crate::ops::ControlFlow; #[lang = "Try"] pub trait Try: FromResidual { /// The type of the value produced by `?` when *not* short-circuiting. - #[unstable(feature = "try_trait_v2", issue = "84277")] + #[unstable(feature = "try_trait_v2", issue = "84277", old_name = "try_trait")] type Output; /// The type of the value passed to [`FromResidual::from_residual`] @@ -154,7 +154,7 @@ pub trait Try: FromResidual { /// then typically you can use `Foo` as its `Residual` /// type: that type will have a "hole" in the correct place, and will maintain the /// "foo-ness" of the residual so other types need to opt-in to interconversion. - #[unstable(feature = "try_trait_v2", issue = "84277")] + #[unstable(feature = "try_trait_v2", issue = "84277", old_name = "try_trait")] type Residual; /// Constructs the type from its `Output` type. @@ -186,7 +186,7 @@ pub trait Try: FromResidual { /// assert_eq!(r, Some(4)); /// ``` #[lang = "from_output"] - #[unstable(feature = "try_trait_v2", issue = "84277")] + #[unstable(feature = "try_trait_v2", issue = "84277", old_name = "try_trait")] fn from_output(output: Self::Output) -> Self; /// Used in `?` to decide whether the operator should produce a value @@ -213,7 +213,7 @@ pub trait Try: FromResidual { /// ); /// ``` #[lang = "branch"] - #[unstable(feature = "try_trait_v2", issue = "84277")] + #[unstable(feature = "try_trait_v2", issue = "84277", old_name = "try_trait")] fn branch(self) -> ControlFlow; } @@ -303,7 +303,7 @@ pub trait Try: FromResidual { ), )] #[rustc_diagnostic_item = "FromResidual"] -#[unstable(feature = "try_trait_v2", issue = "84277")] +#[unstable(feature = "try_trait_v2", issue = "84277", old_name = "try_trait")] pub trait FromResidual::Residual> { /// Constructs the type from a compatible `Residual` type. /// @@ -326,7 +326,7 @@ pub trait FromResidual::Residual> { /// ); /// ``` #[lang = "from_residual"] - #[unstable(feature = "try_trait_v2", issue = "84277")] + #[unstable(feature = "try_trait_v2", issue = "84277", old_name = "try_trait")] fn from_residual(residual: R) -> Self; } diff --git a/library/core/src/option.rs b/library/core/src/option.rs index 675556b07a838..4a055fd2e808f 100644 --- a/library/core/src/option.rs +++ b/library/core/src/option.rs @@ -2532,7 +2532,7 @@ impl> FromIterator> for Option { } } -#[unstable(feature = "try_trait_v2", issue = "84277")] +#[unstable(feature = "try_trait_v2", issue = "84277", old_name = "try_trait")] impl ops::Try for Option { type Output = T; type Residual = Option; @@ -2551,7 +2551,7 @@ impl ops::Try for Option { } } -#[unstable(feature = "try_trait_v2", issue = "84277")] +#[unstable(feature = "try_trait_v2", issue = "84277", old_name = "try_trait")] // Note: manually specifying the residual type instead of using the default to work around // https://github.com/rust-lang/rust/issues/99940 impl ops::FromResidual> for Option { diff --git a/library/core/src/result.rs b/library/core/src/result.rs index 23e32c2e0f01d..3a84ea66ad4b2 100644 --- a/library/core/src/result.rs +++ b/library/core/src/result.rs @@ -2051,7 +2051,7 @@ impl> FromIterator> for Result { } } -#[unstable(feature = "try_trait_v2", issue = "84277")] +#[unstable(feature = "try_trait_v2", issue = "84277", old_name = "try_trait")] impl ops::Try for Result { type Output = T; type Residual = Result; @@ -2070,7 +2070,7 @@ impl ops::Try for Result { } } -#[unstable(feature = "try_trait_v2", issue = "84277")] +#[unstable(feature = "try_trait_v2", issue = "84277", old_name = "try_trait")] impl> ops::FromResidual> for Result { #[inline] #[track_caller] diff --git a/library/core/src/task/poll.rs b/library/core/src/task/poll.rs index 6aab22177ab9d..ca668361ef63b 100644 --- a/library/core/src/task/poll.rs +++ b/library/core/src/task/poll.rs @@ -229,7 +229,7 @@ impl From for Poll { } } -#[unstable(feature = "try_trait_v2", issue = "84277")] +#[unstable(feature = "try_trait_v2", issue = "84277", old_name = "try_trait")] impl ops::Try for Poll> { type Output = Poll; type Residual = Result; @@ -249,7 +249,7 @@ impl ops::Try for Poll> { } } -#[unstable(feature = "try_trait_v2", issue = "84277")] +#[unstable(feature = "try_trait_v2", issue = "84277", old_name = "try_trait")] impl> ops::FromResidual> for Poll> { #[inline] fn from_residual(x: Result) -> Self { @@ -259,7 +259,7 @@ impl> ops::FromResidual> for Pol } } -#[unstable(feature = "try_trait_v2", issue = "84277")] +#[unstable(feature = "try_trait_v2", issue = "84277", old_name = "try_trait")] impl ops::Try for Poll>> { type Output = Poll>; type Residual = Result; @@ -280,7 +280,7 @@ impl ops::Try for Poll>> { } } -#[unstable(feature = "try_trait_v2", issue = "84277")] +#[unstable(feature = "try_trait_v2", issue = "84277", old_name = "try_trait")] impl> ops::FromResidual> for Poll>> { diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index bde1a2e5e6642..58e05bd1e8574 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -2638,7 +2638,7 @@ mod size_asserts { static_assert_size!(GenericParamDef, 40); static_assert_size!(Generics, 16); static_assert_size!(Item, 8); - static_assert_size!(ItemInner, 136); + static_assert_size!(ItemInner, 144); static_assert_size!(ItemKind, 48); static_assert_size!(PathSegment, 32); static_assert_size!(Type, 32); diff --git a/tests/ui/stability-attribute/renamed_feature.rs b/tests/ui/stability-attribute/renamed_feature.rs new file mode 100644 index 0000000000000..249c2abecff0e --- /dev/null +++ b/tests/ui/stability-attribute/renamed_feature.rs @@ -0,0 +1,3 @@ +#![feature(try_trait)] //~ ERROR feature `try_trait` has been renamed to `try_trait_v2` [E0635] + +fn main() {} diff --git a/tests/ui/stability-attribute/renamed_feature.stderr b/tests/ui/stability-attribute/renamed_feature.stderr new file mode 100644 index 0000000000000..293a2feffb226 --- /dev/null +++ b/tests/ui/stability-attribute/renamed_feature.stderr @@ -0,0 +1,9 @@ +error[E0635]: feature `try_trait` has been renamed to `try_trait_v2` + --> $DIR/renamed_feature.rs:1:12 + | +LL | #![feature(try_trait)] + | ^^^^^^^^^ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0635`. diff --git a/tests/ui/stats/input-stats.stderr b/tests/ui/stats/input-stats.stderr index f2598bd7eaf85..88f91bef30b1a 100644 --- a/tests/ui/stats/input-stats.stderr +++ b/tests/ui/stats/input-stats.stderr @@ -82,10 +82,10 @@ hir-stats - Expr 32 (NN.N%) 1 hir-stats - Let 32 (NN.N%) 1 hir-stats - Semi 32 (NN.N%) 1 hir-stats FnDecl 120 (NN.N%) 3 40 -hir-stats Attribute 128 (NN.N%) 4 32 hir-stats FieldDef 128 (NN.N%) 2 64 hir-stats GenericArgs 144 (NN.N%) 3 48 hir-stats Variant 144 (NN.N%) 2 72 +hir-stats Attribute 160 (NN.N%) 4 40 hir-stats GenericBound 256 (NN.N%) 4 64 hir-stats - Trait 256 (NN.N%) 4 hir-stats Block 288 (NN.N%) 6 48 @@ -117,5 +117,5 @@ hir-stats - Use 352 (NN.N%) 4 hir-stats Path 1_040 (NN.N%) 26 40 hir-stats PathSegment 1_776 (NN.N%) 37 48 hir-stats ---------------------------------------------------------------- -hir-stats Total 8_644 172 +hir-stats Total 8_676 172 hir-stats