Skip to content

Commit abdc8a8

Browse files
committed
rustc_feature: Separate renamed features from removed features
1 parent 25a54d4 commit abdc8a8

12 files changed

Lines changed: 221 additions & 58 deletions

compiler/rustc_expand/src/config.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use rustc_data_structures::flat_map_in_place::FlatMapInPlace;
1919
use rustc_errors::msg;
2020
use rustc_feature::{
2121
ACCEPTED_LANG_FEATURES, EnabledLangFeature, EnabledLibFeature, Features, REMOVED_LANG_FEATURES,
22-
UNSTABLE_LANG_FEATURES,
22+
RENAMED_LANG_FEATURES, UNSTABLE_LANG_FEATURES,
2323
};
2424
use rustc_hir::attrs::AttributeKind;
2525
use rustc_hir::{
@@ -33,7 +33,7 @@ use tracing::instrument;
3333

3434
use crate::errors::{
3535
CrateNameInCfgAttr, CrateTypeInCfgAttr, FeatureNotAllowed, FeatureRemoved,
36-
FeatureRemovedReason, InvalidCfg, RemoveExprNotSupported,
36+
FeatureRemovedReason, FeatureRenamed, InvalidCfg, RemoveExprNotSupported,
3737
};
3838

3939
/// A folder that strips out items that do not belong in the current configuration.
@@ -81,6 +81,26 @@ pub fn features(sess: &Session, krate_attrs: &[Attribute], crate_name: Symbol) -
8181
continue;
8282
}
8383

84+
// The feature is also removed, but issue a different error message is issued
85+
if let Some(f) =
86+
RENAMED_LANG_FEATURES.iter().find(|f| feature_ident.name == f.feature.name)
87+
{
88+
let pull_note = if let Some(pull) = f.pull {
89+
format!(
90+
"; see <https://github.com/rust-lang/rust/pull/{pull}> for more information",
91+
)
92+
} else {
93+
"".to_owned()
94+
};
95+
sess.dcx().emit_err(FeatureRenamed {
96+
span: feature_ident.span,
97+
new_name: f.new_name,
98+
renamed_rustc_version: f.feature.since,
99+
pull_note,
100+
});
101+
continue;
102+
}
103+
84104
// If the enabled feature is stable, record it.
85105
if let Some(f) = ACCEPTED_LANG_FEATURES.iter().find(|f| feature_ident.name == f.name) {
86106
features.set_enabled_lang_feature(EnabledLangFeature {

compiler/rustc_expand/src/errors.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,23 @@ pub(crate) struct FeatureRemoved<'a> {
156156
pub pull_note: String,
157157
}
158158

159+
#[derive(Diagnostic)]
160+
#[diag("feature was renamed", code = E0557)]
161+
#[note("renamed in {$renamed_rustc_version}{$pull_note}")]
162+
pub(crate) struct FeatureRenamed<'a> {
163+
#[primary_span]
164+
#[suggestion(
165+
"update to the new name",
166+
code = "{new_name}",
167+
applicability = "machine-applicable"
168+
)]
169+
#[label("feature was renamed")]
170+
pub span: Span,
171+
pub new_name: &'a str,
172+
pub renamed_rustc_version: &'a str,
173+
pub pull_note: String,
174+
}
175+
159176
#[derive(Subdiagnostic)]
160177
#[note("{$reason}")]
161178
pub(crate) struct FeatureRemovedReason<'a> {

compiler/rustc_feature/src/lib.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@
1010
//! For the purpose of future feature-tracking, once a feature gate is added,
1111
//! even if it is stabilized or removed, *do not remove it*. Instead, move the
1212
//! symbol to the `accepted` or `removed` modules respectively.
13+
//!
14+
//! If a feature is renamed, move it to the `renamed` module.
1315
1416
mod accepted;
1517
mod builtin_attrs;
1618
mod removed;
19+
mod renamed;
1720
mod unstable;
1821

