Skip to content

Commit 11ebd80

Browse files
committed
Make incomplete features part of delcaration
This prevents mistakes where the feature is in the list of incomplete features but not actually a feature by making the incompleteness a part of the declaration.
1 parent 1abb5bc commit 11ebd80

File tree

6 files changed

+40
-56
lines changed

6 files changed

+40
-56
lines changed

compiler/rustc_feature/src/active.rs

+37-43
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,14 @@ macro_rules! set {
1616
}
1717

1818
macro_rules! declare_features {
19+
(__status_to_bool active) => {
20+
false
21+
};
22+
(__status_to_bool incomplete) => {
23+
true
24+
};
1925
($(
20-
$(#[doc = $doc:tt])* (active, $feature:ident, $ver:expr, $issue:expr, $edition:expr),
26+
$(#[doc = $doc:tt])* ($status:ident, $feature:ident, $ver:expr, $issue:expr, $edition:expr),
2127
)+) => {
2228
/// Represents active features that are currently being implemented or
2329
/// currently being considered for addition/removal.
@@ -67,6 +73,18 @@ macro_rules! declare_features {
6773
pub fn unordered_const_ty_params(&self) -> bool {
6874
self.const_generics || self.const_generics_defaults
6975
}
76+
77+
/// Some features are known to be incomplete and using them is likely to have
78+
/// unanticipated results, such as compiler crashes. We warn the user about these
79+
/// to alert them.
80+
pub fn incomplete(&self, feature: Symbol) -> bool {
81+
match feature {
82+
$(
83+
sym::$feature => declare_features!(__status_to_bool $status),
84+
)*
85+
_ => false,
86+
}
87+
}
7088
}
7189
};
7290
}
@@ -305,7 +323,7 @@ declare_features! (
305323
(active, cfg_target_thread_local, "1.7.0", Some(29594), None),
306324

307325
/// Allows specialization of implementations (RFC 1210).
308-
(active, specialization, "1.7.0", Some(31844), None),
326+
(incomplete, specialization, "1.7.0", Some(31844), None),
309327

310328
/// A minimal, sound subset of specialization intended to be used by the
311329
/// standard library until the soundness issues with specialization
@@ -342,7 +360,7 @@ declare_features! (
342360
(active, abi_ptx, "1.15.0", Some(38788), None),
343361

344362
/// Allows the `#[repr(i128)]` attribute for enums.
345-
(active, repr128, "1.16.0", Some(56071), None),
363+
(incomplete, repr128, "1.16.0", Some(56071), None),
346364

347365
/// Allows `#[link(kind="static-nobundle"...)]`.
348366
(active, static_nobundle, "1.16.0", Some(37403), None),
@@ -384,7 +402,7 @@ declare_features! (
384402
(active, in_band_lifetimes, "1.23.0", Some(44524), None),
385403

386404
/// Allows associated types to be generic, e.g., `type Foo<T>;` (RFC 1598).
387-
(active, generic_associated_types, "1.23.0", Some(44265), None),
405+
(incomplete, generic_associated_types, "1.23.0", Some(44265), None),
388406

389407
/// Allows defining `trait X = A + B;` alias items.
390408
(active, trait_alias, "1.24.0", Some(41517), None),
@@ -429,7 +447,7 @@ declare_features! (
429447
(active, proc_macro_hygiene, "1.30.0", Some(54727), None),
430448

431449
/// Allows unsized rvalues at arguments and parameters.
432-
(active, unsized_locals, "1.30.0", Some(48055), None),
450+
(incomplete, unsized_locals, "1.30.0", Some(48055), None),
433451

434452
/// Allows custom test frameworks with `#![test_runner]` and `#[test_case]`.
435453
(active, custom_test_frameworks, "1.30.0", Some(50297), None),
@@ -438,7 +456,7 @@ declare_features! (
438456
(active, custom_inner_attributes, "1.30.0", Some(54726), None),
439457

440458
/// Allows `impl Trait` in bindings (`let`, `const`, `static`).
441-
(active, impl_trait_in_bindings, "1.30.0", Some(63065), None),
459+
(incomplete, impl_trait_in_bindings, "1.30.0", Some(63065), None),
442460

443461
/// Allows using `reason` in lint attributes and the `#[expect(lint)]` lint check.
444462
(active, lint_reasons, "1.31.0", Some(54503), None),
@@ -450,7 +468,7 @@ declare_features! (
450468
(active, ffi_returns_twice, "1.34.0", Some(58314), None),
451469

452470
/// Allows const generic types (e.g. `struct Foo<const N: usize>(...);`).
453-
(active, const_generics, "1.34.0", Some(44580), None),
471+
(incomplete, const_generics, "1.34.0", Some(44580), None),
454472

455473
/// Allows using `#[optimize(X)]`.
456474
(active, optimize_attribute, "1.34.0", Some(54882), None),
@@ -462,7 +480,7 @@ declare_features! (
462480
(active, associated_type_bounds, "1.34.0", Some(52662), None),
463481

464482
/// Allows `if/while p && let q = r && ...` chains.
465-
(active, let_chains, "1.37.0", Some(53667), None),
483+
(incomplete, let_chains, "1.37.0", Some(53667), None),
466484

467485
/// Allows #[repr(transparent)] on unions (RFC 2645).
468486
(active, transparent_unions, "1.37.0", Some(60405), None),
@@ -474,13 +492,13 @@ declare_features! (
474492
(active, async_closure, "1.37.0", Some(62290), None),
475493

476494
/// Allows `impl Trait` to be used inside type aliases (RFC 2515).
477-
(active, type_alias_impl_trait, "1.38.0", Some(63063), None),
495+
(incomplete, type_alias_impl_trait, "1.38.0", Some(63063), None),
478496

479497
/// Allows the definition of `const extern fn` and `const unsafe extern fn`.
480498
(active, const_extern_fn, "1.40.0", Some(64926), None),
481499

482500
/// Allows the use of raw-dylibs (RFC 2627).
483-
(active, raw_dylib, "1.40.0", Some(58713), None),
501+
(incomplete, raw_dylib, "1.40.0", Some(58713), None),
484502

485503
/// Allows making `dyn Trait` well-formed even if `Trait` is not object safe.
486504
/// In that case, `dyn Trait: Trait` does not hold. Moreover, coercions and
@@ -516,10 +534,10 @@ declare_features! (
516534
(active, bindings_after_at, "1.41.0", Some(65490), None),
517535

518536
/// Allows `impl const Trait for T` syntax.
519-
(active, const_trait_impl, "1.42.0", Some(67792), None),
537+
(incomplete, const_trait_impl, "1.42.0", Some(67792), None),
520538

521539
/// Allows `T: ?const Trait` syntax in bounds.
522-
(active, const_trait_bound_opt_out, "1.42.0", Some(67794), None),
540+
(incomplete, const_trait_bound_opt_out, "1.42.0", Some(67794), None),
523541

524542
/// Allows the use of `no_sanitize` attribute.
525543
(active, no_sanitize, "1.42.0", Some(39699), None),
@@ -552,16 +570,16 @@ declare_features! (
552570
(active, format_args_capture, "1.46.0", Some(67984), None),
553571

554572
/// Lazily evaluate constants. This allows constants to depend on type parameters.
555-
(active, lazy_normalization_consts, "1.46.0", Some(72219), None),
573+
(incomplete, lazy_normalization_consts, "1.46.0", Some(72219), None),
556574

557575
/// Allows calling `transmute` in const fn
558576
(active, const_fn_transmute, "1.46.0", Some(53605), None),
559577

560578
/// Allows `if let` guard in match arms.
561-
(active, if_let_guard, "1.47.0", Some(51114), None),
579+
(incomplete, if_let_guard, "1.47.0", Some(51114), None),
562580

563581
/// Allows non-trivial generic constants which have to be manually propagated upwards.
564-
(active, const_evaluatable_checked, "1.48.0", Some(76560), None),
582+
(incomplete, const_evaluatable_checked, "1.48.0", Some(76560), None),
565583

566584
/// Allows basic arithmetic on floating point types in a `const fn`.
567585
(active, const_fn_floating_point_arithmetic, "1.48.0", Some(57241), None),
@@ -582,7 +600,7 @@ declare_features! (
582600
(active, isa_attribute, "1.48.0", Some(74727), None),
583601

584602
/// Allow anonymous constants from an inline `const` block
585-
(active, inline_const, "1.49.0", Some(76001), None),
603+
(incomplete, inline_const, "1.49.0", Some(76001), None),
586604

587605
/// Allows unsized fn parameters.
588606
(active, unsized_fn_params, "1.49.0", Some(48055), None),
@@ -594,7 +612,7 @@ declare_features! (
594612
(active, cfg_panic, "1.49.0", Some(77443), None),
595613

596614
/// Allows capturing disjoint fields in a closure/generator (RFC 2229).
597-
(active, capture_disjoint_fields, "1.49.0", Some(53488), None),
615+
(incomplete, capture_disjoint_fields, "1.49.0", Some(53488), None),
598616

599617
/// Allows const generics to have default values (e.g. `struct Foo<const N: usize = 3>(...);`).
600618
(active, const_generics_defaults, "1.51.0", Some(44580), None),
@@ -618,7 +636,7 @@ declare_features! (
618636
(active, min_type_alias_impl_trait, "1.52.0", Some(63063), None),
619637

620638
/// Allows associated types in inherent impls.
621-
(active, inherent_associated_types, "1.52.0", Some(8995), None),
639+
(incomplete, inherent_associated_types, "1.52.0", Some(8995), None),
622640

623641
// Allows setting the threshold for the `large_assignments` lint.
624642
(active, large_assignments, "1.52.0", Some(83518), None),
@@ -661,7 +679,7 @@ declare_features! (
661679
(active, native_link_modifiers_as_needed, "1.53.0", Some(81490), None),
662680

663681
/// Allows unnamed fields of struct and union type
664-
(active, unnamed_fields, "1.53.0", Some(49804), None),
682+
(incomplete, unnamed_fields, "1.53.0", Some(49804), None),
665683

666684
/// Allows qualified paths in struct expressions, struct patterns and tuple struct patterns.
667685
(active, more_qualified_paths, "1.54.0", Some(80080), None),
@@ -671,30 +689,6 @@ declare_features! (
671689
// -------------------------------------------------------------------------
672690
);
673691

674-
/// Some features are known to be incomplete and using them is likely to have
675-
/// unanticipated results, such as compiler crashes. We warn the user about these
676-
/// to alert them.
677-
pub const INCOMPLETE_FEATURES: &[Symbol] = &[
678-
sym::if_let_guard,
679-
sym::impl_trait_in_bindings,
680-
sym::generic_associated_types,
681-
sym::const_generics,
682-
sym::let_chains,
683-
sym::raw_dylib,
684-
sym::const_evaluatable_checked,
685-
sym::const_trait_impl,
686-
sym::const_trait_bound_opt_out,
687-
sym::lazy_normalization_consts,
688-
sym::specialization,
689-
sym::inline_const,
690-
sym::repr128,
691-
sym::unsized_locals,
692-
sym::capture_disjoint_fields,
693-
sym::inherent_associated_types,
694-
sym::type_alias_impl_trait,
695-
sym::unnamed_fields,
696-
];
697-
698692
/// Some features are not allowed to be used together at the same time, if
699693
/// the two are present, produce an error.
700694
///

compiler/rustc_feature/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ pub fn find_feature_issue(feature: Symbol, issue: GateIssue) -> Option<NonZeroU3
146146
}
147147

148148
pub use accepted::ACCEPTED_FEATURES;
149-
pub use active::{Features, ACTIVE_FEATURES, INCOMPATIBLE_FEATURES, INCOMPLETE_FEATURES};
149+
pub use active::{Features, ACTIVE_FEATURES, INCOMPATIBLE_FEATURES};
150150
pub use builtin_attrs::{
151151
deprecated_attributes, find_gated_cfg, is_builtin_attr_name, AttributeGate, AttributeTemplate,
152152
AttributeType, BuiltinAttribute, GatedCfg, BUILTIN_ATTRIBUTES, BUILTIN_ATTRIBUTE_MAP,

compiler/rustc_lint/src/builtin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2327,7 +2327,7 @@ impl EarlyLintPass for IncompleteFeatures {
23272327
.iter()
23282328
.map(|(name, span, _)| (name, span))
23292329
.chain(features.declared_lib_features.iter().map(|(name, span)| (name, span)))
2330-
.filter(|(name, _)| rustc_feature::INCOMPLETE_FEATURES.iter().any(|f| name == &f))
2330+
.filter(|(&name, _)| features.incomplete(name))
23312331
.for_each(|(&name, &span)| {
23322332
cx.struct_span_lint(INCOMPLETE_FEATURES, span, |lint| {
23332333
let mut builder = lint.build(&format!(

src/test/ui/feature-gates/rustc_insignificant_dtor.rs

-2
This file was deleted.

src/test/ui/feature-gates/rustc_insignificant_dtor.stderr

-9
This file was deleted.

src/tools/tidy/src/features.rs

+1
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ fn collect_lang_features_in(base: &Path, file: &str, bad: &mut bool) -> Features
301301
let mut parts = line.split(',');
302302
let level = match parts.next().map(|l| l.trim().trim_start_matches('(')) {
303303
Some("active") => Status::Unstable,
304+
Some("incomplete") => Status::Unstable,
304305
Some("removed") => Status::Removed,
305306
Some("accepted") => Status::Stable,
306307
_ => return None,

0 commit comments

Comments
 (0)