Skip to content

Commit 0c28e02

Browse files
committed
feature(const_generics) -> feature(const_param_types)
1 parent c0e853f commit 0c28e02

File tree

574 files changed

+849
-4305
lines changed

Some content is hidden

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

574 files changed

+849
-4305
lines changed

Diff for: compiler/rustc_ast/src/ast.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ pub type GenericBounds = Vec<GenericBound>;
332332
pub enum ParamKindOrd {
333333
Lifetime,
334334
Type,
335-
// `unordered` is only `true` if `sess.has_features().const_generics`
335+
// `unordered` is only `true` if `sess.has_features().const_generics_defaults`
336336
// is active. Specifically, if it's only `min_const_generics`, it will still require
337337
// ordering consts after types.
338338
Const { unordered: bool },

Diff for: compiler/rustc_ast_passes/src/feature_gate.rs

-1
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");

Diff for: compiler/rustc_error_codes/src/error_codes/E0671.md

-2
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
}

Diff for: compiler/rustc_error_codes/src/error_codes/E0741.md

+2-2
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(const_param_types)]
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(const_param_types)]
2020
2121
#[derive(PartialEq, Eq)] // We derive both traits here.
2222
struct A;

Diff for: compiler/rustc_error_codes/src/error_codes/E0770.md

-1
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

Diff for: compiler/rustc_error_codes/src/error_codes/E0771.md

+2-2
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(const_param_types)]
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(const_param_types)]
1717
1818
fn function_with_str<const STRING: &'static str>() {} // ok!
1919
```

Diff for: compiler/rustc_feature/src/accepted.rs

+1-1
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),

Diff for: compiler/rustc_feature/src/active.rs

+4-4
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
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

@@ -676,6 +673,9 @@ declare_features! (
676673
/// Allows non-trivial generic constants which have to have wfness manually propagated to callers
677674
(incomplete, generic_const_exprs, "1.56.0", Some(76560), None),
678675

676+
/// Allows additional const parameter types, such as `&'static str` or user defined types
677+
(incomplete, const_param_types, "1.56.0", Some(44580), None),
678+
679679
// -------------------------------------------------------------------------
680680
// feature-group-end: actual feature gates
681681
// -------------------------------------------------------------------------

Diff for: compiler/rustc_feature/src/removed.rs

+3
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(const_param_types]` 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")),

Diff for: compiler/rustc_infer/src/infer/combine.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ impl<'infcx, 'tcx> InferCtxt<'infcx, 'tcx> {
202202
/// A good example of this is the following:
203203
///
204204
/// ```rust
205-
/// #![feature(const_generics)]
205+
/// #![feature(generic_const_exprs)]
206206
///
207207
/// fn bind<const N: usize>(value: [u8; N]) -> [u8; 3 + 4] {
208208
/// todo!()

