Skip to content

Commit 6c9a2e2

Browse files
committed
Tracking the old name of renamed unstable library attribute
Signed-off-by: xizheyin <[email protected]>
1 parent 8eeaed0 commit 6c9a2e2

File tree

19 files changed

+57
-33
lines changed

19 files changed

+57
-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+
alias: 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 alias = 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::alias) => insert_value_into_option_or_error(cx, &param, &mut alias)?,
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", "alias"],
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+
alias,
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(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 { alias, .. } => FeatureStability::Unstable(alias),
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+
alias: 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(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

library/core/src/ops/control_flow.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ pub enum ControlFlow<B, C = ()> {
9898
// is a no-op conversion in the `Try` implementation.
9999
}
100100

101-
#[unstable(feature = "try_trait_v2", issue = "84277")]
101+
#[unstable(feature = "try_trait_v2", issue = "84277", alias = "try_trait")]
102102
impl<B, C> ops::Try for ControlFlow<B, C> {
103103
type Output = C;
104104
type Residual = ControlFlow<B, convert::Infallible>;
@@ -117,7 +117,7 @@ impl<B, C> ops::Try for ControlFlow<B, C> {
117117
}
118118
}
119119

120-
#[unstable(feature = "try_trait_v2", issue = "84277")]
120+
#[unstable(feature = "try_trait_v2", issue = "84277", alias = "try_trait")]
121121
// Note: manually specifying the residual type instead of using the default to work around
122122
// https://github.com/rust-lang/rust/issues/99940
123123
impl<B, C> ops::FromResidual<ControlFlow<B, convert::Infallible>> for ControlFlow<B, C> {

library/core/src/ops/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ pub use self::try_trait::Residual;
194194
#[unstable(feature = "try_trait_v2_yeet", issue = "96374")]
195195
pub use self::try_trait::Yeet;
196196
pub(crate) use self::try_trait::{ChangeOutputType, NeverShortCircuit};
197-
#[unstable(feature = "try_trait_v2", issue = "84277")]
197+
#[unstable(feature = "try_trait_v2", issue = "84277", alias = "try_trait")]
198198
pub use self::try_trait::{FromResidual, Try};
199199
#[unstable(feature = "coerce_unsized", issue = "18598")]
200200
pub use self::unsize::CoerceUnsized;

library/core/src/ops/try_trait.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ use crate::ops::ControlFlow;
112112
/// R::from_output(accum)
113113
/// }
114114
/// ```
115-
#[unstable(feature = "try_trait_v2", issue = "84277")]
115+
#[unstable(feature = "try_trait_v2", issue = "84277", alias = "try_trait")]
116116
#[rustc_on_unimplemented(
117117
on(
118118
all(from_desugaring = "TryBlock"),
@@ -130,7 +130,7 @@ use crate::ops::ControlFlow;
130130
#[lang = "Try"]
131131
pub trait Try: FromResidual {
132132
/// The type of the value produced by `?` when *not* short-circuiting.
133-
#[unstable(feature = "try_trait_v2", issue = "84277")]
133+
#[unstable(feature = "try_trait_v2", issue = "84277", alias = "try_trait")]
134134
type Output;
135135

136136
/// The type of the value passed to [`FromResidual::from_residual`]
@@ -154,7 +154,7 @@ pub trait Try: FromResidual {
154154
/// then typically you can use `Foo<std::convert::Infallible>` as its `Residual`
155155
/// type: that type will have a "hole" in the correct place, and will maintain the
156156
/// "foo-ness" of the residual so other types need to opt-in to interconversion.
157-
#[unstable(feature = "try_trait_v2", issue = "84277")]
157+
#[unstable(feature = "try_trait_v2", issue = "84277", alias = "try_trait")]
158158
type Residual;
159159

160160
/// Constructs the type from its `Output` type.
@@ -186,7 +186,7 @@ pub trait Try: FromResidual {
186186
/// assert_eq!(r, Some(4));
187187
/// ```
188188
#[lang = "from_output"]
189-
#[unstable(feature = "try_trait_v2", issue = "84277")]
189+
#[unstable(feature = "try_trait_v2", issue = "84277", alias = "try_trait")]
190190
fn from_output(output: Self::Output) -> Self;
191191

192192
/// Used in `?` to decide whether the operator should produce a value
@@ -213,7 +213,7 @@ pub trait Try: FromResidual {
213213
/// );
214214
/// ```
215215
#[lang = "branch"]
216-
#[unstable(feature = "try_trait_v2", issue = "84277")]
216+
#[unstable(feature = "try_trait_v2", issue = "84277", alias = "try_trait")]
217217
fn branch(self) -> ControlFlow<Self::Residual, Self::Output>;
218218
}
219219

@@ -303,7 +303,7 @@ pub trait Try: FromResidual {
303303
),
304304
)]
305305
#[rustc_diagnostic_item = "FromResidual"]
306-
#[unstable(feature = "try_trait_v2", issue = "84277")]
306+
#[unstable(feature = "try_trait_v2", issue = "84277", alias = "try_trait")]
307307
pub trait FromResidual<R = <Self as Try>::Residual> {
308308
/// Constructs the type from a compatible `Residual` type.
309309
///
@@ -326,7 +326,7 @@ pub trait FromResidual<R = <Self as Try>::Residual> {
326326
/// );
327327
/// ```
328328
#[lang = "from_residual"]
329-
#[unstable(feature = "try_trait_v2", issue = "84277")]
329+
#[unstable(feature = "try_trait_v2", issue = "84277", alias = "try_trait")]
330330
fn from_residual(residual: R) -> Self;
331331
}
332332

library/core/src/option.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2532,7 +2532,7 @@ impl<A, V: FromIterator<A>> FromIterator<Option<A>> for Option<V> {
25322532
}
25332533
}
25342534

2535-
#[unstable(feature = "try_trait_v2", issue = "84277")]
2535+
#[unstable(feature = "try_trait_v2", issue = "84277", alias = "try_trait")]
25362536
impl<T> ops::Try for Option<T> {
25372537
type Output = T;
25382538
type Residual = Option<convert::Infallible>;
@@ -2551,7 +2551,7 @@ impl<T> ops::Try for Option<T> {
25512551
}
25522552
}
25532553

2554-
#[unstable(feature = "try_trait_v2", issue = "84277")]
2554+
#[unstable(feature = "try_trait_v2", issue = "84277", alias = "try_trait")]
25552555
// Note: manually specifying the residual type instead of using the default to work around
25562556
// https://github.com/rust-lang/rust/issues/99940
25572557
impl<T> ops::FromResidual<Option<convert::Infallible>> for Option<T> {

library/core/src/result.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2051,7 +2051,7 @@ impl<A, E, V: FromIterator<A>> FromIterator<Result<A, E>> for Result<V, E> {
20512051
}
20522052
}
20532053

2054-
#[unstable(feature = "try_trait_v2", issue = "84277")]
2054+
#[unstable(feature = "try_trait_v2", issue = "84277", alias = "try_trait")]
20552055
impl<T, E> ops::Try for Result<T, E> {
20562056
type Output = T;
20572057
type Residual = Result<convert::Infallible, E>;
@@ -2070,7 +2070,7 @@ impl<T, E> ops::Try for Result<T, E> {
20702070
}
20712071
}
20722072

2073-
#[unstable(feature = "try_trait_v2", issue = "84277")]
2073+
#[unstable(feature = "try_trait_v2", issue = "84277", alias = "try_trait")]
20742074
impl<T, E, F: From<E>> ops::FromResidual<Result<convert::Infallible, E>> for Result<T, F> {
20752075
#[inline]
20762076
#[track_caller]

library/core/src/task/poll.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ impl<T> From<T> for Poll<T> {
229229
}
230230
}
231231

232-
#[unstable(feature = "try_trait_v2", issue = "84277")]
232+
#[unstable(feature = "try_trait_v2", issue = "84277", alias = "try_trait")]
233233
impl<T, E> ops::Try for Poll<Result<T, E>> {
234234
type Output = Poll<T>;
235235
type Residual = Result<convert::Infallible, E>;
@@ -249,7 +249,7 @@ impl<T, E> ops::Try for Poll<Result<T, E>> {
249249
}
250250
}
251251

252-
#[unstable(feature = "try_trait_v2", issue = "84277")]
252+
#[unstable(feature = "try_trait_v2", issue = "84277", alias = "try_trait")]
253253
impl<T, E, F: From<E>> ops::FromResidual<Result<convert::Infallible, E>> for Poll<Result<T, F>> {
254254
#[inline]
255255
fn from_residual(x: Result<convert::Infallible, E>) -> Self {
@@ -259,7 +259,7 @@ impl<T, E, F: From<E>> ops::FromResidual<Result<convert::Infallible, E>> for Pol
259259
}
260260
}
261261

262-
#[unstable(feature = "try_trait_v2", issue = "84277")]
262+
#[unstable(feature = "try_trait_v2", issue = "84277", alias = "try_trait")]
263263
impl<T, E> ops::Try for Poll<Option<Result<T, E>>> {
264264
type Output = Poll<Option<T>>;
265265
type Residual = Result<convert::Infallible, E>;
@@ -280,7 +280,7 @@ impl<T, E> ops::Try for Poll<Option<Result<T, E>>> {
280280
}
281281
}
282282

283-
#[unstable(feature = "try_trait_v2", issue = "84277")]
283+
#[unstable(feature = "try_trait_v2", issue = "84277", alias = "try_trait")]
284284
impl<T, E, F: From<E>> ops::FromResidual<Result<convert::Infallible, E>>
285285
for Poll<Option<Result<T, F>>>
286286
{

src/librustdoc/clean/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2638,7 +2638,7 @@ mod size_asserts {
26382638
static_assert_size!(GenericParamDef, 40);
26392639
static_assert_size!(Generics, 16);
26402640
static_assert_size!(Item, 8);
2641-
static_assert_size!(ItemInner, 136);
2641+
static_assert_size!(ItemInner, 144);
26422642
static_assert_size!(ItemKind, 48);
26432643
static_assert_size!(PathSegment, 32);
26442644
static_assert_size!(Type, 32);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
#![feature(try_trait)] //~ ERROR unknown feature `try_trait`
1+
#![feature(try_trait)] //~ ERROR feature `try_trait` has been renamed to `try_trait_v2` [E0635]
22

33
fn main() {}

tests/ui/stability-attribute/renamed_feature.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0635]: unknown feature `try_trait`
1+
error[E0635]: feature `try_trait` has been renamed to `try_trait_v2`
22
--> $DIR/renamed_feature.rs:1:12
33
|
44
LL | #![feature(try_trait)]

tests/ui/stats/input-stats.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ hir-stats - Expr 32 (NN.N%) 1
8282
hir-stats - Let 32 (NN.N%) 1
8383
hir-stats - Semi 32 (NN.N%) 1
8484
hir-stats FnDecl 120 (NN.N%) 3 40
85-
hir-stats Attribute 128 (NN.N%) 4 32
8685
hir-stats FieldDef 128 (NN.N%) 2 64
8786
hir-stats GenericArgs 144 (NN.N%) 3 48
8887
hir-stats Variant 144 (NN.N%) 2 72
88+
hir-stats Attribute 160 (NN.N%) 4 40
8989
hir-stats GenericBound 256 (NN.N%) 4 64
9090
hir-stats - Trait 256 (NN.N%) 4
9191
hir-stats Block 288 (NN.N%) 6 48
@@ -117,5 +117,5 @@ hir-stats - Use 352 (NN.N%) 4
117117
hir-stats Path 1_040 (NN.N%) 26 40
118118
hir-stats PathSegment 1_776 (NN.N%) 37 48
119119
hir-stats ----------------------------------------------------------------
120-
hir-stats Total 8_644 172
120+
hir-stats Total 8_676 172
121121
hir-stats

0 commit comments

Comments
 (0)