1922
#[cfg(test)]
@@ -103,6 +106,9 @@ fn find_lang_feature_issue(feature: Symbol) -> Option<NonZero<u32>> {
103106
if let Some(f) = REMOVED_LANG_FEATURES.iter().find(|f| f.feature.name == feature) {
104107
return f.feature.issue;
105108
}
109+
if let Some(f) = RENAMED_LANG_FEATURES.iter().find(|f| f.feature.name == feature) {
110+
return f.feature.issue;
111+
}
106112
panic!("feature `{feature}` is not declared anywhere");
107113
}
108114

@@ -135,7 +141,18 @@ pub use builtin_attrs::{
135141
is_valid_for_get_attr,
136142
};
137143
pub use removed::REMOVED_LANG_FEATURES;
144+
pub use renamed::{RENAMED_LANG_FEATURES, RenamedFeature};
138145
pub use unstable::{
139146
DEPENDENT_FEATURES, EnabledLangFeature, EnabledLibFeature, Features, INCOMPATIBLE_FEATURES,
140147
TRACK_FEATURE, UNSTABLE_LANG_FEATURES,
141148
};
149+
150+
macro_rules! opt_nonzero_u32 {
151+
() => {
152+
None
153+
};
154+
($val:expr) => {
155+
Some(core::num::NonZeroU32::new($val).unwrap())
156+
};
157+
}
158+
pub(crate) use opt_nonzero_u32;

compiler/rustc_feature/src/removed.rs

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,18 @@
11
//! List of the removed feature gates.
22
3-
use std::num::{NonZero, NonZeroU32};
3+
use std::num::NonZero;
44

55
use rustc_span::sym;
66

77
use super::{Feature, to_nonzero};
8+
use crate::opt_nonzero_u32;
89

910
pub struct RemovedFeature {
1011
pub feature: Feature,
1112
pub reason: Option<&'static str>,
1213
pub pull: Option<NonZero<u32>>,
1314
}
1415

