remove feature gate and cleanup code
This commit is contained in:
parent
3b263ceb5c
commit
69d2d735bc
10 changed files with 18 additions and 99 deletions
|
@ -332,10 +332,7 @@ pub type GenericBounds = Vec<GenericBound>;
|
||||||
pub enum ParamKindOrd {
|
pub enum ParamKindOrd {
|
||||||
Lifetime,
|
Lifetime,
|
||||||
Type,
|
Type,
|
||||||
// `unordered` is only `true` if `sess.unordered_const_ty_params()`
|
Const,
|
||||||
// returns true. Specifically, if it's only `min_const_generics`, it will still require
|
|
||||||
// ordering consts after types.
|
|
||||||
Const { unordered: bool },
|
|
||||||
// `Infer` is not actually constructed directly from the AST, but is implicitly constructed
|
// `Infer` is not actually constructed directly from the AST, but is implicitly constructed
|
||||||
// during HIR lowering, and `ParamKindOrd` will implicitly order inferred variables last.
|
// during HIR lowering, and `ParamKindOrd` will implicitly order inferred variables last.
|
||||||
Infer,
|
Infer,
|
||||||
|
@ -346,11 +343,7 @@ impl Ord for ParamKindOrd {
|
||||||
use ParamKindOrd::*;
|
use ParamKindOrd::*;
|
||||||
let to_int = |v| match v {
|
let to_int = |v| match v {
|
||||||
Lifetime => 0,
|
Lifetime => 0,
|
||||||
Infer | Type | Const { unordered: true } => 1,
|
Infer | Type | Const => 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,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
to_int(*self).cmp(&to_int(*other))
|
to_int(*self).cmp(&to_int(*other))
|
||||||
|
|
|
@ -894,7 +894,6 @@ impl<'a> AstValidator<'a> {
|
||||||
/// Checks that generic parameters are in the correct order,
|
/// Checks that generic parameters are in the correct order,
|
||||||
/// which is lifetimes, then types and then consts. (`<'a, T, const N: usize>`)
|
/// which is lifetimes, then types and then consts. (`<'a, T, const N: usize>`)
|
||||||
fn validate_generic_param_order(
|
fn validate_generic_param_order(
|
||||||
sess: &Session,
|
|
||||||
handler: &rustc_errors::Handler,
|
handler: &rustc_errors::Handler,
|
||||||
generics: &[GenericParam],
|
generics: &[GenericParam],
|
||||||
span: Span,
|
span: Span,
|
||||||
|
@ -911,8 +910,7 @@ fn validate_generic_param_order(
|
||||||
GenericParamKind::Type { default: _ } => (ParamKindOrd::Type, ident.to_string()),
|
GenericParamKind::Type { default: _ } => (ParamKindOrd::Type, ident.to_string()),
|
||||||
GenericParamKind::Const { ref ty, kw_span: _, default: _ } => {
|
GenericParamKind::Const { ref ty, kw_span: _, default: _ } => {
|
||||||
let ty = pprust::ty_to_string(ty);
|
let ty = pprust::ty_to_string(ty);
|
||||||
let unordered = sess.features_untracked().unordered_const_ty_params();
|
(ParamKindOrd::Const, format!("const {}: {}", ident, ty))
|
||||||
(ParamKindOrd::Const { unordered }, format!("const {}: {}", ident, ty))
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
param_idents.push((kind, ord_kind, bounds, idx, ident));
|
param_idents.push((kind, ord_kind, bounds, idx, ident));
|
||||||
|
@ -968,14 +966,7 @@ fn validate_generic_param_order(
|
||||||
);
|
);
|
||||||
err.span_suggestion(
|
err.span_suggestion(
|
||||||
span,
|
span,
|
||||||
&format!(
|
"reorder the parameters: lifetimes, then consts and types",
|
||||||
"reorder the parameters: lifetimes, {}",
|
|
||||||
if sess.features_untracked().unordered_const_ty_params() {
|
|
||||||
"then consts and types"
|
|
||||||
} else {
|
|
||||||
"then types, then consts"
|
|
||||||
}
|
|
||||||
),
|
|
||||||
ordered_params.clone(),
|
ordered_params.clone(),
|
||||||
Applicability::MachineApplicable,
|
Applicability::MachineApplicable,
|
||||||
);
|
);
|
||||||
|
@ -1342,8 +1333,6 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_generics(&mut self, generics: &'a Generics) {
|
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;
|
let mut prev_param_default = None;
|
||||||
for param in &generics.params {
|
for param in &generics.params {
|
||||||
match param.kind {
|
match param.kind {
|
||||||
|
@ -1358,12 +1347,6 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
|
||||||
span,
|
span,
|
||||||
"generic parameters with a default must be trailing",
|
"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();
|
err.emit();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1371,12 +1354,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
validate_generic_param_order(
|
validate_generic_param_order(self.err_handler(), &generics.params, generics.span);
|
||||||
self.session,
|
|
||||||
self.err_handler(),
|
|
||||||
&generics.params,
|
|
||||||
generics.span,
|
|
||||||
);
|
|
||||||
|
|
||||||
for predicate in &generics.where_clause.predicates {
|
for predicate in &generics.where_clause.predicates {
|
||||||
if let WherePredicate::EqPredicate(ref predicate) = *predicate {
|
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!(half_open_range_patterns, "half-open range patterns are unstable");
|
||||||
gate_all!(inline_const, "inline-const is experimental");
|
gate_all!(inline_const, "inline-const is experimental");
|
||||||
gate_all!(inline_const_pat, "inline-const in pattern position 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 {
|
if sess.parse_sess.span_diagnostic.err_count() == 0 {
|
||||||
// Errors for `destructuring_assignment` can get quite noisy, especially where `_` is
|
// Errors for `destructuring_assignment` can get quite noisy, especially where `_` is
|
||||||
// involved, so we only emit errors where there are no other parsing errors.
|
// 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),
|
(accepted, while_let, "1.0.0", None, None),
|
||||||
/// Allows `#![windows_subsystem]`.
|
/// Allows `#![windows_subsystem]`.
|
||||||
(accepted, windows_subsystem, "1.18.0", Some(37499), None),
|
(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.
|
// 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
|
/// 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
|
/// unanticipated results, such as compiler crashes. We warn the user about these
|
||||||
/// to alert them.
|
/// to alert them.
|
||||||
|
@ -334,8 +330,6 @@ declare_features! (
|
||||||
(active, const_fn_trait_bound, "1.53.0", Some(57563), None),
|
(active, const_fn_trait_bound, "1.53.0", Some(57563), None),
|
||||||
/// Allows `for _ in _` loops in const contexts.
|
/// Allows `for _ in _` loops in const contexts.
|
||||||
(active, const_for, "1.56.0", Some(87575), None),
|
(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`.
|
/// Allows argument and return position `impl Trait` in a `const fn`.
|
||||||
(active, const_impl_trait, "1.48.0", Some(77463), None),
|
(active, const_impl_trait, "1.48.0", Some(77463), None),
|
||||||
/// Allows using `&mut` in constant functions.
|
/// 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 {
|
match self {
|
||||||
GenericArg::Lifetime(_) => ast::ParamKindOrd::Lifetime,
|
GenericArg::Lifetime(_) => ast::ParamKindOrd::Lifetime,
|
||||||
GenericArg::Type(_) => ast::ParamKindOrd::Type,
|
GenericArg::Type(_) => ast::ParamKindOrd::Type,
|
||||||
GenericArg::Const(_) => {
|
GenericArg::Const(_) => ast::ParamKindOrd::Const,
|
||||||
ast::ParamKindOrd::Const { unordered: feats.unordered_const_ty_params() }
|
|
||||||
}
|
|
||||||
GenericArg::Infer(_) => ast::ParamKindOrd::Infer,
|
GenericArg::Infer(_) => ast::ParamKindOrd::Infer,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,13 +24,11 @@ impl GenericParamDefKind {
|
||||||
GenericParamDefKind::Const { .. } => "constant",
|
GenericParamDefKind::Const { .. } => "constant",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn to_ord(&self, tcx: TyCtxt<'_>) -> ast::ParamKindOrd {
|
pub fn to_ord(&self) -> ast::ParamKindOrd {
|
||||||
match self {
|
match self {
|
||||||
GenericParamDefKind::Lifetime => ast::ParamKindOrd::Lifetime,
|
GenericParamDefKind::Lifetime => ast::ParamKindOrd::Lifetime,
|
||||||
GenericParamDefKind::Type { .. } => ast::ParamKindOrd::Type,
|
GenericParamDefKind::Type { .. } => ast::ParamKindOrd::Type,
|
||||||
GenericParamDefKind::Const { .. } => {
|
GenericParamDefKind::Const { .. } => ast::ParamKindOrd::Const,
|
||||||
ast::ParamKindOrd::Const { unordered: tcx.features().unordered_const_ty_params() }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ use rustc_ast::{
|
||||||
self as ast, Attribute, GenericBounds, GenericParam, GenericParamKind, WhereClause,
|
self as ast, Attribute, GenericBounds, GenericParam, GenericParamKind, WhereClause,
|
||||||
};
|
};
|
||||||
use rustc_errors::PResult;
|
use rustc_errors::PResult;
|
||||||
use rustc_span::symbol::{kw, sym};
|
use rustc_span::symbol::kw;
|
||||||
|
|
||||||
impl<'a> Parser<'a> {
|
impl<'a> Parser<'a> {
|
||||||
/// Parses bounds of a lifetime parameter `BOUND + BOUND + BOUND`, possibly with trailing `+`.
|
/// Parses bounds of a lifetime parameter `BOUND + BOUND + BOUND`, possibly with trailing `+`.
|
||||||
|
@ -59,19 +59,8 @@ impl<'a> Parser<'a> {
|
||||||
self.expect(&token::Colon)?;
|
self.expect(&token::Colon)?;
|
||||||
let ty = self.parse_ty()?;
|
let ty = self.parse_ty()?;
|
||||||
|
|
||||||
// Parse optional const generics default value, taking care of feature gating the spans
|
// Parse optional const generics default value.
|
||||||
// with the unstable syntax mechanism.
|
let default = if self.eat(&token::Eq) { Some(self.parse_const_arg()?) } else { None };
|
||||||
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
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(GenericParam {
|
Ok(GenericParam {
|
||||||
ident,
|
ident,
|
||||||
|
|
|
@ -131,8 +131,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
let kind_ord = param.kind.to_ord(tcx);
|
let kind_ord = param.kind.to_ord();
|
||||||
let arg_ord = arg.to_ord(tcx.features());
|
let arg_ord = arg.to_ord();
|
||||||
|
|
||||||
// This note is only true when generic parameters are strictly ordered by their kind.
|
// 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 {
|
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
|
.params
|
||||||
.clone()
|
.clone()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|param| {
|
.map(|param| (param.kind.to_ord(), param))
|
||||||
(
|
|
||||||
match param.kind {
|
|
||||||
GenericParamDefKind::Lifetime => {
|
|
||||||
ParamKindOrd::Lifetime
|
|
||||||
}
|
|
||||||
GenericParamDefKind::Type { .. } => {
|
|
||||||
ParamKindOrd::Type
|
|
||||||
}
|
|
||||||
GenericParamDefKind::Const { .. } => {
|
|
||||||
ParamKindOrd::Const {
|
|
||||||
unordered: tcx
|
|
||||||
.features()
|
|
||||||
.unordered_const_ty_params(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
param,
|
|
||||||
)
|
|
||||||
})
|
|
||||||
.collect::<Vec<(ParamKindOrd, GenericParamDef)>>();
|
.collect::<Vec<(ParamKindOrd, GenericParamDef)>>();
|
||||||
param_types_present.sort_by_key(|(ord, _)| *ord);
|
param_types_present.sort_by_key(|(ord, _)| *ord);
|
||||||
let (mut param_types_present, ordered_params): (
|
let (mut param_types_present, ordered_params): (
|
||||||
|
@ -330,16 +311,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||||
tcx,
|
tcx,
|
||||||
arg,
|
arg,
|
||||||
param,
|
param,
|
||||||
!args_iter.clone().is_sorted_by_key(|arg| match arg {
|
!args_iter.clone().is_sorted_by_key(|arg| arg.to_ord()),
|
||||||
GenericArg::Lifetime(_) => ParamKindOrd::Lifetime,
|
|
||||||
GenericArg::Type(_) => ParamKindOrd::Type,
|
|
||||||
GenericArg::Const(_) => ParamKindOrd::Const {
|
|
||||||
unordered: tcx
|
|
||||||
.features()
|
|
||||||
.unordered_const_ty_params(),
|
|
||||||
},
|
|
||||||
GenericArg::Infer(_) => ParamKindOrd::Infer,
|
|
||||||
}),
|
|
||||||
Some(&format!(
|
Some(&format!(
|
||||||
"reorder the arguments: {}: `<{}>`",
|
"reorder the arguments: {}: `<{}>`",
|
||||||
param_types_present
|
param_types_present
|
||||||
|
|
|
@ -696,7 +696,6 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) {
|
||||||
hir::GenericParamKind::Lifetime { .. } | hir::GenericParamKind::Type { .. } => (),
|
hir::GenericParamKind::Lifetime { .. } | hir::GenericParamKind::Type { .. } => (),
|
||||||
|
|
||||||
// Const parameters are well formed if their type is structural match.
|
// 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: _ } => {
|
hir::GenericParamKind::Const { ty: hir_ty, default: _ } => {
|
||||||
let ty = tcx.type_of(tcx.hir().local_def_id(param.hir_id));
|
let ty = tcx.type_of(tcx.hir().local_def_id(param.hir_id));
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue