about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEllen <supbscripter@gmail.com>2021-10-23 16:57:13 +0100
committerEllen <supbscripter@gmail.com>2021-12-10 19:20:31 +0000
commit69d2d735bc3f7bff7c42542691283d8a5f1a60f8 (patch)
treec8d8893225463df6a7cec222c1bbc34e235d31a0
parent3b263ceb5cb89b6d53b5a03b47ec447c3a7f7765 (diff)
downloadrust-69d2d735bc3f7bff7c42542691283d8a5f1a60f8.tar.gz
rust-69d2d735bc3f7bff7c42542691283d8a5f1a60f8.zip
remove feature gate and cleanup code
-rw-r--r--compiler/rustc_ast/src/ast.rs11
-rw-r--r--compiler/rustc_ast_passes/src/ast_validation.rs28
-rw-r--r--compiler/rustc_ast_passes/src/feature_gate.rs4
-rw-r--r--compiler/rustc_feature/src/accepted.rs2
-rw-r--r--compiler/rustc_feature/src/active.rs6
-rw-r--r--compiler/rustc_hir/src/hir.rs6
-rw-r--r--compiler/rustc_middle/src/ty/generics.rs6
-rw-r--r--compiler/rustc_parse/src/parser/generics.rs17
-rw-r--r--compiler/rustc_typeck/src/astconv/generics.rs36
-rw-r--r--compiler/rustc_typeck/src/check/wfcheck.rs1
10 files changed, 18 insertions, 99 deletions
diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs
index 03b957adeda..4f55f37e2e9 100644
--- a/compiler/rustc_ast/src/ast.rs
+++ b/compiler/rustc_ast/src/ast.rs
@@ -332,10 +332,7 @@ pub type GenericBounds = Vec<GenericBound>;
 pub enum ParamKindOrd {
     Lifetime,
     Type,
-    // `unordered` is only `true` if `sess.unordered_const_ty_params()`
-    // returns true. Specifically, if it's only `min_const_generics`, it will still require
-    // ordering consts after types.
-    Const { unordered: bool },
+    Const,
     // `Infer` is not actually constructed directly from the AST, but is implicitly constructed
     // during HIR lowering, and `ParamKindOrd` will implicitly order inferred variables last.
     Infer,
@@ -346,11 +343,7 @@ impl Ord for ParamKindOrd {
         use ParamKindOrd::*;
         let to_int = |v| match v {
             Lifetime => 0,
-            Infer | Type | Const { unordered: true } => 1,
-            // technically both consts should be ordered equally,
-            // but only one is ever encountered at a time, so this is
-            // fine.
-            Const { unordered: false } => 2,
+            Infer | Type | Const => 1,
         };
 
         to_int(*self).cmp(&to_int(*other))
diff --git a/compiler/rustc_ast_passes/src/ast_validation.rs b/compiler/rustc_ast_passes/src/ast_validation.rs
index efc30121987..ae8c4330a1c 100644
--- a/compiler/rustc_ast_passes/src/ast_validation.rs
+++ b/compiler/rustc_ast_passes/src/ast_validation.rs
@@ -894,7 +894,6 @@ impl<'a> AstValidator<'a> {
 /// Checks that generic parameters are in the correct order,
 /// which is lifetimes, then types and then consts. (`<'a, T, const N: usize>`)
 fn validate_generic_param_order(
-    sess: &Session,
     handler: &rustc_errors::Handler,
     generics: &[GenericParam],
     span: Span,
@@ -911,8 +910,7 @@ fn validate_generic_param_order(
             GenericParamKind::Type { default: _ } => (ParamKindOrd::Type, ident.to_string()),
             GenericParamKind::Const { ref ty, kw_span: _, default: _ } => {
                 let ty = pprust::ty_to_string(ty);
-                let unordered = sess.features_untracked().unordered_const_ty_params();
-                (ParamKindOrd::Const { unordered }, format!("const {}: {}", ident, ty))
+                (ParamKindOrd::Const, format!("const {}: {}", ident, ty))
             }
         };
         param_idents.push((kind, ord_kind, bounds, idx, ident));
@@ -968,14 +966,7 @@ fn validate_generic_param_order(
             );
             err.span_suggestion(
                 span,
-                &format!(
-                    "reorder the parameters: lifetimes, {}",
-                    if sess.features_untracked().unordered_const_ty_params() {
-                        "then consts and types"
-                    } else {
-                        "then types, then consts"
-                    }
-                ),
+                "reorder the parameters: lifetimes, then consts and types",
                 ordered_params.clone(),
                 Applicability::MachineApplicable,
             );
@@ -1342,8 +1333,6 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
     }
 
     fn visit_generics(&mut self, generics: &'a Generics) {
-        let cg_defaults = self.session.features_untracked().unordered_const_ty_params();
-
         let mut prev_param_default = None;
         for param in &generics.params {
             match param.kind {
@@ -1358,12 +1347,6 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
                             span,
                             "generic parameters with a default must be trailing",
                         );
-                        if matches!(param.kind, GenericParamKind::Const { .. }) && !cg_defaults {
-                            err.note(
-                                "using type defaults and const parameters \
-                                 in the same parameter list is currently not permitted",
-                            );
-                        }
                         err.emit();
                         break;
                     }
@@ -1371,12 +1354,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
             }
         }
 
-        validate_generic_param_order(
-            self.session,
-            self.err_handler(),
-            &generics.params,
-            generics.span,
-        );
+        validate_generic_param_order(self.err_handler(), &generics.params, generics.span);
 
         for predicate in &generics.where_clause.predicates {
             if let WherePredicate::EqPredicate(ref predicate) = *predicate {
diff --git a/compiler/rustc_ast_passes/src/feature_gate.rs b/compiler/rustc_ast_passes/src/feature_gate.rs
index ad539f2564d..2497fa67d8c 100644
--- a/compiler/rustc_ast_passes/src/feature_gate.rs
+++ b/compiler/rustc_ast_passes/src/feature_gate.rs
@@ -724,10 +724,6 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session) {
     gate_all!(half_open_range_patterns, "half-open range patterns are unstable");
     gate_all!(inline_const, "inline-const is experimental");
     gate_all!(inline_const_pat, "inline-const in pattern position is experimental");
-    gate_all!(
-        const_generics_defaults,
-        "default values for const generic parameters are experimental"
-    );
     if sess.parse_sess.span_diagnostic.err_count() == 0 {
         // Errors for `destructuring_assignment` can get quite noisy, especially where `_` is
         // involved, so we only emit errors where there are no other parsing errors.
diff --git a/compiler/rustc_feature/src/accepted.rs b/compiler/rustc_feature/src/accepted.rs
index 6950fae898f..1b999258aed 100644
--- a/compiler/rustc_feature/src/accepted.rs
+++ b/compiler/rustc_feature/src/accepted.rs
@@ -306,6 +306,8 @@ declare_features! (
     (accepted, while_let, "1.0.0", None, None),
     /// Allows `#![windows_subsystem]`.
     (accepted, windows_subsystem, "1.18.0", Some(37499), None),
+    /// Allows const generics to have default values (e.g. `struct Foo<const N: usize = 3>(...);`).
+    (accepted, const_generics_defaults, "1.58.0", Some(44580), None),
     // !!!!    !!!!    !!!!    !!!!   !!!!    !!!!    !!!!    !!!!    !!!!    !!!!    !!!!
     // Features are listed in alphabetical order. Tidy will fail if you don't keep it this way.
     // !!!!    !!!!    !!!!    !!!!   !!!!    !!!!    !!!!    !!!!    !!!!    !!!!    !!!!
diff --git a/compiler/rustc_feature/src/active.rs b/compiler/rustc_feature/src/active.rs
index 640c4bba6da..22f6559d15f 100644
--- a/compiler/rustc_feature/src/active.rs
+++ b/compiler/rustc_feature/src/active.rs
@@ -69,10 +69,6 @@ macro_rules! declare_features {
                 }
             }
 
-            pub fn unordered_const_ty_params(&self) -> bool {
-                self.const_generics_defaults || self.generic_const_exprs || self.adt_const_params
-            }
-
             /// Some features are known to be incomplete and using them is likely to have
             /// unanticipated results, such as compiler crashes. We warn the user about these
             /// to alert them.
@@ -334,8 +330,6 @@ declare_features! (
     (active, const_fn_trait_bound, "1.53.0", Some(57563), None),
     /// Allows `for _ in _` loops in const contexts.
     (active, const_for, "1.56.0", Some(87575), None),
-    /// Allows const generics to have default values (e.g. `struct Foo<const N: usize = 3>(...);`).
-    (active, const_generics_defaults, "1.51.0", Some(44580), None),
     /// Allows argument and return position `impl Trait` in a `const fn`.
     (active, const_impl_trait, "1.48.0", Some(77463), None),
     /// Allows using `&mut` in constant functions.
diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs
index 487ae87052b..77b1f417725 100644
--- a/compiler/rustc_hir/src/hir.rs
+++ b/compiler/rustc_hir/src/hir.rs
@@ -325,13 +325,11 @@ impl GenericArg<'_> {
         }
     }
 
-    pub fn to_ord(&self, feats: &rustc_feature::Features) -> ast::ParamKindOrd {
+    pub fn to_ord(&self) -> ast::ParamKindOrd {
         match self {
             GenericArg::Lifetime(_) => ast::ParamKindOrd::Lifetime,
             GenericArg::Type(_) => ast::ParamKindOrd::Type,
-            GenericArg::Const(_) => {
-                ast::ParamKindOrd::Const { unordered: feats.unordered_const_ty_params() }
-            }
+            GenericArg::Const(_) => ast::ParamKindOrd::Const,
             GenericArg::Infer(_) => ast::ParamKindOrd::Infer,
         }
     }
diff --git a/compiler/rustc_middle/src/ty/generics.rs b/compiler/rustc_middle/src/ty/generics.rs
index f53f1871508..1c3a01e2cfa 100644
--- a/compiler/rustc_middle/src/ty/generics.rs
+++ b/compiler/rustc_middle/src/ty/generics.rs
@@ -24,13 +24,11 @@ impl GenericParamDefKind {
             GenericParamDefKind::Const { .. } => "constant",
         }
     }
-    pub fn to_ord(&self, tcx: TyCtxt<'_>) -> ast::ParamKindOrd {
+    pub fn to_ord(&self) -> ast::ParamKindOrd {
         match self {
             GenericParamDefKind::Lifetime => ast::ParamKindOrd::Lifetime,
             GenericParamDefKind::Type { .. } => ast::ParamKindOrd::Type,
-            GenericParamDefKind::Const { .. } => {
-                ast::ParamKindOrd::Const { unordered: tcx.features().unordered_const_ty_params() }
-            }
+            GenericParamDefKind::Const { .. } => ast::ParamKindOrd::Const,
         }
     }
 }
diff --git a/compiler/rustc_parse/src/parser/generics.rs b/compiler/rustc_parse/src/parser/generics.rs
index 07887a7a59c..419ea9cced0 100644
--- a/compiler/rustc_parse/src/parser/generics.rs
+++ b/compiler/rustc_parse/src/parser/generics.rs
@@ -5,7 +5,7 @@ use rustc_ast::{
     self as ast, Attribute, GenericBounds, GenericParam, GenericParamKind, WhereClause,
 };
 use rustc_errors::PResult;
-use rustc_span::symbol::{kw, sym};
+use rustc_span::symbol::kw;
 
 impl<'a> Parser<'a> {
     /// Parses bounds of a lifetime parameter `BOUND + BOUND + BOUND`, possibly with trailing `+`.
@@ -59,19 +59,8 @@ impl<'a> Parser<'a> {
         self.expect(&token::Colon)?;
         let ty = self.parse_ty()?;
 
-        // Parse optional const generics default value, taking care of feature gating the spans
-        // with the unstable syntax mechanism.
-        let default = if self.eat(&token::Eq) {
-            // The gated span goes from the `=` to the end of the const argument that follows (and
-            // which could be a block expression).
-            let start = self.prev_token.span;
-            let const_arg = self.parse_const_arg()?;
-            let span = start.to(const_arg.value.span);
-            self.sess.gated_spans.gate(sym::const_generics_defaults, span);
-            Some(const_arg)
-        } else {
-            None
-        };
+        // Parse optional const generics default value.
+        let default = if self.eat(&token::Eq) { Some(self.parse_const_arg()?) } else { None };
 
         Ok(GenericParam {
             ident,
diff --git a/compiler/rustc_typeck/src/astconv/generics.rs b/compiler/rustc_typeck/src/astconv/generics.rs
index e8bd038fed7..caa5c71e21c 100644
--- a/compiler/rustc_typeck/src/astconv/generics.rs
+++ b/compiler/rustc_typeck/src/astconv/generics.rs
@@ -131,8 +131,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
             _ => {}
         }
 
-        let kind_ord = param.kind.to_ord(tcx);
-        let arg_ord = arg.to_ord(tcx.features());
+        let kind_ord = param.kind.to_ord();
+        let arg_ord = arg.to_ord();
 
         // This note is only true when generic parameters are strictly ordered by their kind.
         if possible_ordering_error && kind_ord.cmp(&arg_ord) != core::cmp::Ordering::Equal {
@@ -298,26 +298,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
                                         .params
                                         .clone()
                                         .into_iter()
-                                        .map(|param| {
-                                            (
-                                                match param.kind {
-                                                    GenericParamDefKind::Lifetime => {
-                                                        ParamKindOrd::Lifetime
-                                                    }
-                                                    GenericParamDefKind::Type { .. } => {
-                                                        ParamKindOrd::Type
-                                                    }
-                                                    GenericParamDefKind::Const { .. } => {
-                                                        ParamKindOrd::Const {
-                                                            unordered: tcx
-                                                                .features()
-                                                                .unordered_const_ty_params(),
-                                                        }
-                                                    }
-                                                },
-                                                param,
-                                            )
-                                        })
+                                        .map(|param| (param.kind.to_ord(), param))
                                         .collect::<Vec<(ParamKindOrd, GenericParamDef)>>();
                                     param_types_present.sort_by_key(|(ord, _)| *ord);
                                     let (mut param_types_present, ordered_params): (
@@ -330,16 +311,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
                                         tcx,
                                         arg,
                                         param,
-                                        !args_iter.clone().is_sorted_by_key(|arg| match arg {
-                                            GenericArg::Lifetime(_) => ParamKindOrd::Lifetime,
-                                            GenericArg::Type(_) => ParamKindOrd::Type,
-                                            GenericArg::Const(_) => ParamKindOrd::Const {
-                                                unordered: tcx
-                                                    .features()
-                                                    .unordered_const_ty_params(),
-                                            },
-                                            GenericArg::Infer(_) => ParamKindOrd::Infer,
-                                        }),
+                                        !args_iter.clone().is_sorted_by_key(|arg| arg.to_ord()),
                                         Some(&format!(
                                             "reorder the arguments: {}: `<{}>`",
                                             param_types_present
diff --git a/compiler/rustc_typeck/src/check/wfcheck.rs b/compiler/rustc_typeck/src/check/wfcheck.rs
index 1fc88829c77..16255b3c56a 100644
--- a/compiler/rustc_typeck/src/check/wfcheck.rs
+++ b/compiler/rustc_typeck/src/check/wfcheck.rs
@@ -696,7 +696,6 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) {
         hir::GenericParamKind::Lifetime { .. } | hir::GenericParamKind::Type { .. } => (),
 
         // Const parameters are well formed if their type is structural match.
-        // FIXME(const_generics_defaults): we also need to check that the `default` is wf.
         hir::GenericParamKind::Const { ty: hir_ty, default: _ } => {
             let ty = tcx.type_of(tcx.hir().local_def_id(param.hir_id));