Skip to content

Commit 375bccb

Browse files
committed
add min_const_generics feature gate
1 parent ec9d524 commit 375bccb

File tree

6 files changed

+21
-5
lines changed

6 files changed

+21
-5
lines changed

src/librustc_ast_passes/ast_validation.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,13 @@ fn validate_generic_param_order<'a>(
776776
span,
777777
&format!(
778778
"reorder the parameters: lifetimes, then types{}",
779-
if sess.features_untracked().const_generics { ", then consts" } else { "" },
779+
if sess.features_untracked().const_generics
780+
|| sess.features_untracked().min_const_generics
781+
{
782+
", then consts"
783+
} else {
784+
""
785+
},
780786
),
781787
ordered_params.clone(),
782788
Applicability::MachineApplicable,

src/librustc_ast_passes/feature_gate.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -526,12 +526,13 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
526526

527527
fn visit_generic_param(&mut self, param: &'a GenericParam) {
528528
if let GenericParamKind::Const { .. } = param.kind {
529-
gate_feature_post!(
529+
gate_feature_fn!(
530530
&self,
531-
const_generics,
531+
|x: &Features| x.const_generics || x.min_const_generics,
532532
param.ident.span,
533+
sym::const_generics,
533534
"const generics are unstable"
534-
)
535+
);
535536
}
536537
visit::walk_generic_param(self, param)
537538
}

src/librustc_feature/active.rs

+3
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,9 @@ declare_features! (
579579
/// Alloc calling `transmute` in const fn
580580
(active, const_fn_transmute, "1.46.0", Some(53605), None),
581581

582+
/// The smallest useful subset of `const_generics`.
583+
(active, min_const_generics, "1.46.0", None, None),
584+
582585
// -------------------------------------------------------------------------
583586
// feature-group-end: actual feature gates
584587
// -------------------------------------------------------------------------

src/librustc_middle/ty/context.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1380,7 +1380,9 @@ impl<'tcx> TyCtxt<'tcx> {
13801380
/// we still evaluate them eagerly.
13811381
#[inline]
13821382
pub fn lazy_normalization(self) -> bool {
1383-
self.features().const_generics || self.features().lazy_normalization_consts
1383+
let features = self.features();
1384+
// Note: We do not enable lazy normalization for `features.min_const_generics`.
1385+
features.const_generics || features.lazy_normalization_consts
13841386
}
13851387

13861388
#[inline]

src/librustc_span/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,7 @@ symbols! {
672672
min_align_of,
673673
min_align_of_val,
674674
min_const_fn,
675+
min_const_generics,
675676
min_const_unsafe_fn,
676677
min_specialization,
677678
minnumf32,

src/librustc_typeck/collect.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1238,6 +1238,9 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
12381238
// HACK(eddyb) this provides the correct generics when
12391239
// `feature(const_generics)` is enabled, so that const expressions
12401240
// used with const generics, e.g. `Foo<{N+1}>`, can work at all.
1241+
//
1242+
// Note that we do not supply the parent generics when using
1243+
// `feature(min_const_generics)`.
12411244
Some(parent_def_id.to_def_id())
12421245
} else {
12431246
let parent_node = tcx.hir().get(tcx.hir().get_parent_node(hir_id));

0 commit comments

Comments
 (0)