From 7a4fdcbbc50a177a766fceb3bd2b9d35b2b5678e Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 28 Jun 2022 08:56:54 +1000 Subject: [PATCH] Remove unnecessary fields from `EnumNonMatchingCollapsed`. The `&[ast::Variant]` field isn't used. The `Vec` field is only used for its length, but that's always the same as the length of the `&[Ident]` and so isn't necessary. --- .../src/deriving/cmp/ord.rs | 4 +-- .../src/deriving/cmp/partial_eq.rs | 2 +- .../src/deriving/cmp/partial_ord.rs | 4 +-- .../src/deriving/generic/mod.rs | 34 +++++-------------- 4 files changed, 14 insertions(+), 30 deletions(-) diff --git a/compiler/rustc_builtin_macros/src/deriving/cmp/ord.rs b/compiler/rustc_builtin_macros/src/deriving/cmp/ord.rs index 2b3ac0a86c1..5823d6fc40b 100644 --- a/compiler/rustc_builtin_macros/src/deriving/cmp/ord.rs +++ b/compiler/rustc_builtin_macros/src/deriving/cmp/ord.rs @@ -99,8 +99,8 @@ pub fn cs_cmp(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>) -> P< cx.expr_match(span, new, vec![eq_arm, neq_arm]) }, cx.expr_path(equals_path.clone()), - Box::new(|cx, span, (self_args, tag_tuple), _non_self_args| { - if self_args.len() != 2 { + Box::new(|cx, span, tag_tuple| { + if tag_tuple.len() != 2 { cx.span_bug(span, "not exactly 2 arguments in `derive(Ord)`") } else { ordering_collapsed(cx, span, tag_tuple) diff --git a/compiler/rustc_builtin_macros/src/deriving/cmp/partial_eq.rs b/compiler/rustc_builtin_macros/src/deriving/cmp/partial_eq.rs index eead8b37024..a5b2e6b114f 100644 --- a/compiler/rustc_builtin_macros/src/deriving/cmp/partial_eq.rs +++ b/compiler/rustc_builtin_macros/src/deriving/cmp/partial_eq.rs @@ -48,7 +48,7 @@ pub fn expand_deriving_partial_eq( None => cx.expr_bool(span, base), } }, - Box::new(|cx, span, _, _| cx.expr_bool(span, !base)), + Box::new(|cx, span, _| cx.expr_bool(span, !base)), cx, span, substr, diff --git a/compiler/rustc_builtin_macros/src/deriving/cmp/partial_ord.rs b/compiler/rustc_builtin_macros/src/deriving/cmp/partial_ord.rs index d28ac822a1e..124e16197f2 100644 --- a/compiler/rustc_builtin_macros/src/deriving/cmp/partial_ord.rs +++ b/compiler/rustc_builtin_macros/src/deriving/cmp/partial_ord.rs @@ -102,8 +102,8 @@ pub fn cs_partial_cmp(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_ cx.expr_match(span, new, vec![eq_arm, neq_arm]) }, equals_expr, - Box::new(|cx, span, (self_args, tag_tuple), _non_self_args| { - if self_args.len() != 2 { + Box::new(|cx, span, tag_tuple| { + if tag_tuple.len() != 2 { cx.span_bug(span, "not exactly 2 arguments in `derive(PartialOrd)`") } else { let lft = cx.expr_addr_of(span, cx.expr_ident(span, tag_tuple[0])); diff --git a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs index e6b21b3ff94..82eb064edb0 100644 --- a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs +++ b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs @@ -146,8 +146,6 @@ //! //! ```{.text} //! EnumNonMatchingCollapsed( -//! vec![, ], -//! &[, ], //! &[, ]) //! ``` //! @@ -299,13 +297,10 @@ pub enum SubstructureFields<'a> { /// variant. EnumMatching(usize, usize, &'a ast::Variant, Vec>), - /// Non-matching variants of the enum, but with all state hidden from - /// the consequent code. The first component holds `Ident`s for all of - /// the `Self` arguments; the second component is a slice of all of the - /// variants for the enum itself, and the third component is a list of - /// `Ident`s bound to the variant index values for each of the actual - /// input `Self` arguments. - EnumNonMatchingCollapsed(Vec, &'a [ast::Variant], &'a [Ident]), + /// Non-matching variants of the enum, but with all state hidden from the + /// consequent code. The field is a list of `Ident`s bound to the variant + /// index values for each of the actual input `Self` arguments. + EnumNonMatchingCollapsed(&'a [Ident]), /// A static method where `Self` is a struct. StaticStruct(&'a ast::VariantData, StaticFields), @@ -318,13 +313,10 @@ pub enum SubstructureFields<'a> { pub type CombineSubstructureFunc<'a> = Box, Span, &Substructure<'_>) -> P + 'a>; -/// Deal with non-matching enum variants. The tuple is a list of -/// identifiers (one for each `Self` argument, which could be any of the -/// variants since they have been collapsed together) and the identifiers -/// holding the variant index value for each of the `Self` arguments. The -/// last argument is all the non-`Self` args of the method being derived. +/// Deal with non-matching enum variants. The slice is the identifiers holding +/// the variant index value for each of the `Self` arguments. pub type EnumNonMatchCollapsedFunc<'a> = - Box, Span, (&[Ident], &[Ident]), &[P]) -> P + 'a>; + Box, Span, &[Ident]) -> P + 'a>; pub fn combine_substructure( f: CombineSubstructureFunc<'_>, @@ -1184,11 +1176,6 @@ impl<'a> MethodDef<'a> { ) .collect::>(); - let self_arg_idents = self_arg_names - .iter() - .map(|name| Ident::from_str_and_span(name, span)) - .collect::>(); - // The `vi_idents` will be bound, solely in the catch-all, to // a series of let statements mapping each self_arg to an int // value corresponding to its discriminant. @@ -1203,8 +1190,7 @@ impl<'a> MethodDef<'a> { // Builds, via callback to call_substructure_method, the // delegated expression that handles the catch-all case, // using `__variants_tuple` to drive logic if necessary. - let catch_all_substructure = - EnumNonMatchingCollapsed(self_arg_idents, &variants, &vi_idents); + let catch_all_substructure = EnumNonMatchingCollapsed(&vi_idents); let first_fieldless = variants.iter().find(|v| v.data.fields().is_empty()); @@ -1657,9 +1643,7 @@ pub fn cs_fold_enumnonmatch( substructure: &Substructure<'_>, ) -> P { match *substructure.fields { - EnumNonMatchingCollapsed(ref all_args, _, tuple) => { - enum_nonmatch_f(cx, trait_span, (&all_args[..], tuple), substructure.nonself_args) - } + EnumNonMatchingCollapsed(tuple) => enum_nonmatch_f(cx, trait_span, tuple), _ => cx.span_bug(trait_span, "cs_fold_enumnonmatch expected an EnumNonMatchingCollapsed"), } }