Skip to content

Commit

Permalink
add min_const_generics feature gate
Browse files Browse the repository at this point in the history
  • Loading branch information
lcnr committed Aug 5, 2020
1 parent ec9d524 commit 375bccb
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 5 deletions.
8 changes: 7 additions & 1 deletion src/librustc_ast_passes/ast_validation.rs
Expand Up @@ -776,7 +776,13 @@ fn validate_generic_param_order<'a>(
span,
&format!(
"reorder the parameters: lifetimes, then types{}",
if sess.features_untracked().const_generics { ", then consts" } else { "" },
if sess.features_untracked().const_generics
|| sess.features_untracked().min_const_generics
{
", then consts"
} else {
""
},
),
ordered_params.clone(),
Applicability::MachineApplicable,
Expand Down
7 changes: 4 additions & 3 deletions src/librustc_ast_passes/feature_gate.rs
Expand Up @@ -526,12 +526,13 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {

fn visit_generic_param(&mut self, param: &'a GenericParam) {
if let GenericParamKind::Const { .. } = param.kind {
gate_feature_post!(
gate_feature_fn!(
&self,
const_generics,
|x: &Features| x.const_generics || x.min_const_generics,
param.ident.span,
sym::const_generics,
"const generics are unstable"
)
);
}
visit::walk_generic_param(self, param)
}
Expand Down
3 changes: 3 additions & 0 deletions src/librustc_feature/active.rs
Expand Up @@ -579,6 +579,9 @@ declare_features! (
/// Alloc calling `transmute` in const fn
(active, const_fn_transmute, "1.46.0", Some(53605), None),

/// The smallest useful subset of `const_generics`.
(active, min_const_generics, "1.46.0", None, None),

// -------------------------------------------------------------------------
// feature-group-end: actual feature gates
// -------------------------------------------------------------------------
Expand Down
4 changes: 3 additions & 1 deletion src/librustc_middle/ty/context.rs
Expand Up @@ -1380,7 +1380,9 @@ impl<'tcx> TyCtxt<'tcx> {
/// we still evaluate them eagerly.
#[inline]
pub fn lazy_normalization(self) -> bool {
self.features().const_generics || self.features().lazy_normalization_consts
let features = self.features();
// Note: We do not enable lazy normalization for `features.min_const_generics`.
features.const_generics || features.lazy_normalization_consts
}

#[inline]
Expand Down
1 change: 1 addition & 0 deletions src/librustc_span/symbol.rs
Expand Up @@ -672,6 +672,7 @@ symbols! {
min_align_of,
min_align_of_val,
min_const_fn,
min_const_generics,
min_const_unsafe_fn,
min_specialization,
minnumf32,
Expand Down
3 changes: 3 additions & 0 deletions src/librustc_typeck/collect.rs
Expand Up @@ -1238,6 +1238,9 @@ 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
// used with const generics, e.g. `Foo<{N+1}>`, can work at all.
//
// Note that we do not supply the parent generics when using
// `feature(min_const_generics)`.
Some(parent_def_id.to_def_id())
} else {
let parent_node = tcx.hir().get(tcx.hir().get_parent_node(hir_id));
Expand Down

0 comments on commit 375bccb

Please sign in to comment.