Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update const generics feature gates #88369

Merged
merged 5 commits into from
Aug 31, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Prev Previous commit
Next Next commit
feature(const_generics) -> feature(const_param_types)
  • Loading branch information
lcnr committed Aug 30, 2021
commit 0c28e028b6f45f33447f24de7dd762b8599b7a4e
2 changes: 1 addition & 1 deletion compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ pub type GenericBounds = Vec<GenericBound>;
pub enum ParamKindOrd {
Lifetime,
Type,
// `unordered` is only `true` if `sess.has_features().const_generics`
// `unordered` is only `true` if `sess.has_features().const_generics_defaults`
// is active. Specifically, if it's only `min_const_generics`, it will still require
// ordering consts after types.
Const { unordered: bool },
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,6 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session) {
gate_all!(trait_alias, "trait aliases are experimental");
gate_all!(associated_type_bounds, "associated type bounds are unstable");
gate_all!(crate_visibility_modifier, "`crate` visibility modifier is experimental");
gate_all!(const_generics, "const generics are unstable");
estebank marked this conversation as resolved.
Show resolved Hide resolved
gate_all!(decl_macro, "`macro` is experimental");
gate_all!(box_patterns, "box pattern syntax is experimental");
gate_all!(exclusive_range_pattern, "exclusive range pattern syntax is experimental");
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_error_codes/src/error_codes/E0671.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ Const parameters cannot depend on type parameters.
The following is therefore invalid:

```compile_fail,E0770
#![feature(const_generics)]

fn const_id<T, const N: T>() -> T { // error
N
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_error_codes/src/error_codes/E0741.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ A non-structural-match type was used as the type of a const generic parameter.
Erroneous code example:

```compile_fail,E0741
#![feature(const_generics)]
#![feature(const_param_types)]

struct A;

Expand All @@ -16,7 +16,7 @@ may be used as the types of const generic parameters.
To fix the previous code example, we derive `PartialEq` and `Eq`:

```
#![feature(const_generics)]
#![feature(const_param_types)]

#[derive(PartialEq, Eq)] // We derive both traits here.
struct A;
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_error_codes/src/error_codes/E0770.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ The type of a const parameter references other generic parameters.
Erroneous code example:

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

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_error_codes/src/error_codes/E0771.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ allowed.
Erroneous code example:

```compile_fail,E0771
#![feature(const_generics)]
#![feature(const_param_types)]

fn function_with_str<'a, const STRING: &'a str>() {} // error!
```
Expand All @@ -13,7 +13,7 @@ To fix this issue, the lifetime in the const generic need to be changed to
`'static`:

```
#![feature(const_generics)]
#![feature(const_param_types)]

fn function_with_str<const STRING: &'static str>() {} // ok!
```
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_feature/src/accepted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ declare_features! (
/// Allows patterns with concurrent by-move and by-ref bindings.
/// For example, you can write `Foo(a, ref b)` where `a` is by-move and `b` is by-ref.
(accepted, move_ref_pattern, "1.49.0", Some(68354), None),
/// The smallest useful subset of `const_generics`.
/// The smallest useful subset of const generics.
(accepted, min_const_generics, "1.51.0", Some(74878), None),
/// The `unsafe_op_in_unsafe_fn` lint (allowed by default): no longer treat an unsafe function as an unsafe block.
(accepted, unsafe_block_in_unsafe_fn, "1.52.0", Some(71668), None),
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_feature/src/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ macro_rules! declare_features {
}

pub fn unordered_const_ty_params(&self) -> bool {
self.const_generics || self.const_generics_defaults
self.const_generics_defaults
}

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

/// Allows const generic types (e.g. `struct Foo<const N: usize>(...);`).
(incomplete, const_generics, "1.34.0", Some(44580), None),

/// Allows using `#[optimize(X)]`.
(active, optimize_attribute, "1.34.0", Some(54882), None),

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

/// Allows additional const parameter types, such as `&'static str` or user defined types
(incomplete, const_param_types, "1.56.0", Some(44580), None),

// -------------------------------------------------------------------------
// feature-group-end: actual feature gates
// -------------------------------------------------------------------------
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_feature/src/removed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ declare_features! (
(removed, extern_in_paths, "1.33.0", Some(55600), None,
Some("subsumed by `::foo::bar` paths")),
(removed, quote, "1.33.0", Some(29601), None, None),
/// Allows const generic types (e.g. `struct Foo<const N: usize>(...);`).
(removed, const_generics, "1.34.0", Some(44580), None,
Some("removed in favor of `#![feature(const_param_types]` and `#![feature(generic_const_exprs)]`")),
/// Allows `[x; N]` where `x` is a constant (RFC 2203).
(removed, const_in_array_repeat_expressions, "1.37.0", Some(49147), None,
Some("removed due to causing promotable bugs")),
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_infer/src/infer/combine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ impl<'infcx, 'tcx> InferCtxt<'infcx, 'tcx> {
/// A good example of this is the following:
///
/// ```rust
/// #![feature(const_generics)]
/// #![feature(generic_const_exprs)]
///
/// fn bind<const N: usize>(value: [u8; N]) -> [u8; 3 + 4] {
/// todo!()
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2340,7 +2340,7 @@ declare_lint! {
/// ### Example
///
/// ```rust
/// #![feature(const_generics)]
/// #![feature(generic_const_exprs)]
/// ```
///
/// {{produces}}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1420,8 +1420,8 @@ impl<'tcx> TyCtxt<'tcx> {
#[inline]
pub fn lazy_normalization(self) -> bool {
let features = self.features();
// Note: We do not enable lazy normalization for `min_const_generics`.
features.const_generics || features.generic_const_exprs
// Note: We only use lazy normalization for generic const expressions.
features.generic_const_exprs
}

#[inline]
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -506,8 +506,7 @@ impl<'a> Resolver<'a> {

if self.session.is_nightly_build() {
err.help(
"use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` \
to allow generic const expressions",
"use `#![feature(generic_const_exprs)]` to allow generic const expressions",
);
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_resolve/src/late/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2245,7 +2245,7 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
}

/// Non-static lifetimes are prohibited in anonymous constants under `min_const_generics`.
/// This function will emit an error if `const_generics` is not enabled, the body identified by
/// This function will emit an error if `generic_const_exprs` is not enabled, the body identified by
/// `body_id` is an anonymous constant and `lifetime_ref` is non-static.
crate fn maybe_emit_forbidden_non_static_lifetime_error(
&self,
Expand All @@ -2264,7 +2264,7 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
if !self.tcx.lazy_normalization() && is_anon_const && !is_allowed_lifetime {
feature_err(
&self.tcx.sess.parse_sess,
sym::const_generics,
sym::generic_const_exprs,
lifetime_ref.span,
"a non-static lifetime is not allowed in a `const`",
)
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_resolve/src/late/lifetimes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2301,7 +2301,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
match *scope {
Scope::Body { id, s } => {
// Non-static lifetimes are prohibited in anonymous constants without
// `const_generics`.
// `generic_const_exprs`.
self.maybe_emit_forbidden_non_static_lifetime_error(id, lifetime_ref);

outermost_body = Some(id);
Expand Down
6 changes: 2 additions & 4 deletions compiler/rustc_resolve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2734,8 +2734,7 @@ impl<'a> Resolver<'a> {
ConstantItemRibKind(trivial, _) => {
let features = self.session.features_untracked();
// HACK(min_const_generics): We currently only allow `N` or `{ N }`.
if !(trivial || features.const_generics || features.generic_const_exprs)
{
if !(trivial || features.generic_const_exprs) {
// HACK(min_const_generics): If we encounter `Self` in an anonymous constant
// we can't easily tell if it's generic at this stage, so we instead remember
// this and then enforce the self type to be concrete later on.
Expand Down Expand Up @@ -2807,8 +2806,7 @@ impl<'a> Resolver<'a> {
ConstantItemRibKind(trivial, _) => {
let features = self.session.features_untracked();
// HACK(min_const_generics): We currently only allow `N` or `{ N }`.
if !(trivial || features.const_generics || features.generic_const_exprs)
{
if !(trivial || features.generic_const_exprs) {
if record_used {
self.report_error(
span,
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ symbols! {
const_mut_refs,
const_panic,
const_panic_fmt,
const_param_types,
const_precise_live_drops,
const_ptr,
const_raw_ptr_deref,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_typeck/src/check/wfcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) {

let err_ty_str;
let mut is_ptr = true;
let err = if tcx.features().const_generics {
let err = if tcx.features().const_param_types {
match ty.peel_refs().kind() {
ty::FnPtr(_) => Some("function pointers"),
ty::RawPtr(_) => Some("raw pointers"),
Expand Down Expand Up @@ -328,7 +328,7 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) {
err.note("the only supported types are integers, `bool` and `char`");
if tcx.sess.is_nightly_build() {
err.help(
"more complex types are supported with `#![feature(const_generics)]`",
"more complex types are supported with `#![feature(const_param_types)]`",
);
}
err.emit()
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_typeck/src/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1489,7 +1489,7 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
}

// HACK(eddyb) this provides the correct generics when
// `feature(const_generics)` is enabled, so that const expressions
// `feature(generic_const_expressions)` is enabled, so that const expressions
// used with const generics, e.g. `Foo<{N+1}>`, can work at all.
//
// Note that we do not supply the parent generics when using
Expand Down
4 changes: 2 additions & 2 deletions src/test/debuginfo/function-names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@
#![allow(unused_variables)]
#![feature(omit_gdb_pretty_printer_section)]
#![omit_gdb_pretty_printer_section]
#![feature(const_generics, generators, generator_trait)]
#![allow(incomplete_features)] // for const_generics
#![feature(const_param_types, generators, generator_trait)]
#![allow(incomplete_features)]

use Mod1::TestTrait2;
use std::ops::Generator;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// revisions: cfail
#![feature(const_generics, generic_const_exprs)]
#![feature(generic_const_exprs, const_param_types)]
#![allow(incomplete_features)]
// regression test for #77650
fn c<T, const N: std::num::NonZeroUsize>()
Expand Down
35 changes: 0 additions & 35 deletions src/test/incremental/const-generics/hash-tyvid-regression-1.stderr

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// revisions: cfail
#![feature(const_generics, generic_const_exprs)]
#![feature(generic_const_exprs, const_param_types, const_generics_defaults)]
#![allow(incomplete_features)]
// regression test for #77650
struct C<T, const N: core::num::NonZeroUsize>([T; N.get()])
Expand Down
11 changes: 0 additions & 11 deletions src/test/incremental/const-generics/hash-tyvid-regression-2.stderr

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// revisions: cfail
#![feature(const_generics, generic_const_exprs)]
#![feature(generic_const_exprs)]
#![allow(incomplete_features)]
// regression test for #79251
struct Node<const D: usize>
Expand Down
12 changes: 0 additions & 12 deletions src/test/incremental/const-generics/hash-tyvid-regression-3.stderr

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// revisions: cfail
#![feature(const_generics, generic_const_exprs)]
#![feature(generic_const_exprs)]
#![allow(incomplete_features)]
// regression test for #79251
#[derive(Debug)]
Expand Down
12 changes: 0 additions & 12 deletions src/test/incremental/const-generics/hash-tyvid-regression-4.stderr

This file was deleted.

2 changes: 0 additions & 2 deletions src/test/incremental/const-generics/issue-61338.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// revisions:rpass1

#![feature(const_generics)]

struct Struct<T>(T);

impl<T, const N: usize> Struct<[T; N]> {
Expand Down
2 changes: 0 additions & 2 deletions src/test/incremental/const-generics/issue-61516.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// revisions:rpass1

#![feature(const_generics)]

struct FakeArray<T, const N: usize>(T);

impl<T, const N: usize> FakeArray<T, N> {
Expand Down
3 changes: 0 additions & 3 deletions src/test/incremental/const-generics/issue-62536.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// revisions:cfail1
#![feature(const_generics)]
//[cfail1]~^ WARN the feature `const_generics` is incomplete

struct S<T, const N: usize>([T; N]);

fn f<T, const N: usize>(x: T) -> S<T, {N}> { panic!() }
Expand Down
2 changes: 0 additions & 2 deletions src/test/incremental/const-generics/issue-64087.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// revisions:cfail1
#![feature(const_generics)]
//[cfail1]~^ WARN the feature `const_generics` is incomplete

fn combinator<T, const S: usize>() -> [T; S] {}
//[cfail1]~^ ERROR mismatched types
Expand Down
2 changes: 0 additions & 2 deletions src/test/incremental/const-generics/issue-65623.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// revisions:rpass1
#![feature(const_generics)]

pub struct Foo<T, const N: usize>([T; 0]);

impl<T, const N: usize> Foo<T, {N}> {
Expand Down
4 changes: 3 additions & 1 deletion src/test/incremental/const-generics/issue-68477.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// edition:2018
// revisions:rpass1
#![feature(const_generics)]

// Needed to supply generic arguments to the anon const in `[(); FOO]`.
#![feature(generic_const_exprs)]

const FOO: usize = 1;

Expand Down
Loading