Skip to content

Commit 6f388bb

Browse files
committed
Auto merge of #88369 - lcnr:cec-rename, r=oli-obk
update const generics feature gates **tl;dr: split const generics into three features: `adt_const_params`, `const_generics_defaults` and `generic_const_exprs`** continuing the work of `@BoxyUwU` in #88324, this PR - renames `feature(const_evaluatable_checked)` to `feature(generic_const_exprs)` which now doesn't need any other feature gate to work. Previously `feature(const_evaluatable_checked)` was only useful in combination with `feature(const_generics)`. - completely removes `feature(lazy_normalization_consts)`. This feature only supplied the parents generics to anonymous constants, which is pretty useless as generic anon consts are only allowed with `feature(generic_const_exprs)` anyways. - moves the ability to use additional const param types from `feature(const_generics)` into `feature(adt_const_params)`. As `feature(const_generics)` is now mostly useless without `feature(generic_const_exprs)` we also remove that feature flag. - updates tests, removing duplicates and unnecessary revisions in some cases and also deletes all unused `*.stderr` files. I not also remove the ordering restriction for const and type parameters if any of the three const generics features is active. This ordering restriction feels like the only "real" use of the current `feature(const_generics)` right now so this change isn't a perfect solution, but as I intend to stabilize the ordering - and `feature(const_generics_defaults)` - in the very near future, I think this is acceptable for now. --- cc `@rust-lang/project-const-generics` about the new feature names and this change in general. I don't think we need any external approval for this change but I do intend to publish an update to the const generics tracking issue the day this PR lands, so I don't want this merged yet. Apologies to whoever ends up reviewing this PR 😅 ❤️ r? rust-lang/project-const-generics
2 parents 5d68044 + 87e7817 commit 6f388bb

File tree

613 files changed

+917
-4514
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

613 files changed

+917
-4514
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,8 +332,8 @@ pub type GenericBounds = Vec<GenericBound>;
332332
pub enum ParamKindOrd {
333333
Lifetime,
334334
Type,
335-
// `unordered` is only `true` if `sess.has_features().const_generics`
336-
// is active. Specifically, if it's only `min_const_generics`, it will still require
335+
// `unordered` is only `true` if `sess.unordered_const_ty_params()`
336+
// returns true. Specifically, if it's only `min_const_generics`, it will still require
337337
// ordering consts after types.
338338
Const { unordered: bool },
339339
// `Infer` is not actually constructed directly from the AST, but is implicitly constructed

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1351,7 +1351,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
13511351
}
13521352

