Rollup merge of #142158 - xizheyin:141617, r=jdonszelmann

Tracking the old name of renamed unstable library features

This PR resolves the first problem of rust-lang/rust#141617 : tracking renamed unstable features. The first commit is to add a ui test, and the second one tracks the changes. I will comment on the code for clarification.

r? `@jdonszelmann`
There have been a lot of PR's reviewed by you lately, thanks for your time!

cc `@jyn514`
This commit is contained in:
Matthias Krüger
2025-06-13 05:16:56 +02:00
committed by GitHub
20 changed files with 68 additions and 31 deletions

View File

@@ -719,6 +719,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}`

View File

@@ -1434,6 +1434,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 {

View File

@@ -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 { .. }, _))) => {}
}
}
}

View File

@@ -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<Symbol, Symbol>,
) {
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;
}