Skip to content

Commit 7a4fdcb

Browse files
committed
Remove unnecessary fields from EnumNonMatchingCollapsed.
The `&[ast::Variant]` field isn't used. The `Vec<Ident>` field is only used for its length, but that's always the same as the length of the `&[Ident]` and so isn't necessary.
1 parent 72a1621 commit 7a4fdcb

File tree

4 files changed

+14
-30
lines changed

4 files changed

+14
-30
lines changed

compiler/rustc_builtin_macros/src/deriving/cmp/ord.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ pub fn cs_cmp(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>) -> P<
9999
cx.expr_match(span, new, vec![eq_arm, neq_arm])
100100
},
101101
cx.expr_path(equals_path.clone()),
102-
Box::new(|cx, span, (self_args, tag_tuple), _non_self_args| {
103-
if self_args.len() != 2 {
102+
Box::new(|cx, span, tag_tuple| {
103+
if tag_tuple.len() != 2 {
104104
cx.span_bug(span, "not exactly 2 arguments in `derive(Ord)`")
105105
} else {
106106
ordering_collapsed(cx, span, tag_tuple)

compiler/rustc_builtin_macros/src/deriving/cmp/partial_eq.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pub fn expand_deriving_partial_eq(
4848
None => cx.expr_bool(span, base),
4949
}
5050
},
51-
Box::new(|cx, span, _, _| cx.expr_bool(span, !base)),
51+
Box::new(|cx, span, _| cx.expr_bool(span, !base)),
5252
cx,
5353
span,
5454
substr,

compiler/rustc_builtin_macros/src/deriving/cmp/partial_ord.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ pub fn cs_partial_cmp(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_
102102
cx.expr_match(span, new, vec![eq_arm, neq_arm])
103103
},
104104
equals_expr,
105-
Box::new(|cx, span, (self_args, tag_tuple), _non_self_args| {
106-
if self_args.len() != 2 {
105+
Box::new(|cx, span, tag_tuple| {
106+
if tag_tuple.len() != 2 {
107107
cx.span_bug(span, "not exactly 2 arguments in `derive(PartialOrd)`")
108108
} else {
109109
let lft = cx.expr_addr_of(span, cx.expr_ident(span, tag_tuple[0]));

compiler/rustc_builtin_macros/src/deriving/generic/mod.rs

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,6 @@
146146
//!
147147
//! ```{.text}
148148
//! EnumNonMatchingCollapsed(
149-
//! vec![<ident of self>, <ident of __arg_1>],
150-
//! &[<ast::Variant for C0>, <ast::Variant for C1>],
151149
//! &[<ident for self index value>, <ident of __arg_1 index value>])
152150
//! ```
153151
//!
@@ -299,13 +297,10 @@ pub enum SubstructureFields<'a> {
299297
/// variant.
300298
EnumMatching(usize, usize, &'a ast::Variant, Vec<FieldInfo<'a>>),
301299

302-
/// Non-matching variants of the enum, but with all state hidden from
303-
/// the consequent code. The first component holds `Ident`s for all of
304-
/// the `Self` arguments; the second component is a slice of all of the
305-
/// variants for the enum itself, and the third component is a list of
306-
/// `Ident`s bound to the variant index values for each of the actual
307-
/// input `Self` arguments.
308-
EnumNonMatchingCollapsed(Vec<Ident>, &'a [ast::Variant], &'a [Ident]),
300+
/// Non-matching variants of the enum, but with all state hidden from the
301+
/// consequent code. The field is a list of `Ident`s bound to the variant
302+
/// index values for each of the actual input `Self` arguments.
303+
EnumNonMatchingCollapsed(&'a [Ident]),
309304

310305
/// A static method where `Self` is a struct.
311306
StaticStruct(&'a ast::VariantData, StaticFields),
@@ -318,13 +313,10 @@ pub enum SubstructureFields<'a> {
318313
pub type CombineSubstructureFunc<'a> =
319314
Box<dyn FnMut(&mut ExtCtxt<'_>, Span, &Substructure<'_>) -> P<Expr> + 'a>;
320315

321-
/// Deal with non-matching enum variants. The tuple is a list of
322-
/// identifiers (one for each `Self` argument, which could be any of the
323-
/// variants since they have been collapsed together) and the identifiers
324-
/// holding the variant index value for each of the `Self` arguments. The
325-
/// last argument is all the non-`Self` args of the method being derived.
316+
/// Deal with non-matching enum variants. The slice is the identifiers holding
317+
/// the variant index value for each of the `Self` arguments.
326318
pub type EnumNonMatchCollapsedFunc<'a> =
327-
Box<dyn FnMut(&mut ExtCtxt<'_>, Span, (&[Ident], &[Ident]), &[P<Expr>]) -> P<Expr> + 'a>;
319+
Box<dyn FnMut(&mut ExtCtxt<'_>, Span, &[Ident]) -> P<Expr> + 'a>;
328320

329321
pub fn combine_substructure(
330322
f: CombineSubstructureFunc<'_>,
@@ -1184,11 +1176,6 @@ impl<'a> MethodDef<'a> {
11841176
)
11851177
.collect::<Vec<String>>();
11861178

1187-
let self_arg_idents = self_arg_names
1188-
.iter()
1189-
.map(|name| Ident::from_str_and_span(name, span))
1190-
.collect::<Vec<Ident>>();
1191-
11921179
// The `vi_idents` will be bound, solely in the catch-all, to
11931180
// a series of let statements mapping each self_arg to an int
11941181
// value corresponding to its discriminant.
@@ -1203,8 +1190,7 @@ impl<'a> MethodDef<'a> {
12031190
// Builds, via callback to call_substructure_method, the
12041191
// delegated expression that handles the catch-all case,
12051192
// using `__variants_tuple` to drive logic if necessary.
1206-
let catch_all_substructure =
1207-
EnumNonMatchingCollapsed(self_arg_idents, &variants, &vi_idents);
1193+
let catch_all_substructure = EnumNonMatchingCollapsed(&vi_idents);
12081194

12091195
let first_fieldless = variants.iter().find(|v| v.data.fields().is_empty());
12101196

@@ -1657,9 +1643,7 @@ pub fn cs_fold_enumnonmatch(
16571643
substructure: &Substructure<'_>,
16581644
) -> P<Expr> {
16591645
match *substructure.fields {
1660-
EnumNonMatchingCollapsed(ref all_args, _, tuple) => {
1661-
enum_nonmatch_f(cx, trait_span, (&all_args[..], tuple), substructure.nonself_args)
1662-
}
1646+
EnumNonMatchingCollapsed(tuple) => enum_nonmatch_f(cx, trait_span, tuple),
16631647
_ => cx.span_bug(trait_span, "cs_fold_enumnonmatch expected an EnumNonMatchingCollapsed"),
16641648
}
16651649
}

0 commit comments

Comments
 (0)