Diff for: compiler/rustc_lint/src/builtin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2340,7 +2340,7 @@ declare_lint! {
23402340
/// ### Example
23412341
///
23422342
/// ```rust
2343-
/// #![feature(const_generics)]
2343+
/// #![feature(generic_const_exprs)]
23442344
/// ```
23452345
///
23462346
/// {{produces}}

Diff for: compiler/rustc_middle/src/ty/context.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1420,8 +1420,8 @@ impl<'tcx> TyCtxt<'tcx> {
14201420
#[inline]
14211421
pub fn lazy_normalization(self) -> bool {
14221422
let features = self.features();
1423-
// Note: We do not enable lazy normalization for `min_const_generics`.
1424-
features.const_generics || features.generic_const_exprs
1423+
// Note: We only use lazy normalization for generic const expressions.
1424+
features.generic_const_exprs
14251425
}
14261426

14271427
#[inline]

Diff for: compiler/rustc_resolve/src/diagnostics.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -506,8 +506,7 @@ impl<'a> Resolver<'a> {
506506

507507
if self.session.is_nightly_build() {
508508
err.help(
509-
"use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` \
510-
to allow generic const expressions",
509+
"use `#![feature(generic_const_exprs)]` to allow generic const expressions",
511510
);
512511
}
513512

Diff for: compiler/rustc_resolve/src/late/diagnostics.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2245,7 +2245,7 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
22452245
}
22462246

22472247
/// Non-static lifetimes are prohibited in anonymous constants under `min_const_generics`.
2248-
/// This function will emit an error if `const_generics` is not enabled, the body identified by
2248+
/// This function will emit an error if `generic_const_exprs` is not enabled, the body identified by
22492249
/// `body_id` is an anonymous constant and `lifetime_ref` is non-static.
22502250
crate fn maybe_emit_forbidden_non_static_lifetime_error(
22512251
&self,
@@ -2264,7 +2264,7 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
22642264
if !self.tcx.lazy_normalization() && is_anon_const && !is_allowed_lifetime {
22652265
feature_err(
22662266
&self.tcx.sess.parse_sess,
2267-
sym::const_generics,
2267+
sym::generic_const_exprs,
22682268
lifetime_ref.span,
22692269
"a non-static lifetime is not allowed in a `const`",
22702270
)

Diff for: compiler/rustc_resolve/src/late/lifetimes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2301,7 +2301,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
23012301
match *scope {
23022302
Scope::Body { id, s } => {
23032303
// Non-static lifetimes are prohibited in anonymous constants without
2304-
// `const_generics`.
2304+
// `generic_const_exprs`.
23052305
self.maybe_emit_forbidden_non_static_lifetime_error(id, lifetime_ref);
23062306

23072307
outermost_body = Some(id);

Diff for: compiler/rustc_resolve/src/lib.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -2734,8 +2734,7 @@ impl<'a> Resolver<'a> {
27342734
ConstantItemRibKind(trivial, _) => {
27352735
let features = self.session.features_untracked();
27362736
// HACK(min_const_generics): We currently only allow `N` or `{ N }`.
2737-
if !(trivial || features.const_generics || features.generic_const_exprs)
2738-
{
2737+
if !(trivial || features.generic_const_exprs) {
27392738
// HACK(min_const_generics): If we encounter `Self` in an anonymous constant
27402739
// we can't easily tell if it's generic at this stage, so we instead remember
27412740
// this and then enforce the self type to be concrete later on.
@@ -2807,8 +2806,7 @@ impl<'a> Resolver<'a> {
28072806
ConstantItemRibKind(trivial, _) => {
28082807
let features = self.session.features_untracked();
28092808
// HACK(min_const_generics): We currently only allow `N` or `{ N }`.
2810-
if !(trivial || features.const_generics || features.generic_const_exprs)
2811-
{
2809+
if !(trivial || features.generic_const_exprs) {
28122810
if record_used {
28132811
self.report_error(
28142812
span,

Diff for: compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,7 @@ symbols! {
451451
const_mut_refs,
452452
const_panic,
453453
const_panic_fmt,
454+
const_param_types,
454455
const_precise_live_drops,
455456
const_ptr,
456457
const_raw_ptr_deref,

Diff for: compiler/rustc_typeck/src/check/wfcheck.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) {
290290

291291
let err_ty_str;
292292
let mut is_ptr = true;
293-
let err = if tcx.features().const_generics {
293+
let err = if tcx.features().const_param_types {
294294
match ty.peel_refs().kind() {
295295
ty::FnPtr(_) => Some("function pointers"),
296296
ty::RawPtr(_) => Some("raw pointers"),
@@ -328,7 +328,7 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) {
328328
err.note("the only supported types are integers, `bool` and `char`");
329329
if tcx.sess.is_nightly_build() {
330330
err.help(
331-
"more complex types are supported with `#![feature(const_generics)]`",
331+
"more complex types are supported with `#![feature(const_param_types)]`",
332332
);
333333
}
334334
err.emit()

Diff for: compiler/rustc_typeck/src/collect.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1489,7 +1489,7 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
14891489
}
14901490

14911491
// HACK(eddyb) this provides the correct generics when
1492-
// `feature(const_generics)` is enabled, so that const expressions
1492+
// `feature(generic_const_expressions)` is enabled, so that const expressions
14931493
// used with const generics, e.g. `Foo<{N+1}>`, can work at all.
14941494
//
14951495
// Note that we do not supply the parent generics when using

Diff for: src/test/debuginfo/function-names.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@
8282
#![allow(unused_variables)]
8383
#![feature(omit_gdb_pretty_printer_section)]
8484
#![omit_gdb_pretty_printer_section]
85-
#![feature(const_generics, generators, generator_trait)]
86-
#![allow(incomplete_features)] // for const_generics
85+
#![feature(const_param_types, generators, generator_trait)]
86+
#![allow(incomplete_features)]
8787

8888
use Mod1::TestTrait2;
8989
use std::ops::Generator;

Diff for: src/test/incremental/const-generics/hash-tyvid-regression-1.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// revisions: cfail
2-
#![feature(const_generics, generic_const_exprs)]
2+
#![feature(generic_const_exprs, const_param_types)]
33
#![allow(incomplete_features)]
44
// regression test for #77650
55
fn c<T, const N: std::num::NonZeroUsize>()

Diff for: src/test/incremental/const-generics/hash-tyvid-regression-1.stderr

-35
This file was deleted.

Diff for: src/test/incremental/const-generics/hash-tyvid-regression-2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// revisions: cfail
2-
#![feature(const_generics, generic_const_exprs)]
2+
#![feature(generic_const_exprs, const_param_types, const_generics_defaults)]
33
#![allow(incomplete_features)]
44
// regression test for #77650
55
struct C<T, const N: core::num::NonZeroUsize>([T; N.get()])

Diff for: src/test/incremental/const-generics/hash-tyvid-regression-2.stderr

-11
This file was deleted.

Diff for: src/test/incremental/const-generics/hash-tyvid-regression-3.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// revisions: cfail
2-
#![feature(const_generics, generic_const_exprs)]
2+
#![feature(generic_const_exprs)]
33
#![allow(incomplete_features)]
44
// regression test for #79251
55
struct Node<const D: usize>

Diff for: src/test/incremental/const-generics/hash-tyvid-regression-3.stderr

-12
This file was deleted.

Diff for: src/test/incremental/const-generics/hash-tyvid-regression-4.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// revisions: cfail
2-
#![feature(const_generics, generic_const_exprs)]
2+
#![feature(generic_const_exprs)]
33
#![allow(incomplete_features)]
44
// regression test for #79251
55
#[derive(Debug)]

Diff for: src/test/incremental/const-generics/hash-tyvid-regression-4.stderr

-12
This file was deleted.

Diff for: src/test/incremental/const-generics/issue-61338.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// revisions:rpass1
22

3-
#![feature(const_generics)]
4-
53
struct Struct<T>(T);
64

75
impl<T, const N: usize> Struct<[T; N]> {

Diff for: src/test/incremental/const-generics/issue-61516.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// revisions:rpass1
22

3-
#![feature(const_generics)]
4-
53
struct FakeArray<T, const N: usize>(T);
64

75
impl<T, const N: usize> FakeArray<T, N> {

Diff for: src/test/incremental/const-generics/issue-62536.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
// revisions:cfail1
2-
#![feature(const_generics)]
3-
//[cfail1]~^ WARN the feature `const_generics` is incomplete
4-
52
struct S<T, const N: usize>([T; N]);
63

74
fn f<T, const N: usize>(x: T) -> S<T, {N}> { panic!() }

Diff for: src/test/incremental/const-generics/issue-64087.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
// revisions:cfail1
2-
#![feature(const_generics)]
3-
//[cfail1]~^ WARN the feature `const_generics` is incomplete
42

53
fn combinator<T, const S: usize>() -> [T; S] {}
64
//[cfail1]~^ ERROR mismatched types

Diff for: src/test/incremental/const-generics/issue-65623.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
// revisions:rpass1
2-
#![feature(const_generics)]
3-
42
pub struct Foo<T, const N: usize>([T; 0]);
53

64
impl<T, const N: usize> Foo<T, {N}> {

Diff for: src/test/incremental/const-generics/issue-68477.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// edition:2018
22
// revisions:rpass1
3-
#![feature(const_generics)]
3+
4+
// Needed to supply generic arguments to the anon const in `[(); FOO]`.
5+
#![feature(generic_const_exprs)]
46

57
const FOO: usize = 1;
68

0 commit comments

Comments
 (0)