Skip to content

Commit 4f461f5

Browse files
committed
Switched to unordered field in ParamKindOrd
Run fmt
1 parent 1ae1a63 commit 4f461f5

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

src/librustc_ast/ast.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -313,17 +313,15 @@ pub type GenericBounds = Vec<GenericBound>;
313313
pub enum ParamKindOrd {
314314
Lifetime,
315315
Type,
316-
Const,
317-
ConstUnordered,
316+
Const { unordered: bool },
318317
}
319318

320319
impl fmt::Display for ParamKindOrd {
321320
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
322321
match self {
323322
ParamKindOrd::Lifetime => "lifetime".fmt(f),
324323
ParamKindOrd::Type => "type".fmt(f),
325-
ParamKindOrd::Const => "const".fmt(f),
326-
ParamKindOrd::ConstUnordered => "const".fmt(f),
324+
ParamKindOrd::Const { .. } => "const".fmt(f),
327325
}
328326
}
329327
}

src/librustc_ast_passes/ast_validation.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ fn validate_generic_param_order<'a>(
735735
}
736736
let max_param = &mut max_param;
737737
match max_param {
738-
Some(ParamKindOrd::ConstUnordered) if kind != ParamKindOrd::Lifetime => (),
738+
Some(ParamKindOrd::Const { unordered: true }) if kind != ParamKindOrd::Lifetime => (),
739739
Some(max_param) if *max_param > kind => {
740740
let entry = out_of_order.entry(kind).or_insert((*max_param, vec![]));
741741
entry.1.push(span);
@@ -1159,7 +1159,11 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
11591159
GenericParamKind::Type { default: _ } => (ParamKindOrd::Type, ident),
11601160
GenericParamKind::Const { ref ty, kw_span: _ } => {
11611161
let ty = pprust::ty_to_string(ty);
1162-
(ParamKindOrd::Const, Some(format!("const {}: {}", param.ident, ty)))
1162+
let unordered = self.session.features_untracked().const_generics;
1163+
(
1164+
ParamKindOrd::Const { unordered },
1165+
Some(format!("const {}: {}", param.ident, ty)),
1166+
)
11631167
}
11641168
};
11651169
(kind, Some(&*param.bounds), param.ident.span, ident)

src/librustc_typeck/astconv.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -489,18 +489,19 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
489489
kind,
490490
);
491491

492+
let unordered = sess.features_untracked().const_generics;
492493
let kind_ord = match kind {
493494
"lifetime" => ParamKindOrd::Lifetime,
494495
"type" => ParamKindOrd::Type,
495-
"constant" => ParamKindOrd::Const,
496+
"constant" => ParamKindOrd::Const { unordered },
496497
// It's more concise to match on the string representation, though it means
497498
// the match is non-exhaustive.
498499
_ => bug!("invalid generic parameter kind {}", kind),
499500
};
500501
let arg_ord = match arg {
501502
GenericArg::Lifetime(_) => ParamKindOrd::Lifetime,
502503
GenericArg::Type(_) => ParamKindOrd::Type,
503-
GenericArg::Const(_) => ParamKindOrd::Const,
504+
GenericArg::Const(_) => ParamKindOrd::Const { unordered },
504505
};
505506

506507
// 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 {
672673
ParamKindOrd::Type
673674
}
674675
GenericParamDefKind::Const => {
675-
ParamKindOrd::Const
676+
ParamKindOrd::Const {
677+
unordered: tcx
678+
.sess
679+
.features_untracked()
680+
.const_generics,
681+
}
676682
}
677683
},
678684
param,

0 commit comments

Comments
 (0)