15-
macro_rules! opt_nonzero_u32 {
16-
() => {
17-
None
18-
};
19-
($val:expr) => {
20-
Some(NonZeroU32::new($val).unwrap())
21-
};
22-
}
23-
2416
macro_rules! declare_features {
2517
($(
2618
$(#[doc = $doc:tt])* (removed, $feature:ident, $ver:expr, $issue:expr, $reason:expr $(, $pull:expr)?),
@@ -54,7 +46,6 @@ declare_features! (
5446

5547
/// Allows using the `amdgpu-kernel` ABI.
5648
(removed, abi_amdgpu_kernel, "1.77.0", Some(51575), None, 120495),
57-
(removed, abi_c_cmse_nonsecure_call, "1.90.0", Some(81391), Some("renamed to abi_cmse_nonsecure_call"), 142146),
5849
(removed, advanced_slice_patterns, "1.42.0", Some(62254),
5950
Some("merged into `#![feature(slice_patterns)]`"), 67712),
6051
(removed, allocator, "1.0.0", None, None),
@@ -74,8 +65,6 @@ declare_features! (
7465
Some("cannot be allowed in const eval in any meaningful way"), 73398),
7566
/// Allows limiting the evaluation steps of const expressions
7667
(removed, const_eval_limit, "1.72.0", Some(67217), Some("removed the limit entirely"), 103877),
77-
/// Allows non-trivial generic constants which have to be manually propagated upwards.
78-
(removed, const_evaluatable_checked, "1.56.0", Some(76560), Some("renamed to `generic_const_exprs`"), 88369),
7968
/// Allows the definition of `const` functions with some advanced features.
8069
(removed, const_fn, "1.54.0", Some(57563),
8170
Some("split into finer-grained feature gates"), 85109),
@@ -116,11 +105,6 @@ declare_features! (
116105
/// Allows using `doc(primitive)` without a future-incompat warning.
117106
(removed, doc_primitive, "1.58.0", Some(88070),
118107
Some("merged into `#![feature(rustdoc_internals)]`"), 90420),
119-
/// Allows `#[doc(spotlight)]`.
120-
/// The attribute was renamed to `#[doc(notable_trait)]`
121-
/// and the feature to `doc_notable_trait`.
122-
(removed, doc_spotlight, "1.53.0", Some(45040),
123-
Some("renamed to `doc_notable_trait`"), 80965),
124108
/// Allows using `#[unsafe_destructor_blind_to_params]` (RFC 1238).
125109
(removed, dropck_parametricity, "1.38.0", Some(28498), None),
126110
/// Allows making `dyn Trait` well-formed even if `Trait` is not dyn compatible[^1].
@@ -150,10 +134,6 @@ declare_features! (
150134
/// Allows using `#[ffi_returns_twice]` on foreign functions.
151135
(removed, ffi_returns_twice, "1.78.0", Some(58314),
152136
Some("being investigated by the ffi-unwind project group"), 120502),
153-
/// Allows generators to be cloned.
154-
(removed, generator_clone, "1.75.0", Some(95360), Some("renamed to `coroutine_clone`"), 116958),
155-
/// Allows defining generators.
156-
(removed, generators, "1.75.0", Some(43122), Some("renamed to `coroutines`"), 116958),
157137
/// An extension to the `generic_associated_types` feature, allowing incomplete features.
158138
(removed, generic_associated_types_extended, "1.85.0", Some(95451),
159139
Some(
@@ -199,34 +179,20 @@ declare_features! (
199179
(removed, negate_unsigned, "1.0.0", Some(29645), None),
200180
/// Allows diverging expressions to fall back to `!` rather than `()`.
201181
(removed, never_type_fallback, "1.93.0", Some(65992), Some("removed in favor of unconditional fallback"), 148871),
202-
/// Allows `#[no_coverage]` on functions.
203-
/// The feature was renamed to `coverage_attribute` and the attribute to `#[coverage(on|off)]`
204-
(removed, no_coverage, "1.74.0", Some(84605), Some("renamed to `coverage_attribute`"), 114656),
205182
/// Allows `#[no_debug]`.
206183
(removed, no_debug, "1.43.0", Some(29721), Some("removed due to lack of demand"), 69667),
207-
// Allows the use of `no_sanitize` attribute.
208-
/// The feature was renamed to `sanitize` and the attribute to `#[sanitize(xyz = "on|off")]`
209-
(removed, no_sanitize, "1.91.0", Some(39699), Some(r#"renamed to sanitize(xyz = "on|off")"#), 142681),
210184
/// Note: this feature was previously recorded in a separate
211185
/// `STABLE_REMOVED` list because it, uniquely, was once stable but was
212186
/// then removed. But there was no utility storing it separately, so now
213187
/// it's in this list.
214188
(removed, no_stack_check, "1.0.0", None, None, 40110),
215-
/// Allows making `dyn Trait` well-formed even if `Trait` is not dyn compatible (object safe).
216-
/// Renamed to `dyn_compatible_for_dispatch`.
217-
(removed, object_safe_for_dispatch, "1.83.0", Some(43561),
218-
Some("renamed to `dyn_compatible_for_dispatch`"), 131511),
219189
/// Allows using `#[omit_gdb_pretty_printer_section]`.
220190
(removed, omit_gdb_pretty_printer_section, "1.91.0", None, None, 144738),
221191
/// Allows using `#[on_unimplemented(..)]` on traits.
222192
/// (Moved to `rustc_attrs`.)
223193
(removed, on_unimplemented, "1.40.0", None, None, 65794),
224194
/// A way to temporarily opt out of opt-in copy. This will *never* be accepted.
225195
(removed, opt_out_copy, "1.0.0", None, None, 20740),
226-
/// Allows features specific to OIBIT (now called auto traits).
227-
/// Renamed to `auto_traits`.
228-
(removed, optin_builtin_traits, "1.50.0", Some(13231),
229-
Some("renamed to `auto_traits`"), 79336),
230196
/// Allows overlapping impls of marker traits.
231197
(removed, overlapping_marker_traits, "1.42.0", Some(29864),
232198
Some("removed in favor of `#![feature(marker_trait_attr)]`"), 68544),
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
//! List of the renamed feature gates.
2+
3+
use std::num::NonZero;
4+
5+
use rustc_span::sym;
6+
7+
use super::{Feature, to_nonzero};
8+
use crate::opt_nonzero_u32;
9+
10+
pub struct RenamedFeature {
11+
pub feature: Feature,
12+
pub new_name: &'static str,
13+
pub pull: Option<NonZero<u32>>,
14+
}
15+
16+
macro_rules! declare_features {
17+
($(
18+
$(#[doc = $doc:tt])* (renamed, $old_feature_name:ident => $new_feature_name:ident, $ver:expr, $issue:expr $(, $pull:expr)?),
19+
)+) => {
20+
/// Formerly unstable features that have now been renamed.
21+
pub static RENAMED_LANG_FEATURES: &[RenamedFeature] = &[
22+
$(RenamedFeature {
23+
feature: Feature {
24+
name: sym::$old_feature_name,
25+
since: $ver,
26+
issue: to_nonzero($issue),
27+
},
28+
new_name: stringify!($new_feature_name),
29+
pull: opt_nonzero_u32!($($pull)?),
30+
}),+
31+
];
32+
};
33+
}
34+
35+
#[rustfmt::skip]
36+
declare_features! {
37+
// -------------------------------------------------------------------------
38+
// feature-group-start: renamed features
39+
// -------------------------------------------------------------------------
40+
41+
// Note that the version indicates when it got *renamed*.
42+
//
43+
// When moving an unstable feature here, set the version number to
44+
// `CURRENT RUSTC VERSION` with ` ` replaced by `_`.
45+
// (But not all features below do this properly; many indicate the
46+
// version they got originally added in.)
47+
48+
(renamed, abi_c_cmse_nonsecure_call => abi_cmse_nonsecure_call, "1.90.0", Some(81391), 142146),
49+
/// Allows non-trivial generic constants which have to be manually propagated upwards.
50+
(renamed, const_evaluatable_checked => generic_const_exprs, "1.56.0", Some(76560), 88369),
51+
/// Allows `#[doc(spotlight)]`.
52+
/// The attribute was renamed to `#[doc(notable_trait)]`
53+
/// and the feature to `doc_notable_trait`.
54+
(renamed, doc_spotlight => doc_notable_trait, "1.53.0", Some(45040), 80965),
55+
/// Allows generators to be cloned.
56+
(renamed, generator_clone => coroutine_clone, "1.75.0", Some(95360), 116958),
57+
/// Allows defining generators.
58+
(renamed, generators => coroutines, "1.75.0", Some(43122), 116958),
59+
/// Allows `#[no_coverage]` on functions.
60+
/// The feature was renamed to `coverage_attribute` and the attribute to `#[coverage(on|off)]`
61+
(renamed, no_coverage => coverage_attribute, "1.74.0", Some(84605), 114656),
62+
// Allows the use of `no_sanitize` attribute.
63+
/// The feature was renamed to `sanitize` and the attribute to `#[sanitize(xyz = "on|off")]`
64+
(renamed, no_sanitize => sanitize, "1.91.0", Some(39699), 142681),
65+
/// Allows making `dyn Trait` well-formed even if `Trait` is not dyn compatible (object safe).
66+
/// Renamed to `dyn_compatible_for_dispatch`.
67+
(renamed, object_safe_for_dispatch => dyn_compatible_for_dispatch, "1.83.0", Some(43561), 131511),
68+
/// Allows features specific to OIBIT (now called auto traits).
69+
/// Renamed to `auto_traits`.
70+
(renamed, optin_builtin_traits => auto_traits, "1.50.0", Some(13231), 79336),
71+
72+
// -------------------------------------------------------------------------
73+
// feature-group-end: renamed features
74+
// -------------------------------------------------------------------------
75+
76+
77+
// -------------------------------------------------------------------------
78+
// feature-group-start: renamed library features
79+
// -------------------------------------------------------------------------
80+
//
81+
// FIXME(#141617): we should have a better way to track removed library features, but we reuse
82+
// the infrastructure here so users still get hints. The symbols used here can be remove from
83+
// `symbol.rs` when that happens.
84+
85+
// -------------------------------------------------------------------------
86+
// feature-group-end: renamed library features
87+
// -------------------------------------------------------------------------
88+
}

0 commit comments

Comments
 (0)