Skip to content

Commit b8066f9

Browse files
committed
Tracking the old name of renamed unstable library attribute
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
1 parent 8eeaed0 commit b8066f9

File tree

20 files changed

+58
-33
lines changed

20 files changed

+58
-33
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
@@ -299,6 +299,7 @@ pub(crate) fn parse_unstability(
299299
let mut issue_num = None;
300300
let mut is_soft = false;
301301
let mut implied_by = None;
302+
let mut old_name = None;
302303
for param in args.list()?.mixed() {
303304
let Some(param) = param.meta_item() else {
304305
cx.emit_err(session_diagnostics::UnsupportedLiteral {
@@ -346,11 +347,12 @@ pub(crate) fn parse_unstability(
346347
Some(sym::implied_by) => {
347348
insert_value_into_option_or_error(cx, &param, &mut implied_by)?
348349
}
350+
Some(sym::old_name) => insert_value_into_option_or_error(cx, &param, &mut old_name)?,
349351
_ => {
350352
cx.emit_err(session_diagnostics::UnknownMetaItem {
351353
span: param.span(),
352354
item: param.path().to_string(),
353-
expected: &["feature", "reason", "issue", "soft", "implied_by"],
355+
expected: &["feature", "reason", "issue", "soft", "implied_by", "old_name"],
354356
});
355357
return None;
356358
}
@@ -375,6 +377,7 @@ pub(crate) fn parse_unstability(
375377
issue: issue_num,
376378
is_soft,
377379
implied_by,
380+
old_name,
378381
};
379382
Some((feature, level))
380383
}

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
@@ -748,6 +748,9 @@ passes_unknown_external_lang_item =
748748
passes_unknown_feature =
749749
unknown feature `{$feature}`
750750
751+
passes_unknown_feature_alias =
752+
feature `{$alias}` has been renamed to `{$feature}`
753+
751754
passes_unknown_lang_item =
752755
definition of an unknown lang item: `{$name}`
753756
.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
@@ -1560,6 +1560,15 @@ pub(crate) struct UnknownFeature {
15601560
pub feature: Symbol,
15611561
}
15621562

1563+
#[derive(Diagnostic)]
1564+
#[diag(passes_unknown_feature_alias, code = E0635)]
1565+
pub(crate) struct RenamedFeature {
1566+
#[primary_span]
1567+
pub span: Span,
1568+
pub feature: Symbol,
1569+
pub alias: Symbol,
1570+
}
1571+
15631572
#[derive(Diagnostic)]
15641573
#[diag(passes_implied_feature_not_exist)]
15651574
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
@@ -1496,6 +1496,7 @@ symbols! {
14961496
offset_of_nested,
14971497
offset_of_slice,
14981498
ok_or_else,
1499+
old_name,
14991500
omit_gdb_pretty_printer_section,
15001501
on,
15011502
on_unimplemented,

0 commit comments

Comments
 (0)