remove feature gate and cleanup code
This commit is contained in:
parent
3b263ceb5c
commit
69d2d735bc
@ -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))
|
||||
|
@ -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 {
|
||||
|
@ -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.
|
||||
|
@ -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.
|
||||
// !!!! !!!! !!!! !!!! !!!! !!!! !!!! !!!! !!!! !!!! !!!!
|
||||
|
@ -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.
|
||||
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
|
@ -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));
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user