Skip to content

Commit fac011e

Browse files
authored
Rollup merge of rust-lang#142158 - xizheyin:141617, r=jdonszelmann
Tracking the old name of renamed unstable library features This PR resolves the first problem of rust-lang#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`
2 parents 9639a7c + b8066f9 commit fac011e

File tree

20 files changed

+68
-31
lines changed

20 files changed

+68
-31
lines changed

compiler/rustc_attr_data_structures/src/stability.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ pub enum StabilityLevel {
132132
/// fn foobar() {}
133133
/// ```
134134
implied_by: Option<Symbol>,
135+
old_name: Option<Symbol>,
135136
},
136137
/// `#[stable]`
137138
Stable {

compiler/rustc_attr_parsing/src/attributes/stability.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ pub(crate) fn parse_unstability<S: Stage>(
298298
let mut issue_num = None;
299299
let mut is_soft = false;
300300
let mut implied_by = None;
301+
let mut old_name = None;
301302
for param in args.list()?.mixed() {
302303
let Some(param) = param.meta_item() else {
303304
cx.emit_err(session_diagnostics::UnsupportedLiteral {
@@ -345,11 +346,12 @@ pub(crate) fn parse_unstability<S: Stage>(
345346
Some(sym::implied_by) => {
346347
insert_value_into_option_or_error(cx, &param, &mut implied_by)?
347348
}
349+
Some(sym::old_name) => insert_value_into_option_or_error(cx, &param, &mut old_name)?,
348350
_ => {
349351
cx.emit_err(session_diagnostics::UnknownMetaItem {
350352
span: param.span(),
351353
item: param.path().to_string(),
352-
expected: &["feature", "reason", "issue", "soft", "implied_by"],
354+
expected: &["feature", "reason", "issue", "soft", "implied_by", "old_name"],
353355
});
354356
return None;
355357
}
@@ -374,6 +376,7 @@ pub(crate) fn parse_unstability<S: Stage>(
374376
issue: issue_num,
375377
is_soft,
376378
implied_by,
379+
old_name,
377380
};
378381
Some((feature, level))
379382
}

compiler/rustc_middle/src/middle/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub mod lib_features {
1212
#[derive(HashStable, TyEncodable, TyDecodable)]
1313
pub enum FeatureStability {
1414
AcceptedSince(Symbol),
15-
Unstable,
15+
Unstable { old_name: Option<Symbol> },
1616
}
1717

1818
#[derive(HashStable, Debug, Default)]

compiler/rustc_middle/src/middle/stability.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ impl<'tcx> TyCtxt<'tcx> {
411411

412412
match stability {
413413
Some(Stability {
414-
level: attrs::StabilityLevel::Unstable { reason, issue, is_soft, implied_by },
414+
level: attrs::StabilityLevel::Unstable { reason, issue, is_soft, implied_by, .. },
415415
feature,
416416
..
417417
}) => {

compiler/rustc_passes/messages.ftl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,9 @@ passes_unknown_external_lang_item =
719719
passes_unknown_feature =
720720
unknown feature `{$feature}`
721721
722+
passes_unknown_feature_alias =
723+
feature `{$alias}` has been renamed to `{$feature}`
724+
722725
passes_unknown_lang_item =
723726
definition of an unknown lang item: `{$name}`
724727
.label = definition of unknown lang item `{$name}`

compiler/rustc_passes/src/errors.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,6 +1434,15 @@ pub(crate) struct UnknownFeature {
14341434
pub feature: Symbol,
14351435
}
14361436

1437+
#[derive(Diagnostic)]
1438+
#[diag(passes_unknown_feature_alias, code = E0635)]
1439+
pub(crate) struct RenamedFeature {
1440+
#[primary_span]
1441+
pub span: Span,
1442+
pub feature: Symbol,
1443+
pub alias: Symbol,
1444+
}
1445+
14371446
#[derive(Diagnostic)]
14381447
#[diag(passes_implied_feature_not_exist)]
14391448
pub(crate) struct ImpliedFeatureNotExist {

compiler/rustc_passes/src/lib_features.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl<'tcx> LibFeatureCollector<'tcx> {
4040
};
4141

4242
let feature_stability = match level {
43-
StabilityLevel::Unstable { .. } => FeatureStability::Unstable,
43+
StabilityLevel::Unstable { old_name, .. } => FeatureStability::Unstable { old_name },
4444
StabilityLevel::Stable { since, .. } => FeatureStability::AcceptedSince(match since {
4545
StableSince::Version(v) => Symbol::intern(&v.to_string()),
4646
StableSince::Current => sym::env_CFG_RELEASE,
@@ -71,15 +71,15 @@ impl<'tcx> LibFeatureCollector<'tcx> {
7171
});
7272
}
7373
}
74-
(FeatureStability::AcceptedSince(_), Some((FeatureStability::Unstable, _))) => {
74+
(FeatureStability::AcceptedSince(_), Some((FeatureStability::Unstable { .. }, _))) => {
7575
self.tcx.dcx().emit_err(FeaturePreviouslyDeclared {
7676
span,
7777
feature,
7878
declared: "stable",
7979
prev_declared: "unstable",
8080
});
8181
}
82-
(FeatureStability::Unstable, Some((FeatureStability::AcceptedSince(_), _))) => {
82+
(FeatureStability::Unstable { .. }, Some((FeatureStability::AcceptedSince(_), _))) => {
8383
self.tcx.dcx().emit_err(FeaturePreviouslyDeclared {
8484
span,
8585
feature,
@@ -88,7 +88,7 @@ impl<'tcx> LibFeatureCollector<'tcx> {
8888
});
8989
}
9090
// duplicate `unstable` feature is ok.
91-
(FeatureStability::Unstable, Some((FeatureStability::Unstable, _))) => {}
91+
(FeatureStability::Unstable { .. }, Some((FeatureStability::Unstable { .. }, _))) => {}
9292
}
9393
}
9494
}

compiler/rustc_passes/src/stability.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,7 @@ fn stability_index(tcx: TyCtxt<'_>, (): ()) -> Index {
718718
issue: NonZero::new(27812),
719719
is_soft: false,
720720
implied_by: None,
721+
old_name: None,
721722
},
722723
feature: sym::rustc_private,
723724
};
@@ -1161,8 +1162,8 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) {
11611162
defined_features: &LibFeatures,
11621163
all_implications: &UnordMap<Symbol, Symbol>,
11631164
) {
1164-
for (feature, since) in defined_features.to_sorted_vec() {
1165-
if let FeatureStability::AcceptedSince(since) = since
1165+
for (feature, stability) in defined_features.to_sorted_vec() {
1166+
if let FeatureStability::AcceptedSince(since) = stability
11661167
&& let Some(span) = remaining_lib_features.get(&feature)
11671168
{
11681169
// Warn if the user has enabled an already-stable lib feature.
@@ -1181,6 +1182,12 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) {
11811182
// implications from this crate.
11821183
remaining_implications.remove(&feature);
11831184

1185+
if let FeatureStability::Unstable { old_name: Some(alias) } = stability {
1186+
if let Some(span) = remaining_lib_features.swap_remove(&alias) {
1187+
tcx.dcx().emit_err(errors::RenamedFeature { span, feature, alias });
1188+
}
1189+
}
1190+
11841191
if remaining_lib_features.is_empty() && remaining_implications.is_empty() {
11851192
break;
11861193
}

compiler/rustc_resolve/src/macros.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -974,7 +974,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
974974
) {
975975
let span = path.span;
976976
if let Some(stability) = &ext.stability {
977-
if let StabilityLevel::Unstable { reason, issue, is_soft, implied_by } = stability.level
977+
if let StabilityLevel::Unstable { reason, issue, is_soft, implied_by, .. } =
978+
stability.level
978979
{
979980
let feature = stability.feature;
980981

compiler/rustc_span/src/symbol.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,6 +1512,7 @@ symbols! {
15121512
offset_of_nested,
15131513
offset_of_slice,
15141514
ok_or_else,
1515+
old_name,
15151516
omit_gdb_pretty_printer_section,
15161517
on,
15171518
on_unimplemented,

0 commit comments

Comments
 (0)