Switched to unordered field in ParamKindOrd

Run fmt
This commit is contained in:
kadmin 2020-08-06 00:23:17 +00:00
parent 1ae1a6332c
commit 4f461f5d12
3 changed files with 17 additions and 9 deletions

View File

@ -313,8 +313,7 @@ pub type GenericBounds = Vec<GenericBound>;
pub enum ParamKindOrd {
Lifetime,
Type,
Const,
ConstUnordered,
Const { unordered: bool },
}
impl fmt::Display for ParamKindOrd {
@ -322,8 +321,7 @@ impl fmt::Display for ParamKindOrd {
match self {
ParamKindOrd::Lifetime => "lifetime".fmt(f),
ParamKindOrd::Type => "type".fmt(f),
ParamKindOrd::Const => "const".fmt(f),
ParamKindOrd::ConstUnordered => "const".fmt(f),
ParamKindOrd::Const { .. } => "const".fmt(f),
}
}
}

View File

@ -735,7 +735,7 @@ fn validate_generic_param_order<'a>(
}
let max_param = &mut max_param;
match max_param {
Some(ParamKindOrd::ConstUnordered) if kind != ParamKindOrd::Lifetime => (),
Some(ParamKindOrd::Const { unordered: true }) if kind != ParamKindOrd::Lifetime => (),
Some(max_param) if *max_param > kind => {
let entry = out_of_order.entry(kind).or_insert((*max_param, vec![]));
entry.1.push(span);
@ -1159,7 +1159,11 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
GenericParamKind::Type { default: _ } => (ParamKindOrd::Type, ident),
GenericParamKind::Const { ref ty, kw_span: _ } => {
let ty = pprust::ty_to_string(ty);
(ParamKindOrd::Const, Some(format!("const {}: {}", param.ident, ty)))
let unordered = self.session.features_untracked().const_generics;
(
ParamKindOrd::Const { unordered },
Some(format!("const {}: {}", param.ident, ty)),
)
}
};
(kind, Some(&*param.bounds), param.ident.span, ident)

View File

@ -489,10 +489,11 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
kind,
);
let unordered = sess.features_untracked().const_generics;
let kind_ord = match kind {
"lifetime" => ParamKindOrd::Lifetime,
"type" => ParamKindOrd::Type,
"constant" => ParamKindOrd::Const,
"constant" => ParamKindOrd::Const { unordered },
// It's more concise to match on the string representation, though it means
// the match is non-exhaustive.
_ => bug!("invalid generic parameter kind {}", kind),
@ -500,7 +501,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
let arg_ord = match arg {
GenericArg::Lifetime(_) => ParamKindOrd::Lifetime,
GenericArg::Type(_) => ParamKindOrd::Type,
GenericArg::Const(_) => ParamKindOrd::Const,
GenericArg::Const(_) => ParamKindOrd::Const { unordered },
};
// This note will be true as long as generic parameters are strictly ordered by their kind.
@ -672,7 +673,12 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
ParamKindOrd::Type
}
GenericParamDefKind::Const => {
ParamKindOrd::Const
ParamKindOrd::Const {
unordered: tcx
.sess
.features_untracked()
.const_generics,
}
}
},
param,