Skip to content

do a bunch of stuff to const generic feature gates #88324

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

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions compiler/rustc_feature/src/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -548,15 +548,9 @@ declare_features! (
/// Allows capturing variables in scope using format_args!
(active, format_args_capture, "1.46.0", Some(67984), None),

/// Lazily evaluate constants. This allows constants to depend on type parameters.
(incomplete, lazy_normalization_consts, "1.46.0", Some(72219), None),

/// Allows `if let` guard in match arms.
(incomplete, if_let_guard, "1.47.0", Some(51114), None),

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

/// Allows basic arithmetic on floating point types in a `const fn`.
(active, const_fn_floating_point_arithmetic, "1.48.0", Some(57241), None),

Expand Down Expand Up @@ -682,6 +676,9 @@ declare_features! (
/// Allows using doc(primitive) without a future-incompat warning
(active, doc_primitive, "1.56.0", Some(88070), None),

/// Allows non-trivial generic constants which have to have wfness manually propagated to callers
(incomplete, generic_const_exprs, "1.56.0", Some(76560), None),

// -------------------------------------------------------------------------
// feature-group-end: actual feature gates
// -------------------------------------------------------------------------
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_feature/src/removed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,13 @@ declare_features! (
Some("removed in favor of `#![feature(marker_trait_attr)]`")),
/// Allows `#[no_debug]`.
(removed, no_debug, "1.43.0", Some(29721), None, Some("removed due to lack of demand")),
/// Lazily evaluate constants. This allows constants to depend on type parameters.
(removed, lazy_normalization_consts, "1.46.0", Some(72219), None, Some("superseded by `generic_const_exprs`")),
/// Allows comparing raw pointers during const eval.
(removed, const_compare_raw_pointers, "1.46.0", Some(53020), None,
Some("cannot be allowed in const eval in any meaningful way")),
/// Allows non-trivial generic constants which have to be manually propagated upwards.
(removed, const_evaluatable_checked, "1.48.0", Some(76560), None, Some("renamed to `generic_const_exprs`")),
/// Allows using the `#[link_args]` attribute.
(removed, link_args, "1.53.0", Some(29596), None,
Some("removed in favor of using `-C link-arg=ARG` on command line, \
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir/src/def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ pub enum Res<Id = hir::HirId> {
/// We do however allow `Self` in repeat expression even if it is generic to not break code
/// which already works on stable while causing the `const_evaluatable_unchecked` future compat lint.
///
/// FIXME(lazy_normalization_consts): Remove this bodge once that feature is stable.
/// FIXME(generic_const_exprs): Remove this bodge once that feature is stable.
SelfTy(
/// Optionally, the trait associated with this `Self` type.
Option<DefId>,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_infer/src/infer/canonical/query_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ impl<'tcx> TypeRelatingDelegate<'tcx> for QueryTypeRelatingDelegate<'_, 'tcx> {
fn const_equate(&mut self, _a: &'tcx Const<'tcx>, _b: &'tcx Const<'tcx>) {
span_bug!(
self.cause.span(self.infcx.tcx),
"lazy_normalization_consts: unreachable `const_equate`"
"generic_const_exprs: unreachable `const_equate`"
);
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1421,7 +1421,7 @@ impl<'tcx> TyCtxt<'tcx> {
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.lazy_normalization_consts
features.const_generics || features.generic_const_exprs
}

#[inline]
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/ty/relate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -577,13 +577,13 @@ pub fn super_relate_consts<R: TypeRelation<'tcx>>(
}

(ty::ConstKind::Unevaluated(au), ty::ConstKind::Unevaluated(bu))
if tcx.features().const_evaluatable_checked =>
if tcx.features().generic_const_exprs =>
{
tcx.try_unify_abstract_consts(((au.def, au.substs), (bu.def, bu.substs)))
}

// While this is slightly incorrect, it shouldn't matter for `min_const_generics`
// and is the better alternative to waiting until `const_evaluatable_checked` can
// and is the better alternative to waiting until `generic_const_exprs` can
// be stabilized.
(ty::ConstKind::Unevaluated(au), ty::ConstKind::Unevaluated(bu))
if au.def == bu.def && au.promoted == bu.promoted =>
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_privacy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ where
}
ty::PredicateKind::RegionOutlives(..) => ControlFlow::CONTINUE,
ty::PredicateKind::ConstEvaluatable(defs, substs)
if self.def_id_visitor.tcx().features().const_evaluatable_checked =>
if self.def_id_visitor.tcx().features().generic_const_exprs =>
{
let tcx = self.def_id_visitor.tcx();
if let Ok(Some(ct)) = AbstractConst::new(tcx, defs, substs) {
Expand Down Expand Up @@ -1785,7 +1785,7 @@ impl SearchInterfaceForPrivateItemsVisitor<'tcx> {
self.visit(self.tcx.type_of(param.def_id));
}
}
// FIXME(const_evaluatable_checked): May want to look inside const here
// FIXME(generic_const_exprs): May want to look inside const here
GenericParamDefKind::Const { .. } => {
self.visit(self.tcx.type_of(param.def_id));
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -506,8 +506,8 @@ impl<'a> Resolver<'a> {

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

Expand Down
8 changes: 2 additions & 6 deletions compiler/rustc_resolve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2734,9 +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.lazy_normalization_consts)
if !(trivial || features.const_generics || 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
Expand Down Expand Up @@ -2809,9 +2807,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.lazy_normalization_consts)
if !(trivial || features.const_generics || features.generic_const_exprs)
{
if record_used {
self.report_error(
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 @@ -662,6 +662,7 @@ symbols! {
generators,
generic_arg_infer,
generic_associated_types,
generic_const_exprs,
generic_param_attrs,
get_context,
global_allocator,
Expand Down
12 changes: 6 additions & 6 deletions compiler/rustc_trait_selection/src/traits/const_evaluatable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub fn is_const_evaluatable<'cx, 'tcx>(
span: Span,
) -> Result<(), NotConstEvaluatable> {
debug!("is_const_evaluatable({:?}, {:?})", def, substs);
if infcx.tcx.features().const_evaluatable_checked {
if infcx.tcx.features().generic_const_exprs {
let tcx = infcx.tcx;
match AbstractConst::new(tcx, def, substs)? {
// We are looking at a generic abstract constant.
Expand Down Expand Up @@ -550,9 +550,9 @@ pub(super) fn mir_abstract_const<'tcx>(
tcx: TyCtxt<'tcx>,
def: ty::WithOptConstParam<LocalDefId>,
) -> Result<Option<&'tcx [mir::abstract_const::Node<'tcx>]>, ErrorReported> {
if tcx.features().const_evaluatable_checked {
if tcx.features().generic_const_exprs {
match tcx.def_kind(def.did) {
// FIXME(const_evaluatable_checked): We currently only do this for anonymous constants,
// FIXME(generic_const_exprs): We currently only do this for anonymous constants,
// meaning that we do not look into associated constants. I(@lcnr) am not yet sure whether
// we want to look into them or treat them as opaque projections.
//
Expand Down Expand Up @@ -584,7 +584,7 @@ pub(super) fn try_unify_abstract_consts<'tcx>(
Ok(false)
})()
.unwrap_or_else(|ErrorReported| true)
// FIXME(const_evaluatable_checked): We should instead have this
// FIXME(generic_const_exprs): We should instead have this
// method return the resulting `ty::Const` and return `ConstKind::Error`
// on `ErrorReported`.
}
Expand Down Expand Up @@ -672,13 +672,13 @@ pub(super) fn try_unify<'tcx>(
// branch should only be taking when dealing with associated constants, at
// which point directly comparing them seems like the desired behavior.
//
// FIXME(const_evaluatable_checked): This isn't actually the case.
// FIXME(generic_const_exprs): This isn't actually the case.
// We also take this branch for concrete anonymous constants and
// expand generic anonymous constants with concrete substs.
(ty::ConstKind::Unevaluated(a_uv), ty::ConstKind::Unevaluated(b_uv)) => {
a_uv == b_uv
}
// FIXME(const_evaluatable_checked): We may want to either actually try
// FIXME(generic_const_exprs): We may want to either actually try
// to evaluate `a_ct` and `b_ct` if they are are fully concrete or something like
// this, for now we just return false here.
_ => false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
)
}
SelectionError::NotConstEvaluatable(NotConstEvaluatable::MentionsParam) => {
if !self.tcx.features().const_evaluatable_checked {
if !self.tcx.features().generic_const_exprs {
let mut err = self.tcx.sess.struct_span_err(
span,
"constant expression depends on a generic parameter",
Expand All @@ -803,7 +803,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
// issue. However, this is currently not actually possible
// (see https://github.com/rust-lang/rust/issues/66962#issuecomment-575907083).
//
// Note that with `feature(const_evaluatable_checked)` this case should not
// Note that with `feature(generic_const_exprs)` this case should not
// be reachable.
err.note("this may fail depending on what value the parameter takes");
err.emit();
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_trait_selection/src/traits/fulfill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> {

ty::PredicateKind::ConstEquate(c1, c2) => {
debug!(?c1, ?c2, "equating consts");
if self.selcx.tcx().features().const_evaluatable_checked {
if self.selcx.tcx().features().generic_const_exprs {
// FIXME: we probably should only try to unify abstract constants
// if the constants depend on generic parameters.
//
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_trait_selection/src/traits/object_safety.rs
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,7 @@ fn contains_illegal_self_type_reference<'tcx, T: TypeFoldable<'tcx>>(

fn visit_predicate(&mut self, pred: ty::Predicate<'tcx>) -> ControlFlow<Self::BreakTy> {
if let ty::PredicateKind::ConstEvaluatable(def, substs) = pred.kind().skip_binder() {
// FIXME(const_evaluatable_checked): We should probably deduplicate the logic for
// FIXME(generic_const_exprs): We should probably deduplicate the logic for
// `AbstractConst`s here, it might make sense to change `ConstEvaluatable` to
// take a `ty::Const` instead.
use rustc_middle::mir::abstract_const::Node;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_trait_selection/src/traits/select/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
ty::PredicateKind::ConstEquate(c1, c2) => {
debug!(?c1, ?c2, "evaluate_predicate_recursively: equating consts");

if self.tcx().features().const_evaluatable_checked {
if self.tcx().features().generic_const_exprs {
// FIXME: we probably should only try to unify abstract constants
// if the constants depend on generic parameters.
//
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 @@ -2302,7 +2302,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP
}
}

if tcx.features().const_evaluatable_checked {
if tcx.features().generic_const_exprs {
predicates.extend(const_evaluatable_predicates_of(tcx, def_id.expect_local()));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// revisions: cfail
#![feature(const_generics, const_evaluatable_checked)]
#![feature(const_generics, generic_const_exprs)]
#![allow(incomplete_features)]
// regression test for #77650
fn c<T, const N: std::num::NonZeroUsize>()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// revisions: cfail
#![feature(const_generics, const_evaluatable_checked)]
#![feature(const_generics, generic_const_exprs)]
#![allow(incomplete_features)]
// regression test for #77650
struct C<T, const N: core::num::NonZeroUsize>([T; N.get()])
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// revisions: cfail
#![feature(const_generics, const_evaluatable_checked)]
#![feature(const_generics, generic_const_exprs)]
#![allow(incomplete_features)]
// regression test for #79251
struct Node<const D: usize>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// revisions: cfail
#![feature(const_generics, const_evaluatable_checked)]
#![feature(const_generics, generic_const_exprs)]
#![allow(incomplete_features)]
// regression test for #79251
#[derive(Debug)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// revisions: cfail
#![feature(const_generics, const_evaluatable_checked)]
#![feature(const_generics, generic_const_exprs)]
#![allow(incomplete_features, unused_braces)]

trait Delegates<T> {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// revisions: rpass
#![feature(const_generics, const_evaluatable_checked)]
#![feature(const_generics, generic_const_exprs)]
#![allow(incomplete_features)]

struct Z;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// revisions: rpass
#![feature(const_generics, const_evaluatable_checked)]
#![feature(const_generics, generic_const_exprs)]
#![allow(incomplete_features)]

use std::{convert::TryFrom, num::NonZeroUsize};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// revisions: rpass
#![feature(const_generics, const_evaluatable_checked)]
#![feature(const_generics, generic_const_exprs)]
#![allow(incomplete_features)]
pub trait IsTrue {}
pub trait IsFalse {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// revisions: rpass
#![feature(const_generics, const_evaluatable_checked)]
#![feature(const_generics, generic_const_exprs)]
#![allow(incomplete_features)]

pub struct Ref<'a, const NUM: usize>(&'a i32);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// revisions: cfail
#![allow(incomplete_features)]
#![feature(const_generics, const_evaluatable_checked)]
#![feature(const_generics, generic_const_exprs)]

pub struct Ref<'a>(&'a i32);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// revisions: rpass
#![feature(const_generics, const_evaluatable_checked)]
#![feature(const_generics, generic_const_exprs)]
#![allow(incomplete_features)]

fn test<const SIZE: usize>() {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// revisions: rpass
#![feature(const_generics, const_evaluatable_checked)]
#![feature(const_generics, generic_const_exprs)]
#![allow(incomplete_features)]

struct Foo;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// revisions: cfail
#![feature(const_generics, const_evaluatable_checked)]
#![feature(const_generics, generic_const_exprs)]
#![allow(incomplete_features, unused_braces)]

struct Buffer<T, const S: usize>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![crate_name = "foo"]
#![feature(const_evaluatable_checked, const_generics)]
#![feature(generic_const_exprs, const_generics)]
#![allow(incomplete_features)]
// make sure that `ConstEvaluatable` predicates dont cause rustdoc to ICE #77647
// @has foo/struct.Ice.html '//pre[@class="rust struct"]' \
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![crate_name = "foo"]
#![feature(lazy_normalization_consts)]
#![feature(const_generics, generic_const_exprs)]
#![allow(incomplete_features)]

// Checking if `Send` is implemented for `Hasher` requires us to evaluate a `ConstEquate` predicate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LL | let _array: [u32; <A as Foo>::Y];
| ^ cannot perform const operation using `A`
|
= note: type parameters may not be used in const expressions
= help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions
= help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions

error: aborting due to previous error

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LL | links: [u32; A::LINKS], // Shouldn't suggest bounds already there.
| ^^^^^^^^ cannot perform const operation using `A`
|
= note: type parameters may not be used in const expressions
= help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions
= help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions

error: aborting due to previous error

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LL | struct ArithArrayLen<const N: usize>([u32; 0 + N]);
| ^ cannot perform const operation using `N`
|
= help: const parameters may only be used as standalone arguments, i.e. `N`
= help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions
= help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions

error: generic parameters may not be used in const operations
--> $DIR/array-size-in-generic-struct-param.rs:19:15
Expand All @@ -14,7 +14,7 @@ LL | arr: [u8; CFG.arr_size],
| ^^^ cannot perform const operation using `CFG`
|
= help: const parameters may only be used as standalone arguments, i.e. `CFG`
= help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions
= help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions

error: `Config` is forbidden as the type of a const generic parameter
--> $DIR/array-size-in-generic-struct-param.rs:17:21
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/const-generics/auxiliary/generics_of_parent.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(const_generics, const_evaluatable_checked)]
#![feature(const_generics, generic_const_exprs)]
#![allow(incomplete_features)]

// library portion of regression test for #87674
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(const_generics, const_evaluatable_checked)]
#![feature(const_generics, generic_const_exprs)]
#![allow(incomplete_features)]

// library portion of testing that `impl Trait<{ expr }>` doesnt
Expand Down
Loading