Skip to content

Commit 06cc9c2

Browse files
committed
stabilize min_const_generics
1 parent 1f5beec commit 06cc9c2

File tree

17 files changed

+41
-51
lines changed

17 files changed

+41
-51
lines changed

compiler/rustc_arena/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#![feature(new_uninit)]
1717
#![feature(maybe_uninit_slice)]
1818
#![feature(array_value_iter)]
19-
#![feature(min_const_generics)]
19+
#![cfg_attr(bootstrap, feature(min_const_generics))]
2020
#![feature(min_specialization)]
2121
#![cfg_attr(test, feature(test))]
2222

compiler/rustc_ast/src/ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1128,7 +1128,7 @@ impl Expr {
11281128
/// Is this expr either `N`, or `{ N }`.
11291129
///
11301130
/// If this is not the case, name resolution does not resolve `N` when using
1131-
/// `feature(min_const_generics)` as more complex expressions are not supported.
1131+
/// `min_const_generics` as more complex expressions are not supported.
11321132
pub fn is_potential_trivial_const_param(&self) -> bool {
11331133
let this = if let ExprKind::Block(ref block, None) = self.kind {
11341134
if block.stmts.len() == 1 {

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -773,14 +773,12 @@ fn validate_generic_param_order<'a>(
773773
err.span_suggestion(
774774
span,
775775
&format!(
776-
"reorder the parameters: lifetimes{}",
776+
"reorder the parameters: lifetimes, {}",
777777
if sess.features_untracked().const_generics {
778-
", then consts and types"
779-
} else if sess.features_untracked().min_const_generics {
780-
", then types, then consts"
778+
"then consts and types"
781779
} else {
782-
", then types"
783-
},
780+
"then types, then consts"
781+
}
784782
),
785783
ordered_params.clone(),
786784
Applicability::MachineApplicable,

compiler/rustc_ast_passes/src/feature_gate.rs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use rustc_ast as ast;
22
use rustc_ast::visit::{self, AssocCtxt, FnCtxt, FnKind, Visitor};
33
use rustc_ast::{AssocTyConstraint, AssocTyConstraintKind, NodeId};
4-
use rustc_ast::{GenericParam, GenericParamKind, PatKind, RangeEnd, VariantData};
4+
use rustc_ast::{PatKind, RangeEnd, VariantData};
55
use rustc_errors::struct_span_err;
66
use rustc_feature::{AttributeGate, BUILTIN_ATTRIBUTE_MAP};
77
use rustc_feature::{Features, GateIssue};
@@ -529,19 +529,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
529529
visit::walk_fn(self, fn_kind, span)
530530
}
531531

532-
fn visit_generic_param(&mut self, param: &'a GenericParam) {
533-
if let GenericParamKind::Const { .. } = param.kind {
534-
gate_feature_fn!(
535-
&self,
536-
|x: &Features| x.const_generics || x.min_const_generics,
537-
param.ident.span,
538-
sym::min_const_generics,
539-
"const generics are unstable"
540-
);
541-
}
542-
visit::walk_generic_param(self, param)
543-
}
544-
545532
fn visit_assoc_ty_constraint(&mut self, constraint: &'a AssocTyConstraint) {
546533
if let AssocTyConstraintKind::Bound { .. } = constraint.kind {
547534
gate_feature_post!(

compiler/rustc_data_structures/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#![feature(thread_id_value)]
2828
#![feature(extend_one)]
2929
#![feature(const_panic)]
30-
#![feature(min_const_generics)]
30+
#![cfg_attr(bootstrap, feature(min_const_generics))]
3131
#![feature(new_uninit)]
3232
#![feature(once_cell)]
3333
#![feature(maybe_uninit_uninit_array)]

compiler/rustc_feature/src/accepted.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,8 @@ 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.48.0", Some(68354), None),
276+
/// The smallest useful subset of `const_generics`.
277+
(accepted, min_const_generics, "1.51.0", Some(74878), None),
276278

277279
// -------------------------------------------------------------------------
278280
// feature-group-end: accepted features

compiler/rustc_feature/src/active.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -578,9 +578,6 @@ declare_features! (
578578
/// Allows calling `transmute` in const fn
579579
(active, const_fn_transmute, "1.46.0", Some(53605), None),
580580

581-
/// The smallest useful subset of `const_generics`.
582-
(active, min_const_generics, "1.47.0", Some(74878), None),
583-
584581
/// Allows `if let` guard in match arms.
585582
(active, if_let_guard, "1.47.0", Some(51114), None),
586583

@@ -651,5 +648,7 @@ pub const INCOMPLETE_FEATURES: &[Symbol] = &[
651648

652649
/// Some features are not allowed to be used together at the same time, if
653650
/// the two are present, produce an error.
654-
pub const INCOMPATIBLE_FEATURES: &[(Symbol, Symbol)] =
655-
&[(sym::const_generics, sym::min_const_generics)];
651+
///
652+
/// Currently empty, but we will probably need this again in the future,
653+
/// so let's keep it in for now.
654+
pub const INCOMPATIBLE_FEATURES: &[(Symbol, Symbol)] = &[];

compiler/rustc_lint/src/builtin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2299,7 +2299,7 @@ impl EarlyLintPass for IncompleteFeatures {
22992299
}
23002300
}
23012301

2302-
const HAS_MIN_FEATURES: &[Symbol] = &[sym::const_generics, sym::specialization];
2302+
const HAS_MIN_FEATURES: &[Symbol] = &[sym::specialization];
23032303

23042304
declare_lint! {
23052305
/// The `invalid_value` lint detects creating a value that is not valid,

compiler/rustc_middle/src/ty/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1386,7 +1386,7 @@ impl<'tcx> TyCtxt<'tcx> {
13861386
#[inline]
13871387
pub fn lazy_normalization(self) -> bool {
13881388
let features = self.features();
1389-
// Note: We do not enable lazy normalization for `features.min_const_generics`.
1389+
// Note: We do not enable lazy normalization for `min_const_generics`.
13901390
features.const_generics || features.lazy_normalization_consts
13911391
}
13921392

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1638,8 +1638,6 @@ pub type PlaceholderConst<'tcx> = Placeholder<BoundConst<'tcx>>;
16381638
/// which cause cycle errors.
16391639
///
16401640
/// ```rust
1641-
/// #![feature(const_generics)]
1642-
///
16431641
/// struct A;
16441642
/// impl A {
16451643
/// fn foo<const N: usize>(&self) -> [u8; N] { [0; N] }

compiler/rustc_parse/src/parser/generics.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_ast::{
55
self as ast, Attribute, GenericBounds, GenericParam, GenericParamKind, WhereClause,
66
};
77
use rustc_errors::PResult;
8-
use rustc_span::symbol::{kw, sym};
8+
use rustc_span::symbol::kw;
99

1010
impl<'a> Parser<'a> {
1111
/// Parses bounds of a lifetime parameter `BOUND + BOUND + BOUND`, possibly with trailing `+`.
@@ -56,8 +56,6 @@ impl<'a> Parser<'a> {
5656
self.expect(&token::Colon)?;
5757
let ty = self.parse_ty()?;
5858

59-
self.sess.gated_spans.gate(sym::min_const_generics, const_span.to(self.prev_token.span));
60-
6159
Ok(GenericParam {
6260
ident,
6361
id: ast::DUMMY_NODE_ID,

compiler/rustc_resolve/src/late/diagnostics.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1985,8 +1985,8 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
19851985
}
19861986
}
19871987

1988-
/// Non-static lifetimes are prohibited in anonymous constants under `min_const_generics` so
1989-
/// this function will emit an error if `min_const_generics` is enabled, the body identified by
1988+
/// Non-static lifetimes are prohibited in anonymous constants under `min_const_generics`.
1989+
/// This function will emit an error if `const_generics` is not enabled, the body identified by
19901990
/// `body_id` is an anonymous constant and `lifetime_ref` is non-static.
19911991
crate fn maybe_emit_forbidden_non_static_lifetime_error(
19921992
&self,
@@ -2002,7 +2002,7 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
20022002
hir::LifetimeName::Implicit | hir::LifetimeName::Static | hir::LifetimeName::Underscore
20032003
);
20042004

2005-
if self.tcx.features().min_const_generics && is_anon_const && !is_allowed_lifetime {
2005+
if !self.tcx.lazy_normalization() && is_anon_const && !is_allowed_lifetime {
20062006
feature_err(
20072007
&self.tcx.sess.parse_sess,
20082008
sym::const_generics,

compiler/rustc_resolve/src/late/lifetimes.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1769,8 +1769,8 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
17691769
let result = loop {
17701770
match *scope {
17711771
Scope::Body { id, s } => {
1772-
// Non-static lifetimes are prohibited in anonymous constants under
1773-
// `min_const_generics`.
1772+
// Non-static lifetimes are prohibited in anonymous constants without
1773+
// `const_generics`.
17741774
self.maybe_emit_forbidden_non_static_lifetime_error(id, lifetime_ref);
17751775

17761776
outermost_body = Some(id);

compiler/rustc_resolve/src/lib.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2624,8 +2624,12 @@ impl<'a> Resolver<'a> {
26242624
continue;
26252625
}
26262626
ConstantItemRibKind(trivial) => {
2627+
let features = self.session.features_untracked();
26272628
// HACK(min_const_generics): We currently only allow `N` or `{ N }`.
2628-
if !trivial && self.session.features_untracked().min_const_generics {
2629+
if !(trivial
2630+
|| features.const_generics
2631+
|| features.lazy_normalization_consts)
2632+
{
26292633
// HACK(min_const_generics): If we encounter `Self` in an anonymous constant
26302634
// we can't easily tell if it's generic at this stage, so we instead remember
26312635
// this and then enforce the self type to be concrete later on.
@@ -2713,8 +2717,12 @@ impl<'a> Resolver<'a> {
27132717
continue;
27142718
}
27152719
ConstantItemRibKind(trivial) => {
2720+
let features = self.session.features_untracked();
27162721
// HACK(min_const_generics): We currently only allow `N` or `{ N }`.
2717-
if !trivial && self.session.features_untracked().min_const_generics {
2722+
if !(trivial
2723+
|| features.const_generics
2724+
|| features.lazy_normalization_consts)
2725+
{
27182726
if record_used {
27192727
self.report_error(
27202728
span,

compiler/rustc_serialize/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Core encoding and decoding interfaces.
1313
#![feature(never_type)]
1414
#![feature(nll)]
1515
#![feature(associated_type_bounds)]
16-
#![feature(min_const_generics)]
16+
#![cfg_attr(bootstrap, feature(min_const_generics))]
1717
#![cfg_attr(test, feature(test))]
1818
#![allow(rustc::internal)]
1919

compiler/rustc_typeck/src/check/wfcheck.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,13 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) {
293293

294294
let err_ty_str;
295295
let mut is_ptr = true;
296-
let err = if tcx.features().min_const_generics {
296+
let err = if tcx.features().const_generics {
297+
match ty.peel_refs().kind() {
298+
ty::FnPtr(_) => Some("function pointers"),
299+
ty::RawPtr(_) => Some("raw pointers"),
300+
_ => None,
301+
}
302+
} else {
297303
match ty.kind() {
298304
ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::Error(_) => None,
299305
ty::FnPtr(_) => Some("function pointers"),
@@ -304,12 +310,6 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) {
304310
Some(err_ty_str.as_str())
305311
}
306312
}
307-
} else {
308-
match ty.peel_refs().kind() {
309-
ty::FnPtr(_) => Some("function pointers"),
310-
ty::RawPtr(_) => Some("raw pointers"),
311-
_ => None,
312-
}
313313
};
314314
if let Some(unsupported_type) = err {
315315
if is_ptr {

compiler/rustc_typeck/src/collect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1260,7 +1260,7 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
12601260
// used with const generics, e.g. `Foo<{N+1}>`, can work at all.
12611261
//
12621262
// Note that we do not supply the parent generics when using
1263-
// `feature(min_const_generics)`.
1263+
// `min_const_generics`.
12641264
Some(parent_def_id.to_def_id())
12651265
} else {
12661266
let parent_node = tcx.hir().get(tcx.hir().get_parent_node(hir_id));

0 commit comments

Comments
 (0)