13531353
fn visit_generics(&mut self, generics: &'a Generics) {
1354-
let cg_defaults = self.session.features_untracked().const_generics_defaults;
1354+
let cg_defaults = self.session.features_untracked().unordered_const_ty_params();
13551355

13561356
let mut prev_param_default = None;
13571357
for param in &generics.params {

compiler/rustc_ast_passes/src/feature_gate.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,6 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session) {
687687
gate_all!(trait_alias, "trait aliases are experimental");
688688
gate_all!(associated_type_bounds, "associated type bounds are unstable");
689689
gate_all!(crate_visibility_modifier, "`crate` visibility modifier is experimental");
690-
gate_all!(const_generics, "const generics are unstable");
691690
gate_all!(decl_macro, "`macro` is experimental");
692691
gate_all!(box_patterns, "box pattern syntax is experimental");
693692
gate_all!(exclusive_range_pattern, "exclusive range pattern syntax is experimental");

compiler/rustc_error_codes/src/error_codes/E0671.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ Const parameters cannot depend on type parameters.
44
The following is therefore invalid:
55

66
```compile_fail,E0770
7-
#![feature(const_generics)]
8-
97
fn const_id<T, const N: T>() -> T { // error
108
N
119
}

compiler/rustc_error_codes/src/error_codes/E0741.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ A non-structural-match type was used as the type of a const generic parameter.
33
Erroneous code example:
44

55
```compile_fail,E0741
6-
#![feature(const_generics)]
6+
#![feature(adt_const_params)]
77
88
struct A;
99
@@ -16,7 +16,7 @@ may be used as the types of const generic parameters.
1616
To fix the previous code example, we derive `PartialEq` and `Eq`:
1717

1818
```
19-
#![feature(const_generics)]
19+
#![feature(adt_const_params)]
2020
2121
#[derive(PartialEq, Eq)] // We derive both traits here.
2222
struct A;

compiler/rustc_error_codes/src/error_codes/E0770.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ The type of a const parameter references other generic parameters.
33
Erroneous code example:
44

55
```compile_fail,E0770
6-
#![feature(const_generics)]
76
fn foo<T, const N: T>() {} // error!
87
```
98

compiler/rustc_error_codes/src/error_codes/E0771.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ allowed.
44
Erroneous code example:
55

66
```compile_fail,E0771
7-
#![feature(const_generics)]
7+
#![feature(adt_const_params)]
88
99
fn function_with_str<'a, const STRING: &'a str>() {} // error!
1010
```
@@ -13,7 +13,7 @@ To fix this issue, the lifetime in the const generic need to be changed to
1313
`'static`:
1414

1515
```
16-
#![feature(const_generics)]
16+
#![feature(adt_const_params)]
1717
1818
fn function_with_str<const STRING: &'static str>() {} // ok!
1919
```

compiler/rustc_feature/src/accepted.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ declare_features! (
273273
/// Allows patterns with concurrent by-move and by-ref bindings.
274274
/// For example, you can write `Foo(a, ref b)` where `a` is by-move and `b` is by-ref.
275275
(accepted, move_ref_pattern, "1.49.0", Some(68354), None),
276-
/// The smallest useful subset of `const_generics`.
276+
/// The smallest useful subset of const generics.
277277
(accepted, min_const_generics, "1.51.0", Some(74878), None),
278278
/// The `unsafe_op_in_unsafe_fn` lint (allowed by default): no longer treat an unsafe function as an unsafe block.
279279
(accepted, unsafe_block_in_unsafe_fn, "1.52.0", Some(71668), None),

compiler/rustc_feature/src/active.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ macro_rules! declare_features {
7171
}
7272

7373
pub fn unordered_const_ty_params(&self) -> bool {
74-
self.const_generics || self.const_generics_defaults
74+
self.const_generics_defaults || self.generic_const_exprs || self.adt_const_params
7575
}
7676

7777
/// Some features are known to be incomplete and using them is likely to have
@@ -453,9 +453,6 @@ declare_features! (
453453
/// Allows using `#[ffi_returns_twice]` on foreign functions.
454454
(active, ffi_returns_twice, "1.34.0", Some(58314), None),
455455

456-
/// Allows const generic types (e.g. `struct Foo<const N: usize>(...);`).
457-
(incomplete, const_generics, "1.34.0", Some(44580), None),
458-
459456
/// Allows using `#[optimize(X)]`.
460457
(active, optimize_attribute, "1.34.0", Some(54882), None),
461458

@@ -545,15 +542,9 @@ declare_features! (
545542
/// Allows capturing variables in scope using format_args!
546543
(active, format_args_capture, "1.46.0", Some(67984), None),
547544

548-
/// Lazily evaluate constants. This allows constants to depend on type parameters.
549-
(incomplete, lazy_normalization_consts, "1.46.0", Some(72219), None),
550-
551545
/// Allows `if let` guard in match arms.
552546
(active, if_let_guard, "1.47.0", Some(51114), None),
553547

554-
/// Allows non-trivial generic constants which have to be manually propagated upwards.
555-
(incomplete, const_evaluatable_checked, "1.48.0", Some(76560), None),
556-
557548
/// Allows basic arithmetic on floating point types in a `const fn`.
558549
(active, const_fn_floating_point_arithmetic, "1.48.0", Some(57241), None),
559550

@@ -679,6 +670,12 @@ declare_features! (
679670
/// Allows using doc(primitive) without a future-incompat warning
680671
(active, doc_primitive, "1.56.0", Some(88070), None),
681672

673+
/// Allows non-trivial generic constants which have to have wfness manually propagated to callers
674+
(incomplete, generic_const_exprs, "1.56.0", Some(76560), None),
675+
676+
/// Allows additional const parameter types, such as `&'static str` or user defined types
677+
(incomplete, adt_const_params, "1.56.0", Some(44580), None),
678+
682679
// -------------------------------------------------------------------------
683680
// feature-group-end: actual feature gates
684681
// -------------------------------------------------------------------------

compiler/rustc_feature/src/removed.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ declare_features! (
102102
(removed, extern_in_paths, "1.33.0", Some(55600), None,
103103
Some("subsumed by `::foo::bar` paths")),
104104
(removed, quote, "1.33.0", Some(29601), None, None),
105+
/// Allows const generic types (e.g. `struct Foo<const N: usize>(...);`).
106+
(removed, const_generics, "1.34.0", Some(44580), None,
107+
Some("removed in favor of `#![feature(adt_const_params]` and `#![feature(generic_const_exprs)]`")),
105108
/// Allows `[x; N]` where `x` is a constant (RFC 2203).
106109
(removed, const_in_array_repeat_expressions, "1.37.0", Some(49147), None,
107110
Some("removed due to causing promotable bugs")),
@@ -128,9 +131,13 @@ declare_features! (
128131
Some("Removed in favor of `~const` bound in #![feature(const_trait_impl)]")),
129132
/// Allows `#[no_debug]`.
130133
(removed, no_debug, "1.43.0", Some(29721), None, Some("removed due to lack of demand")),
134+
/// Lazily evaluate constants. This allows constants to depend on type parameters.
135+
(removed, lazy_normalization_consts, "1.46.0", Some(72219), None, Some("superseded by `generic_const_exprs`")),
131136
/// Allows comparing raw pointers during const eval.
132137
(removed, const_compare_raw_pointers, "1.46.0", Some(53020), None,
133138
Some("cannot be allowed in const eval in any meaningful way")),
139+
/// Allows non-trivial generic constants which have to be manually propagated upwards.
140+
(removed, const_evaluatable_checked, "1.48.0", Some(76560), None, Some("renamed to `generic_const_exprs`")),
134141
/// Allows using the `#[link_args]` attribute.
135142
(removed, link_args, "1.53.0", Some(29596), None,
136143
Some("removed in favor of using `-C link-arg=ARG` on command line, \

0 commit comments

Comments
 (0)