From f438cf83aa99ca29c8229594b8f28c63bee786ac Mon Sep 17 00:00:00 2001 From: cyrgani Date: Tue, 15 Sep 2026 12:37:49 +0000 Subject: [PATCH 1/9] put the check for empty `assert_fields_are_eq` at the right spot --- .../src/deriving/generic/mod.rs | 22 ++++++++---------- .../mgca/const-ctor-overflow-eval.rs | 3 +-- .../mgca/const-ctor-overflow-eval.stderr | 23 ++++++++++--------- tests/ui/derives/deriving-all-codegen.stdout | 7 +----- 4 files changed, 24 insertions(+), 31 deletions(-) diff --git a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs index a041e83a646ce..599c8e7feab43 100644 --- a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs +++ b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs @@ -837,7 +837,7 @@ impl<'a> TraitDef<'a> { ) -> Box { let field_tys = struct_def.fields().iter().map(|field| &*field.ty); - let methods = self.methods.iter().map(|method_def| { + let methods = self.methods.iter().filter_map(|method_def| { let ArgDetails { explicit_self, selflike_args, nonselflike_args, nonself_arg_tys } = method_def.extract_arg_details(cx, self, type_ident, generics); @@ -912,13 +912,7 @@ impl<'a> TraitDef<'a> { ) }; - // `assert_fields_are_eq` has an empty default implementation - if body.0.is_empty() && body.1.is_none() && method_def.name == sym::assert_fields_are_eq - { - return None; - } - - Some(method_def.create_method( + method_def.create_method( cx, self, type_ident, @@ -926,7 +920,7 @@ impl<'a> TraitDef<'a> { explicit_self, nonself_arg_tys, body, - )) + ) }); let is_packed = false; // enums are never packed @@ -1010,7 +1004,11 @@ impl<'a> MethodDef<'a> { explicit_self: Option, nonself_arg_tys: Vec<(Ident, Box)>, body: BlockOrExpr, - ) -> Box { + ) -> Option> { + // `assert_fields_are_eq` has an empty default implementation + if body.0.is_empty() && body.1.is_none() && self.name == sym::assert_fields_are_eq { + return None; + } let span = trait_.span; // Create the generics that aren't for `Self`. let fn_generics = self.generics.clone(); @@ -1041,7 +1039,7 @@ impl<'a> MethodDef<'a> { let defaultness = ast::Defaultness::Implicit; // Create the method. - Box::new(ast::AssocItem { + Some(Box::new(ast::AssocItem { id: ast::DUMMY_NODE_ID, attrs: self.attributes.clone(), span, @@ -1057,7 +1055,7 @@ impl<'a> MethodDef<'a> { eii_impl: None, })), tokens: None, - }) + })) } /// The normal case uses field access. diff --git a/tests/ui/const-generics/mgca/const-ctor-overflow-eval.rs b/tests/ui/const-generics/mgca/const-ctor-overflow-eval.rs index a4538ffff3854..75e936ee8f5e3 100644 --- a/tests/ui/const-generics/mgca/const-ctor-overflow-eval.rs +++ b/tests/ui/const-generics/mgca/const-ctor-overflow-eval.rs @@ -7,13 +7,12 @@ struct U; #[derive(ConstParamTy, PartialEq, Eq)] //~^ ERROR overflow evaluating whether `S` is well-formed -//~| ERROR overflow evaluating whether `S` is well-formed - struct S() where S<{ U }>:; //~^ ERROR overflow evaluating whether `S` is well-formed //~| ERROR overflow evaluating whether `S` is well-formed //~| ERROR overflow evaluating whether `S` is well-formed +//~| ERROR overflow evaluating whether `S` is well-formed fn main() {} diff --git a/tests/ui/const-generics/mgca/const-ctor-overflow-eval.stderr b/tests/ui/const-generics/mgca/const-ctor-overflow-eval.stderr index bb393cad567e5..98ba1ed42ce3c 100644 --- a/tests/ui/const-generics/mgca/const-ctor-overflow-eval.stderr +++ b/tests/ui/const-generics/mgca/const-ctor-overflow-eval.stderr @@ -1,11 +1,11 @@ error[E0275]: overflow evaluating whether `S` is well-formed - --> $DIR/const-ctor-overflow-eval.rs:14:5 + --> $DIR/const-ctor-overflow-eval.rs:12:5 | LL | S<{ U }>:; | ^^^^^^^^ | note: required by a bound in `S` - --> $DIR/const-ctor-overflow-eval.rs:14:5 + --> $DIR/const-ctor-overflow-eval.rs:12:5 | LL | struct S() | - required by a bound in this struct @@ -14,13 +14,13 @@ LL | S<{ U }>:; | ^^^^^^^^ required by this bound in `S` error[E0275]: overflow evaluating whether `S` is well-formed - --> $DIR/const-ctor-overflow-eval.rs:14:5 + --> $DIR/const-ctor-overflow-eval.rs:12:5 | LL | S<{ U }>:; | ^^^^^^^^ | note: required by a bound in `S` - --> $DIR/const-ctor-overflow-eval.rs:14:5 + --> $DIR/const-ctor-overflow-eval.rs:12:5 | LL | struct S() | - required by a bound in this struct @@ -30,13 +30,13 @@ LL | S<{ U }>:; = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error[E0275]: overflow evaluating whether `S` is well-formed - --> $DIR/const-ctor-overflow-eval.rs:14:5 + --> $DIR/const-ctor-overflow-eval.rs:12:5 | LL | S<{ U }>:; | ^^^^^^^^ | note: required by a bound in `S` - --> $DIR/const-ctor-overflow-eval.rs:14:5 + --> $DIR/const-ctor-overflow-eval.rs:12:5 | LL | struct S() | - required by a bound in this struct @@ -52,7 +52,7 @@ LL | #[derive(ConstParamTy, PartialEq, Eq)] | ^^^^^^^^^ | note: required by a bound in `S` - --> $DIR/const-ctor-overflow-eval.rs:14:5 + --> $DIR/const-ctor-overflow-eval.rs:12:5 | LL | struct S() | - required by a bound in this struct @@ -61,19 +61,20 @@ LL | S<{ U }>:; | ^^^^^^^^ required by this bound in `S` error[E0275]: overflow evaluating whether `S` is well-formed - --> $DIR/const-ctor-overflow-eval.rs:8:35 + --> $DIR/const-ctor-overflow-eval.rs:12:5 | -LL | #[derive(ConstParamTy, PartialEq, Eq)] - | ^^ +LL | S<{ U }>:; + | ^^^^^^^^ | note: required by a bound in `S` - --> $DIR/const-ctor-overflow-eval.rs:14:5 + --> $DIR/const-ctor-overflow-eval.rs:12:5 | LL | struct S() | - required by a bound in this struct LL | where LL | S<{ U }>:; | ^^^^^^^^ required by this bound in `S` + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error: aborting due to 5 previous errors diff --git a/tests/ui/derives/deriving-all-codegen.stdout b/tests/ui/derives/deriving-all-codegen.stdout index 436f57bb8ecb9..bf88d1c0cb7aa 100644 --- a/tests/ui/derives/deriving-all-codegen.stdout +++ b/tests/ui/derives/deriving-all-codegen.stdout @@ -61,12 +61,7 @@ impl ::core::cmp::PartialEq for Empty { fn eq(&self, other: &Empty) -> bool { true } } #[automatically_derived] -impl ::core::cmp::Eq for Empty { - #[inline] - #[doc(hidden)] - #[coverage(off)] - fn assert_fields_are_eq(&self) {} -} +impl ::core::cmp::Eq for Empty { } #[automatically_derived] impl ::core::cmp::PartialOrd for Empty { #[inline] From a51fdcba5bfb2d2234e7d90c8d585a324f5f7ad1 Mon Sep 17 00:00:00 2001 From: cyrgani Date: Tue, 15 Sep 2026 19:59:19 +0000 Subject: [PATCH 2/9] micro cleanups --- .../src/deriving/generic/mod.rs | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs index 599c8e7feab43..dabf303286de6 100644 --- a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs +++ b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs @@ -774,6 +774,7 @@ impl<'a> TraitDef<'a> { // Other crates don't need stability attributes, so adding them is not useful, but libcore needs them // on all const trait impls. if self.is_const && cx.ecfg.features.staged_api() { + // #[rustc_const_unstable(feature = "derive_const", issue = "118304")] attrs.push( cx.attr_nested( rustc_ast::AttrItem { @@ -1195,24 +1196,21 @@ impl<'a> MethodDef<'a> { // let __self_discr = ::core::intrinsics::discriminant_value(self); // let __arg1_discr = ::core::intrinsics::discriminant_value(other); // ``` - let get_discr_pieces = |cx: &ExtCtxt<'_>| { - let discr_idents: Vec<_> = prefixes + let get_discr_pieces = || { + let discr_idents = prefixes .iter() - .map(|name| Ident::from_str_and_span(&format!("{name}_discr"), span)) - .collect(); + .map(|name| Ident::from_str_and_span(&format!("{name}_discr"), span)); - let mut discr_exprs: Vec<_> = discr_idents - .iter() - .map(|&ident| cx.expr_addr_of(span, cx.expr_ident(span, ident))) - .collect(); + let mut discr_exprs = + discr_idents.clone().map(|ident| cx.expr_addr_of(span, cx.expr_ident(span, ident))); - let self_expr = discr_exprs.remove(0); - let other_selflike_exprs = discr_exprs; + let self_expr = discr_exprs.next().unwrap(); + let other_selflike_exprs = discr_exprs.collect(); let discr_field = FieldInfo { span, name: None, self_expr, other_selflike_exprs, maybe_scalar: true }; - let discr_let_stmts: ThinVec<_> = iter::zip(&discr_idents, &selflike_args) - .map(|(&ident, selflike_arg)| { + let discr_let_stmts: ThinVec<_> = iter::zip(discr_idents, &selflike_args) + .map(|(ident, selflike_arg)| { let variant_value = deriving::call_intrinsic( cx, span, @@ -1236,7 +1234,7 @@ impl<'a> MethodDef<'a> { // If the type is fieldless and the trait uses the discriminant and // there are multiple variants, we need just an operation on // the discriminant(s). - let (discr_field, mut discr_let_stmts) = get_discr_pieces(cx); + let (discr_field, mut discr_let_stmts) = get_discr_pieces(); let mut discr_check = self.call_substructure_method( cx, trait_, @@ -1371,7 +1369,7 @@ impl<'a> MethodDef<'a> { // to add a discriminant check operation before the match. Otherwise, the match // is enough. if unify_fieldless_variants && variants.len() > 1 { - let (discr_field, mut discr_let_stmts) = get_discr_pieces(cx); + let (discr_field, mut discr_let_stmts) = get_discr_pieces(); // Combine a discriminant check with the match. let mut discr_check_plus_match = self.call_substructure_method( From 08961a71843ad57290bf38f612d17499a286d3ca Mon Sep 17 00:00:00 2001 From: cyrgani Date: Wed, 16 Sep 2026 21:23:52 +0000 Subject: [PATCH 3/9] remove `use_foldl` arg --- .../src/deriving/generic/mod.rs | 14 +- .../rustc_builtin_macros/src/deriving/ord.rs | 39 +++--- .../src/deriving/partial_ord.rs | 120 ++++++++---------- 3 files changed, 73 insertions(+), 100 deletions(-) diff --git a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs index dabf303286de6..8789220893c2b 100644 --- a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs +++ b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs @@ -1537,8 +1537,7 @@ pub(crate) enum CsFold { /// Folds over fields, combining the expressions for each field in a sequence. /// Statics may not be folded over. -pub(crate) fn cs_fold( - use_foldl: bool, +pub(crate) fn cs_foldr( cx: &ExtCtxt<'_>, trait_span: Span, substructure: Substructure<'_>, @@ -1550,8 +1549,7 @@ where match substructure.fields { EnumMatching(.., all_fields) | Struct(_, all_fields) => { let mut fields = all_fields.into_iter(); - - let base_field = if use_foldl { fields.next() } else { fields.next_back() }; + let base_field = fields.next_back(); let Some(base_field) = base_field else { return f(cx, CsFold::Fieldless); @@ -1565,16 +1563,12 @@ where f(cx, CsFold::Combine(span, old, new)) }; - if use_foldl { fields.fold(base_expr, op) } else { fields.rfold(base_expr, op) } + fields.rfold(base_expr, op) } EnumDiscr(discr_field, match_expr) => { let discr_check_expr = f(cx, CsFold::Single(discr_field)); if let Some(match_expr) = match_expr { - if use_foldl { - f(cx, CsFold::Combine(trait_span, discr_check_expr, match_expr)) - } else { - f(cx, CsFold::Combine(trait_span, match_expr, discr_check_expr)) - } + f(cx, CsFold::Combine(trait_span, match_expr, discr_check_expr)) } else { discr_check_expr } diff --git a/compiler/rustc_builtin_macros/src/deriving/ord.rs b/compiler/rustc_builtin_macros/src/deriving/ord.rs index 3c2d95a299a51..feaee242586df 100644 --- a/compiler/rustc_builtin_macros/src/deriving/ord.rs +++ b/compiler/rustc_builtin_macros/src/deriving/ord.rs @@ -52,29 +52,20 @@ pub(crate) fn cs_cmp(cx: &ExtCtxt<'_>, span: Span, substr: Substructure<'_>) -> // ::core::cmp::Ord::cmp(&self.y, &other.y), // cmp => cmp, // } - let expr = cs_fold( - // foldr nests the if-elses correctly, leaving the first field - // as the outermost one, and the last as the innermost. - false, - cx, - span, - substr, - |cx, fold| match fold { - CsFold::Single(field) => { - let [other_expr] = &field.other_selflike_exprs[..] else { - cx.dcx().span_bug(field.span, "not exactly 2 arguments in `derive(Ord)`"); - }; - let args = thin_vec![field.self_expr.clone(), other_expr.clone()]; - cx.expr_call_global(field.span, cmp_path.clone(), args) - } - CsFold::Combine(span, expr1, expr2) => { - let eq_arm = cx.arm(span, cx.pat_path(span, equal_path.clone()), expr1); - let neq_arm = - cx.arm(span, cx.pat_ident(span, test_id), cx.expr_ident(span, test_id)); - cx.expr_match(span, expr2, thin_vec![eq_arm, neq_arm]) - } - CsFold::Fieldless => cx.expr_path(equal_path.clone()), - }, - ); + let expr = cs_foldr(cx, span, substr, |cx, fold| match fold { + CsFold::Single(field) => { + let [other_expr] = &field.other_selflike_exprs[..] else { + cx.dcx().span_bug(field.span, "not exactly 2 arguments in `derive(Ord)`"); + }; + let args = thin_vec![field.self_expr.clone(), other_expr.clone()]; + cx.expr_call_global(field.span, cmp_path.clone(), args) + } + CsFold::Combine(span, expr1, expr2) => { + let eq_arm = cx.arm(span, cx.pat_path(span, equal_path.clone()), expr1); + let neq_arm = cx.arm(span, cx.pat_ident(span, test_id), cx.expr_ident(span, test_id)); + cx.expr_match(span, expr2, thin_vec![eq_arm, neq_arm]) + } + CsFold::Fieldless => cx.expr_path(equal_path.clone()), + }); BlockOrExpr::new_expr(expr) } diff --git a/compiler/rustc_builtin_macros/src/deriving/partial_ord.rs b/compiler/rustc_builtin_macros/src/deriving/partial_ord.rs index fe5e48b11367d..abf681cb59b38 100644 --- a/compiler/rustc_builtin_macros/src/deriving/partial_ord.rs +++ b/compiler/rustc_builtin_macros/src/deriving/partial_ord.rs @@ -124,73 +124,61 @@ fn cs_partial_cmp( // ::core::cmp::PartialOrd::partial_cmp(&self.y, &other.y), // cmp => cmp, // } - let expr = cs_fold( - // foldr nests the if-elses correctly, leaving the first field - // as the outermost one, and the last as the innermost. - false, - cx, - span, - substr, - |cx, fold| match fold { - CsFold::Single(field) => { - let [other_expr] = &field.other_selflike_exprs[..] else { - cx.dcx() - .span_bug(field.span, "not exactly 2 arguments in `derive(PartialOrd)`"); - }; - let args = thin_vec![field.self_expr.clone(), other_expr.clone()]; - cx.expr_call_global(field.span, partial_cmp_path.clone(), args) - } - CsFold::Combine(span, mut expr1, expr2) => { - // When the item is an enum, this expands to - // ``` - // match (expr2) { - // Some(Ordering::Equal) => expr1, - // cmp => cmp - // } - // ``` - // where `expr2` is `partial_cmp(self_discr, other_discr)`, and `expr1` is a `match` - // against the enum variants. This means that we begin by comparing the enum discriminants, - // before either inspecting their contents (if they match), or returning - // the `cmp::Ordering` of comparing the enum discriminants. - // ``` - // match partial_cmp(self_discr, other_discr) { - // Some(Ordering::Equal) => match (self, other) { - // (Self::A(self_0), Self::A(other_0)) => partial_cmp(self_0, other_0), - // (Self::B(self_0), Self::B(other_0)) => partial_cmp(self_0, other_0), - // _ => Some(Ordering::Equal) - // } - // cmp => cmp - // } - // ``` - // If we have any certain enum layouts, flipping this results in better codegen - // ``` - // match (self, other) { - // (Self::A(self_0), Self::A(other_0)) => partial_cmp(self_0, other_0), - // _ => partial_cmp(self_discr, other_discr) - // } - // ``` - // Reference: https://github.com/rust-lang/rust/pull/103659#issuecomment-1328126354 + let expr = cs_foldr(cx, span, substr, |cx, fold| match fold { + CsFold::Single(field) => { + let [other_expr] = &field.other_selflike_exprs[..] else { + cx.dcx().span_bug(field.span, "not exactly 2 arguments in `derive(PartialOrd)`"); + }; + let args = thin_vec![field.self_expr.clone(), other_expr.clone()]; + cx.expr_call_global(field.span, partial_cmp_path.clone(), args) + } + CsFold::Combine(span, mut expr1, expr2) => { + // When the item is an enum, this expands to + // ``` + // match (expr2) { + // Some(Ordering::Equal) => expr1, + // cmp => cmp + // } + // ``` + // where `expr2` is `partial_cmp(self_discr, other_discr)`, and `expr1` is a `match` + // against the enum variants. This means that we begin by comparing the enum discriminants, + // before either inspecting their contents (if they match), or returning + // the `cmp::Ordering` of comparing the enum discriminants. + // ``` + // match partial_cmp(self_discr, other_discr) { + // Some(Ordering::Equal) => match (self, other) { + // (Self::A(self_0), Self::A(other_0)) => partial_cmp(self_0, other_0), + // (Self::B(self_0), Self::B(other_0)) => partial_cmp(self_0, other_0), + // _ => Some(Ordering::Equal) + // } + // cmp => cmp + // } + // ``` + // If we have any certain enum layouts, flipping this results in better codegen + // ``` + // match (self, other) { + // (Self::A(self_0), Self::A(other_0)) => partial_cmp(self_0, other_0), + // _ => partial_cmp(self_discr, other_discr) + // } + // ``` + // Reference: https://github.com/rust-lang/rust/pull/103659#issuecomment-1328126354 - if !discr_then_data - && let ExprKind::Match(_, arms, _) = &mut expr1.kind - && let Some(last) = arms.last_mut() - && let PatKind::Wild = last.pat.kind - { - last.body = Some(expr2); - expr1 - } else { - let eq_arm = cx.arm( - span, - cx.pat_some(span, cx.pat_path(span, equal_path.clone())), - expr1, - ); - let neq_arm = - cx.arm(span, cx.pat_ident(span, test_id), cx.expr_ident(span, test_id)); - cx.expr_match(span, expr2, thin_vec![eq_arm, neq_arm]) - } + if !discr_then_data + && let ExprKind::Match(_, arms, _) = &mut expr1.kind + && let Some(last) = arms.last_mut() + && let PatKind::Wild = last.pat.kind + { + last.body = Some(expr2); + expr1 + } else { + let eq_arm = + cx.arm(span, cx.pat_some(span, cx.pat_path(span, equal_path.clone())), expr1); + let neq_arm = + cx.arm(span, cx.pat_ident(span, test_id), cx.expr_ident(span, test_id)); + cx.expr_match(span, expr2, thin_vec![eq_arm, neq_arm]) } - CsFold::Fieldless => cx.expr_some(span, cx.expr_path(equal_path.clone())), - }, - ); + } + CsFold::Fieldless => cx.expr_some(span, cx.expr_path(equal_path.clone())), + }); BlockOrExpr::new_expr(expr) } From b6d07600e9fc80feeeb483aaa0d27df2dff224f8 Mon Sep 17 00:00:00 2001 From: cyrgani Date: Wed, 16 Sep 2026 21:40:03 +0000 Subject: [PATCH 4/9] split the `cs_fold` closure into three subclosures --- .../src/deriving/generic/mod.rs | 44 +++++++------------ .../rustc_builtin_macros/src/deriving/ord.rs | 17 ++++--- .../src/deriving/partial_ord.rs | 17 ++++--- 3 files changed, 36 insertions(+), 42 deletions(-) diff --git a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs index 8789220893c2b..8aa2180cf235b 100644 --- a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs +++ b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs @@ -1519,56 +1519,44 @@ impl<'a> TraitDef<'a> { } } -/// The function passed to `cs_fold` is called repeatedly with a value of this -/// type. It describes one part of the code generation. The result is always an -/// expression. -pub(crate) enum CsFold { - /// The basic case: a field expression for one or more selflike args. E.g. - /// for `PartialEq::eq` this is something like `self.x == other.x`. - Single(FieldInfo), - - /// The combination of two field expressions. E.g. for `PartialEq::eq` this - /// is something like ` && `. - Combine(Span, Box, Box), - - // The fallback case for a struct or enum variant with no fields. - Fieldless, -} - /// Folds over fields, combining the expressions for each field in a sequence. /// Statics may not be folded over. -pub(crate) fn cs_foldr( +pub(crate) fn cs_foldr( cx: &ExtCtxt<'_>, trait_span: Span, substructure: Substructure<'_>, - mut f: F, -) -> Box -where - F: FnMut(&ExtCtxt<'_>, CsFold) -> Box, -{ + // The basic case: a field expression for one or more selflike args. E.g. + // for `PartialEq::eq` this is something like `self.x == other.x`. + single: impl Fn(FieldInfo) -> Box, + // The combination of two field expressions. E.g. for `PartialEq::eq` this + // is something like ` && `. + combine: impl Fn(Span, Box, Box) -> Box, + // The fallback case for a struct or enum variant with no fields. + fieldless: impl Fn() -> Box, +) -> Box { match substructure.fields { EnumMatching(.., all_fields) | Struct(_, all_fields) => { let mut fields = all_fields.into_iter(); let base_field = fields.next_back(); let Some(base_field) = base_field else { - return f(cx, CsFold::Fieldless); + return fieldless(); }; - let base_expr = f(cx, CsFold::Single(base_field)); + let base_expr = single(base_field); let op = |old, field: FieldInfo| { let span = field.span; - let new = f(cx, CsFold::Single(field)); - f(cx, CsFold::Combine(span, old, new)) + let new = single(field); + combine(span, old, new) }; fields.rfold(base_expr, op) } EnumDiscr(discr_field, match_expr) => { - let discr_check_expr = f(cx, CsFold::Single(discr_field)); + let discr_check_expr = single(discr_field); if let Some(match_expr) = match_expr { - f(cx, CsFold::Combine(trait_span, match_expr, discr_check_expr)) + combine(trait_span, match_expr, discr_check_expr) } else { discr_check_expr } diff --git a/compiler/rustc_builtin_macros/src/deriving/ord.rs b/compiler/rustc_builtin_macros/src/deriving/ord.rs index feaee242586df..663e9b86a9ebe 100644 --- a/compiler/rustc_builtin_macros/src/deriving/ord.rs +++ b/compiler/rustc_builtin_macros/src/deriving/ord.rs @@ -52,20 +52,23 @@ pub(crate) fn cs_cmp(cx: &ExtCtxt<'_>, span: Span, substr: Substructure<'_>) -> // ::core::cmp::Ord::cmp(&self.y, &other.y), // cmp => cmp, // } - let expr = cs_foldr(cx, span, substr, |cx, fold| match fold { - CsFold::Single(field) => { + let expr = cs_foldr( + cx, + span, + substr, + |field| { let [other_expr] = &field.other_selflike_exprs[..] else { cx.dcx().span_bug(field.span, "not exactly 2 arguments in `derive(Ord)`"); }; let args = thin_vec![field.self_expr.clone(), other_expr.clone()]; cx.expr_call_global(field.span, cmp_path.clone(), args) - } - CsFold::Combine(span, expr1, expr2) => { + }, + |span, expr1, expr2| { let eq_arm = cx.arm(span, cx.pat_path(span, equal_path.clone()), expr1); let neq_arm = cx.arm(span, cx.pat_ident(span, test_id), cx.expr_ident(span, test_id)); cx.expr_match(span, expr2, thin_vec![eq_arm, neq_arm]) - } - CsFold::Fieldless => cx.expr_path(equal_path.clone()), - }); + }, + || cx.expr_path(equal_path.clone()), + ); BlockOrExpr::new_expr(expr) } diff --git a/compiler/rustc_builtin_macros/src/deriving/partial_ord.rs b/compiler/rustc_builtin_macros/src/deriving/partial_ord.rs index abf681cb59b38..8c1d89da6ab30 100644 --- a/compiler/rustc_builtin_macros/src/deriving/partial_ord.rs +++ b/compiler/rustc_builtin_macros/src/deriving/partial_ord.rs @@ -124,15 +124,18 @@ fn cs_partial_cmp( // ::core::cmp::PartialOrd::partial_cmp(&self.y, &other.y), // cmp => cmp, // } - let expr = cs_foldr(cx, span, substr, |cx, fold| match fold { - CsFold::Single(field) => { + let expr = cs_foldr( + cx, + span, + substr, + |field| { let [other_expr] = &field.other_selflike_exprs[..] else { cx.dcx().span_bug(field.span, "not exactly 2 arguments in `derive(PartialOrd)`"); }; let args = thin_vec![field.self_expr.clone(), other_expr.clone()]; cx.expr_call_global(field.span, partial_cmp_path.clone(), args) - } - CsFold::Combine(span, mut expr1, expr2) => { + }, + |span, mut expr1, expr2| { // When the item is an enum, this expands to // ``` // match (expr2) { @@ -177,8 +180,8 @@ fn cs_partial_cmp( cx.arm(span, cx.pat_ident(span, test_id), cx.expr_ident(span, test_id)); cx.expr_match(span, expr2, thin_vec![eq_arm, neq_arm]) } - } - CsFold::Fieldless => cx.expr_some(span, cx.expr_path(equal_path.clone())), - }); + }, + || cx.expr_some(span, cx.expr_path(equal_path.clone())), + ); BlockOrExpr::new_expr(expr) } From 8ca7a1c20c1f068a3189757240fc9ad06ab3fa07 Mon Sep 17 00:00:00 2001 From: cyrgani Date: Thu, 17 Sep 2026 13:46:41 +0000 Subject: [PATCH 5/9] stop passing `explicit_self` around --- .../src/deriving/generic/mod.rs | 42 ++++++------------- 1 file changed, 13 insertions(+), 29 deletions(-) diff --git a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs index 8aa2180cf235b..bcf01bf33a94e 100644 --- a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs +++ b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs @@ -839,7 +839,7 @@ impl<'a> TraitDef<'a> { let field_tys = struct_def.fields().iter().map(|field| &*field.ty); let methods = self.methods.iter().filter_map(|method_def| { - let ArgDetails { explicit_self, selflike_args, nonselflike_args, nonself_arg_tys } = + let ArgDetails { selflike_args, nonselflike_args, nonself_arg_tys } = method_def.extract_arg_details(cx, self, type_ident, generics); let body = if from_scratch || method_def.is_static() { @@ -862,15 +862,7 @@ impl<'a> TraitDef<'a> { ) }; - method_def.create_method( - cx, - self, - type_ident, - generics, - explicit_self, - nonself_arg_tys, - body, - ) + method_def.create_method(cx, self, type_ident, generics, nonself_arg_tys, body) }); self.create_derived_impl(cx, type_ident, generics, field_tys, methods, is_packed) @@ -891,7 +883,7 @@ impl<'a> TraitDef<'a> { .map(|field| &*field.ty); let methods = self.methods.iter().filter_map(|method_def| { - let ArgDetails { explicit_self, selflike_args, nonselflike_args, nonself_arg_tys } = + let ArgDetails { selflike_args, nonselflike_args, nonself_arg_tys } = method_def.extract_arg_details(cx, self, type_ident, generics); let body = if from_scratch || method_def.is_static() { @@ -913,15 +905,7 @@ impl<'a> TraitDef<'a> { ) }; - method_def.create_method( - cx, - self, - type_ident, - generics, - explicit_self, - nonself_arg_tys, - body, - ) + method_def.create_method(cx, self, type_ident, generics, nonself_arg_tys, body) }); let is_packed = false; // enums are never packed @@ -930,8 +914,6 @@ impl<'a> TraitDef<'a> { } struct ArgDetails { - /// The `&self` arg, if present. - explicit_self: Option, /// Expressions for `&self` (if present) and also any other /// args with the same type (e.g. the `other` arg in `PartialEq::eq`). selflike_args: ThinVec>, @@ -972,11 +954,10 @@ impl<'a> MethodDef<'a> { let mut nonself_arg_tys = Vec::new(); let span = trait_.span; - let explicit_self = self.explicit_self.then(|| { + if self.explicit_self { // This constructs a fresh `self` path. selflike_args.push(cx.expr_self(span)); - respan(span, SelfKind::Region(None, ast::Mutability::Not)) - }); + } for (ty, name) in self.nonself_args.iter() { let ast_ty = ty.to_ty(cx, span, type_ident, generics); @@ -993,7 +974,7 @@ impl<'a> MethodDef<'a> { } } - ArgDetails { explicit_self, selflike_args, nonselflike_args, nonself_arg_tys } + ArgDetails { selflike_args, nonselflike_args, nonself_arg_tys } } fn create_method( @@ -1002,7 +983,6 @@ impl<'a> MethodDef<'a> { trait_: &TraitDef<'_>, type_ident: Ident, generics: &Generics, - explicit_self: Option, nonself_arg_tys: Vec<(Ident, Box)>, body: BlockOrExpr, ) -> Option> { @@ -1015,9 +995,13 @@ impl<'a> MethodDef<'a> { let fn_generics = self.generics.clone(); let args = { - let self_arg = explicit_self.map(|explicit_self| { + let self_arg = self.explicit_self.then(|| { let ident = Ident::new(kw::SelfLower, span); - ast::Param::from_self(ast::AttrVec::default(), explicit_self, ident) + ast::Param::from_self( + ast::AttrVec::default(), + respan(span, SelfKind::Region(None, ast::Mutability::Not)), + ident, + ) }); let nonself_args = nonself_arg_tys.into_iter().map(|(name, ty)| cx.param(span, name, ty)); From 3b433cb0c237ae0077c0069db7802d144f7eee36 Mon Sep 17 00:00:00 2001 From: cyrgani Date: Sat, 19 Sep 2026 13:27:41 +0000 Subject: [PATCH 6/9] stop passing `nonself_arg_tys` around --- .../src/deriving/generic/mod.rs | 60 ++++++++----------- 1 file changed, 25 insertions(+), 35 deletions(-) diff --git a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs index bcf01bf33a94e..baab6552052ed 100644 --- a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs +++ b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs @@ -839,8 +839,8 @@ impl<'a> TraitDef<'a> { let field_tys = struct_def.fields().iter().map(|field| &*field.ty); let methods = self.methods.iter().filter_map(|method_def| { - let ArgDetails { selflike_args, nonselflike_args, nonself_arg_tys } = - method_def.extract_arg_details(cx, self, type_ident, generics); + let ArgDetails { selflike_args, nonselflike_args } = + method_def.extract_arg_details(cx, self); let body = if from_scratch || method_def.is_static() { method_def.call_substructure_method( @@ -862,7 +862,7 @@ impl<'a> TraitDef<'a> { ) }; - method_def.create_method(cx, self, type_ident, generics, nonself_arg_tys, body) + method_def.create_method(cx, self, type_ident, generics, body) }); self.create_derived_impl(cx, type_ident, generics, field_tys, methods, is_packed) @@ -883,8 +883,8 @@ impl<'a> TraitDef<'a> { .map(|field| &*field.ty); let methods = self.methods.iter().filter_map(|method_def| { - let ArgDetails { selflike_args, nonselflike_args, nonself_arg_tys } = - method_def.extract_arg_details(cx, self, type_ident, generics); + let ArgDetails { selflike_args, nonselflike_args } = + method_def.extract_arg_details(cx, self); let body = if from_scratch || method_def.is_static() { method_def.call_substructure_method( @@ -905,7 +905,7 @@ impl<'a> TraitDef<'a> { ) }; - method_def.create_method(cx, self, type_ident, generics, nonself_arg_tys, body) + method_def.create_method(cx, self, type_ident, generics, body) }); let is_packed = false; // enums are never packed @@ -919,8 +919,6 @@ struct ArgDetails { selflike_args: ThinVec>, /// Expressions for all the remaining args. nonselflike_args: Vec>, - /// Additional information about all the args other than `&self`. - nonself_arg_tys: Vec<(Ident, Box)>, } impl<'a> MethodDef<'a> { @@ -942,16 +940,9 @@ impl<'a> MethodDef<'a> { !self.explicit_self } - fn extract_arg_details( - &self, - cx: &ExtCtxt<'_>, - trait_: &TraitDef<'_>, - type_ident: Ident, - generics: &Generics, - ) -> ArgDetails { + fn extract_arg_details(&self, cx: &ExtCtxt<'_>, trait_: &TraitDef<'_>) -> ArgDetails { let mut selflike_args = ThinVec::new(); let mut nonselflike_args = Vec::new(); - let mut nonself_arg_tys = Vec::new(); let span = trait_.span; if self.explicit_self { @@ -960,21 +951,18 @@ impl<'a> MethodDef<'a> { } for (ty, name) in self.nonself_args.iter() { - let ast_ty = ty.to_ty(cx, span, type_ident, generics); let ident = Ident::new(*name, span); - nonself_arg_tys.push((ident, ast_ty)); - let arg_expr = cx.expr_ident(span, ident); match ty { // Selflike (`&Self`) arguments only occur in non-static methods. - Ref(Self_, _) if !self.is_static() => selflike_args.push(arg_expr), + Ref(Self_, _) if self.explicit_self => selflike_args.push(arg_expr), Self_ => cx.dcx().span_bug(span, "`Self` in non-return position"), _ => nonselflike_args.push(arg_expr), } } - ArgDetails { selflike_args, nonselflike_args, nonself_arg_tys } + ArgDetails { selflike_args, nonselflike_args } } fn create_method( @@ -983,7 +971,6 @@ impl<'a> MethodDef<'a> { trait_: &TraitDef<'_>, type_ident: Ident, generics: &Generics, - nonself_arg_tys: Vec<(Ident, Box)>, body: BlockOrExpr, ) -> Option> { // `assert_fields_are_eq` has an empty default implementation @@ -994,19 +981,22 @@ impl<'a> MethodDef<'a> { // Create the generics that aren't for `Self`. let fn_generics = self.generics.clone(); - let args = { - let self_arg = self.explicit_self.then(|| { - let ident = Ident::new(kw::SelfLower, span); - ast::Param::from_self( - ast::AttrVec::default(), - respan(span, SelfKind::Region(None, ast::Mutability::Not)), - ident, - ) - }); - let nonself_args = - nonself_arg_tys.into_iter().map(|(name, ty)| cx.param(span, name, ty)); - self_arg.into_iter().chain(nonself_args).collect() - }; + let self_arg = self.explicit_self.then(|| { + let ident = Ident::new(kw::SelfLower, span); + ast::Param::from_self( + ast::AttrVec::default(), + respan(span, SelfKind::Region(None, ast::Mutability::Not)), + ident, + ) + }); + let args = self_arg + .into_iter() + .chain(self.nonself_args.iter().map(|(ty, name)| { + let ast_ty = ty.to_ty(cx, span, type_ident, generics); + let ident = Ident::new(*name, span); + cx.param(span, ident, ast_ty) + })) + .collect(); let ret_type = if let Ty::Unit = &self.ret_ty { ast::FnRetTy::Default(span) From d7a86e471780fc4701aea878326b1d9e21730427 Mon Sep 17 00:00:00 2001 From: cyrgani Date: Sat, 19 Sep 2026 12:46:01 +0000 Subject: [PATCH 7/9] optimize `Path::to_path` --- .../rustc_builtin_macros/src/deriving/generic/ty.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_builtin_macros/src/deriving/generic/ty.rs b/compiler/rustc_builtin_macros/src/deriving/generic/ty.rs index 98ad5b8faf52b..48b9e7f8705c9 100644 --- a/compiler/rustc_builtin_macros/src/deriving/generic/ty.rs +++ b/compiler/rustc_builtin_macros/src/deriving/generic/ty.rs @@ -1,6 +1,8 @@ //! A mini version of ast::Ty, which is easier to use, and features an explicit `Self` type to use //! when specifying impls to be derived. +use std::iter::once; + pub(crate) use Ty::*; use rustc_ast::{self as ast, GenericArg, GenericParamKind, Generics, TyKind}; use rustc_expand::base::ExtCtxt; @@ -40,14 +42,16 @@ impl Path { self_ty: Ident, self_generics: &Generics, ) -> ast::Path { - let mut idents = self.path.iter().map(|s| Ident::new(*s, span)).collect::>(); + let idents = self.path.iter().map(|s| Ident::new(*s, span)); let tys = self.params.iter().map(|t| t.to_ty(cx, span, self_ty, self_generics)); let params = tys.map(GenericArg::Type).collect(); - if let PathKind::Std = self.kind { + let idents = if let PathKind::Std = self.kind { let def_site = cx.with_def_site_ctxt(DUMMY_SP); - idents.insert(0, Ident::new(kw::DollarCrate, def_site)); - } + once(Ident::new(kw::DollarCrate, def_site)).chain(idents).collect() + } else { + idents.collect() + }; cx.path_all(span, false, idents, params) } } From c50e0f00e6be21412cafa546abbe926394aeb0e3 Mon Sep 17 00:00:00 2001 From: cyrgani Date: Thu, 17 Sep 2026 20:16:07 +0000 Subject: [PATCH 8/9] just use `Self` instead of writing the type out --- .../src/deriving/generic/ty.rs | 22 +- tests/ui/derives/deriving-all-codegen.stdout | 204 +++++++++--------- ...ith-same-name-and-derive-default-133965.rs | 2 - ...same-name-and-derive-default-133965.stderr | 51 ++--- ...ultiple-types-with-same-name-and-derive.rs | 2 - ...ple-types-with-same-name-and-derive.stderr | 30 +-- tests/ui/stats/macro-stats.stderr | 10 +- tests/ui/traits/issue-106072.rs | 2 +- tests/ui/traits/issue-106072.stderr | 8 +- 9 files changed, 128 insertions(+), 203 deletions(-) diff --git a/compiler/rustc_builtin_macros/src/deriving/generic/ty.rs b/compiler/rustc_builtin_macros/src/deriving/generic/ty.rs index 48b9e7f8705c9..108166788d8b6 100644 --- a/compiler/rustc_builtin_macros/src/deriving/generic/ty.rs +++ b/compiler/rustc_builtin_macros/src/deriving/generic/ty.rs @@ -4,7 +4,7 @@ use std::iter::once; pub(crate) use Ty::*; -use rustc_ast::{self as ast, GenericArg, GenericParamKind, Generics, TyKind}; +use rustc_ast::{self as ast, GenericArg, Generics, TyKind}; use rustc_expand::base::ExtCtxt; use rustc_span::{DUMMY_SP, Ident, Span, Symbol, kw}; use thin_vec::ThinVec; @@ -106,25 +106,7 @@ impl Ty { generics: &Generics, ) -> ast::Path { match self { - Self_ => { - let params: Vec<_> = generics - .params - .iter() - .map(|param| match param.kind { - GenericParamKind::Lifetime => { - GenericArg::Lifetime(ast::Lifetime { id: param.id, ident: param.ident }) - } - GenericParamKind::Type { .. } => { - GenericArg::Type(cx.ty_ident(span, param.ident)) - } - GenericParamKind::Const { .. } => { - GenericArg::Const(cx.const_ident(span, param.ident)) - } - }) - .collect(); - - cx.path_all(span, false, vec![self_ty], params) - } + Self_ => cx.path_ident(span, Ident::new(kw::SelfUpper, span)), Path(p) => p.to_path(cx, span, self_ty, generics), AstTy(ty) => match &ty.kind { TyKind::Path(_, path) => path.clone(), diff --git a/tests/ui/derives/deriving-all-codegen.stdout b/tests/ui/derives/deriving-all-codegen.stdout index bf88d1c0cb7aa..be6bd1a914c65 100644 --- a/tests/ui/derives/deriving-all-codegen.stdout +++ b/tests/ui/derives/deriving-all-codegen.stdout @@ -32,7 +32,7 @@ unsafe impl ::core::clone::TrivialClone for Empty { } #[automatically_derived] impl ::core::clone::Clone for Empty { #[inline] - fn clone(&self) -> Empty { *self } + fn clone(&self) -> Self { *self } } #[automatically_derived] impl ::core::marker::Copy for Empty { } @@ -46,7 +46,7 @@ impl ::core::fmt::Debug for Empty { #[automatically_derived] impl ::core::default::Default for Empty { #[inline] - fn default() -> Empty { Empty } + fn default() -> Self { Empty } } #[automatically_derived] impl ::core::hash::Hash for Empty { @@ -58,14 +58,14 @@ impl ::core::marker::StructuralPartialEq for Empty { } #[automatically_derived] impl ::core::cmp::PartialEq for Empty { #[inline] - fn eq(&self, other: &Empty) -> bool { true } + fn eq(&self, other: &Self) -> bool { true } } #[automatically_derived] impl ::core::cmp::Eq for Empty { } #[automatically_derived] impl ::core::cmp::PartialOrd for Empty { #[inline] - fn partial_cmp(&self, other: &Empty) + fn partial_cmp(&self, other: &Self) -> ::core::option::Option<::core::cmp::Ordering> { ::core::option::Option::Some(::core::cmp::Ordering::Equal) } @@ -73,7 +73,7 @@ impl ::core::cmp::PartialOrd for Empty { #[automatically_derived] impl ::core::cmp::Ord for Empty { #[inline] - fn cmp(&self, other: &Empty) -> ::core::cmp::Ordering { + fn cmp(&self, other: &Self) -> ::core::cmp::Ordering { ::core::cmp::Ordering::Equal } } @@ -90,7 +90,7 @@ unsafe impl ::core::clone::TrivialClone for Point { } #[automatically_derived] impl ::core::clone::Clone for Point { #[inline] - fn clone(&self) -> Point { + fn clone(&self) -> Self { let _: ::core::clone::AssertParamIsClone; *self } @@ -108,7 +108,7 @@ impl ::core::fmt::Debug for Point { #[automatically_derived] impl ::core::default::Default for Point { #[inline] - fn default() -> Point { + fn default() -> Self { Point { x: ::core::default::Default::default(), y: ::core::default::Default::default(), @@ -128,7 +128,7 @@ impl ::core::marker::StructuralPartialEq for Point { } #[automatically_derived] impl ::core::cmp::PartialEq for Point { #[inline] - fn eq(&self, other: &Point) -> bool { + fn eq(&self, other: &Self) -> bool { self.x == other.x && self.y == other.y } } @@ -144,7 +144,7 @@ impl ::core::cmp::Eq for Point { #[automatically_derived] impl ::core::cmp::PartialOrd for Point { #[inline] - fn partial_cmp(&self, other: &Point) + fn partial_cmp(&self, other: &Self) -> ::core::option::Option<::core::cmp::Ordering> { ::core::option::Option::Some(::core::cmp::Ord::cmp(self, other)) } @@ -152,7 +152,7 @@ impl ::core::cmp::PartialOrd for Point { #[automatically_derived] impl ::core::cmp::Ord for Point { #[inline] - fn cmp(&self, other: &Point) -> ::core::cmp::Ordering { + fn cmp(&self, other: &Self) -> ::core::cmp::Ordering { match ::core::cmp::Ord::cmp(&self.x, &other.x) { ::core::cmp::Ordering::Equal => ::core::cmp::Ord::cmp(&self.y, &other.y), @@ -174,7 +174,7 @@ unsafe impl ::core::clone::TrivialClone for PackedPoint { } #[automatically_derived] impl ::core::clone::Clone for PackedPoint { #[inline] - fn clone(&self) -> PackedPoint { + fn clone(&self) -> Self { let _: ::core::clone::AssertParamIsClone; *self } @@ -192,7 +192,7 @@ impl ::core::fmt::Debug for PackedPoint { #[automatically_derived] impl ::core::default::Default for PackedPoint { #[inline] - fn default() -> PackedPoint { + fn default() -> Self { PackedPoint { x: ::core::default::Default::default(), y: ::core::default::Default::default(), @@ -212,7 +212,7 @@ impl ::core::marker::StructuralPartialEq for PackedPoint { } #[automatically_derived] impl ::core::cmp::PartialEq for PackedPoint { #[inline] - fn eq(&self, other: &PackedPoint) -> bool { + fn eq(&self, other: &Self) -> bool { ({ self.x }) == ({ other.x }) && ({ self.y }) == ({ other.y }) } } @@ -228,7 +228,7 @@ impl ::core::cmp::Eq for PackedPoint { #[automatically_derived] impl ::core::cmp::PartialOrd for PackedPoint { #[inline] - fn partial_cmp(&self, other: &PackedPoint) + fn partial_cmp(&self, other: &Self) -> ::core::option::Option<::core::cmp::Ordering> { ::core::option::Option::Some(::core::cmp::Ord::cmp(self, other)) } @@ -236,7 +236,7 @@ impl ::core::cmp::PartialOrd for PackedPoint { #[automatically_derived] impl ::core::cmp::Ord for PackedPoint { #[inline] - fn cmp(&self, other: &PackedPoint) -> ::core::cmp::Ordering { + fn cmp(&self, other: &Self) -> ::core::cmp::Ordering { match ::core::cmp::Ord::cmp(&{ self.x }, &{ other.x }) { ::core::cmp::Ordering::Equal => ::core::cmp::Ord::cmp(&{ self.y }, &{ other.y }), @@ -252,7 +252,7 @@ unsafe impl ::core::clone::TrivialClone for TupleSingleField { } #[automatically_derived] impl ::core::clone::Clone for TupleSingleField { #[inline] - fn clone(&self) -> TupleSingleField { + fn clone(&self) -> Self { let _: ::core::clone::AssertParamIsClone; *self } @@ -270,14 +270,14 @@ impl ::core::fmt::Debug for TupleSingleField { #[automatically_derived] impl ::core::default::Default for TupleSingleField { #[inline] - fn default() -> TupleSingleField { + fn default() -> Self { TupleSingleField(::core::default::Default::default()) } } #[automatically_derived] impl ::core::convert::From for TupleSingleField { #[inline] - fn from(value: u32) -> TupleSingleField { Self(value) } + fn from(value: u32) -> Self { Self(value) } } #[automatically_derived] impl ::core::hash::Hash for TupleSingleField { @@ -291,7 +291,7 @@ impl ::core::marker::StructuralPartialEq for TupleSingleField { } #[automatically_derived] impl ::core::cmp::PartialEq for TupleSingleField { #[inline] - fn eq(&self, other: &TupleSingleField) -> bool { self.0 == other.0 } + fn eq(&self, other: &Self) -> bool { self.0 == other.0 } } #[automatically_derived] impl ::core::cmp::Eq for TupleSingleField { @@ -305,7 +305,7 @@ impl ::core::cmp::Eq for TupleSingleField { #[automatically_derived] impl ::core::cmp::PartialOrd for TupleSingleField { #[inline] - fn partial_cmp(&self, other: &TupleSingleField) + fn partial_cmp(&self, other: &Self) -> ::core::option::Option<::core::cmp::Ordering> { ::core::option::Option::Some(::core::cmp::Ord::cmp(self, other)) } @@ -313,7 +313,7 @@ impl ::core::cmp::PartialOrd for TupleSingleField { #[automatically_derived] impl ::core::cmp::Ord for TupleSingleField { #[inline] - fn cmp(&self, other: &TupleSingleField) -> ::core::cmp::Ordering { + fn cmp(&self, other: &Self) -> ::core::cmp::Ordering { ::core::cmp::Ord::cmp(&self.0, &other.0) } } @@ -327,7 +327,7 @@ unsafe impl ::core::clone::TrivialClone for SingleField { } #[automatically_derived] impl ::core::clone::Clone for SingleField { #[inline] - fn clone(&self) -> SingleField { + fn clone(&self) -> Self { let _: ::core::clone::AssertParamIsClone; *self } @@ -345,14 +345,14 @@ impl ::core::fmt::Debug for SingleField { #[automatically_derived] impl ::core::default::Default for SingleField { #[inline] - fn default() -> SingleField { + fn default() -> Self { SingleField { foo: ::core::default::Default::default() } } } #[automatically_derived] impl ::core::convert::From for SingleField { #[inline] - fn from(value: bool) -> SingleField { Self { foo: value } } + fn from(value: bool) -> Self { Self { foo: value } } } #[automatically_derived] impl ::core::hash::Hash for SingleField { @@ -366,7 +366,7 @@ impl ::core::marker::StructuralPartialEq for SingleField { } #[automatically_derived] impl ::core::cmp::PartialEq for SingleField { #[inline] - fn eq(&self, other: &SingleField) -> bool { self.foo == other.foo } + fn eq(&self, other: &Self) -> bool { self.foo == other.foo } } #[automatically_derived] impl ::core::cmp::Eq for SingleField { @@ -380,7 +380,7 @@ impl ::core::cmp::Eq for SingleField { #[automatically_derived] impl ::core::cmp::PartialOrd for SingleField { #[inline] - fn partial_cmp(&self, other: &SingleField) + fn partial_cmp(&self, other: &Self) -> ::core::option::Option<::core::cmp::Ordering> { ::core::option::Option::Some(::core::cmp::Ord::cmp(self, other)) } @@ -388,7 +388,7 @@ impl ::core::cmp::PartialOrd for SingleField { #[automatically_derived] impl ::core::cmp::Ord for SingleField { #[inline] - fn cmp(&self, other: &SingleField) -> ::core::cmp::Ordering { + fn cmp(&self, other: &Self) -> ::core::cmp::Ordering { ::core::cmp::Ord::cmp(&self.foo, &other.foo) } } @@ -411,7 +411,7 @@ unsafe impl ::core::clone::TrivialClone for Big { } #[automatically_derived] impl ::core::clone::Clone for Big { #[inline] - fn clone(&self) -> Big { + fn clone(&self) -> Self { let _: ::core::clone::AssertParamIsClone; *self } @@ -434,7 +434,7 @@ impl ::core::fmt::Debug for Big { #[automatically_derived] impl ::core::default::Default for Big { #[inline] - fn default() -> Big { + fn default() -> Self { Big { b1: ::core::default::Default::default(), b2: ::core::default::Default::default(), @@ -466,7 +466,7 @@ impl ::core::marker::StructuralPartialEq for Big { } #[automatically_derived] impl ::core::cmp::PartialEq for Big { #[inline] - fn eq(&self, other: &Big) -> bool { + fn eq(&self, other: &Self) -> bool { self.b1 == other.b1 && self.b2 == other.b2 && self.b3 == other.b3 && self.b4 == other.b4 && self.b5 == other.b5 && self.b6 == other.b6 && self.b7 == other.b7 && @@ -485,7 +485,7 @@ impl ::core::cmp::Eq for Big { #[automatically_derived] impl ::core::cmp::PartialOrd for Big { #[inline] - fn partial_cmp(&self, other: &Big) + fn partial_cmp(&self, other: &Self) -> ::core::option::Option<::core::cmp::Ordering> { ::core::option::Option::Some(::core::cmp::Ord::cmp(self, other)) } @@ -493,7 +493,7 @@ impl ::core::cmp::PartialOrd for Big { #[automatically_derived] impl ::core::cmp::Ord for Big { #[inline] - fn cmp(&self, other: &Big) -> ::core::cmp::Ordering { + fn cmp(&self, other: &Self) -> ::core::cmp::Ordering { match ::core::cmp::Ord::cmp(&self.b1, &other.b1) { ::core::cmp::Ordering::Equal => match ::core::cmp::Ord::cmp(&self.b2, &other.b2) { @@ -545,7 +545,7 @@ impl ::core::marker::StructuralPartialEq for Reorder { } #[automatically_derived] impl ::core::cmp::PartialEq for Reorder { #[inline] - fn eq(&self, other: &Reorder) -> bool { + fn eq(&self, other: &Self) -> bool { self.b2 == other.b2 && self.b4 == other.b4 && self.b5 == other.b5 && self.b6 == other.b6 && self.b7 == other.b7 && self.b8 == other.b8 && self.b10 == other.b10 && @@ -556,7 +556,7 @@ impl ::core::cmp::PartialEq for Reorder { #[automatically_derived] impl ::core::cmp::PartialOrd for Reorder { #[inline] - fn partial_cmp(&self, other: &Reorder) + fn partial_cmp(&self, other: &Self) -> ::core::option::Option<::core::cmp::Ordering> { match ::core::cmp::PartialOrd::partial_cmp(&self.b1, &other.b1) { ::core::option::Option::Some(::core::cmp::Ordering::Equal) => @@ -626,9 +626,7 @@ struct NonCopy(u32); #[automatically_derived] impl ::core::clone::Clone for NonCopy { #[inline] - fn clone(&self) -> NonCopy { - NonCopy(::core::clone::Clone::clone(&self.0)) - } + fn clone(&self) -> Self { NonCopy(::core::clone::Clone::clone(&self.0)) } } // A packed struct that doesn't impl `Copy`, which means it gets the non-trivial @@ -638,7 +636,7 @@ struct PackedNonCopy(u32); #[automatically_derived] impl ::core::clone::Clone for PackedNonCopy { #[inline] - fn clone(&self) -> PackedNonCopy { + fn clone(&self) -> Self { PackedNonCopy(::core::clone::Clone::clone(&{ self.0 })) } } @@ -649,7 +647,7 @@ struct ManualCopy(u32); #[automatically_derived] impl ::core::clone::Clone for ManualCopy { #[inline] - fn clone(&self) -> ManualCopy { + fn clone(&self) -> Self { ManualCopy(::core::clone::Clone::clone(&self.0)) } } @@ -662,7 +660,7 @@ struct PackedManualCopy(u32); #[automatically_derived] impl ::core::clone::Clone for PackedManualCopy { #[inline] - fn clone(&self) -> PackedManualCopy { + fn clone(&self) -> Self { PackedManualCopy(::core::clone::Clone::clone(&{ self.0 })) } } @@ -681,7 +679,7 @@ impl ::core::fmt::Debug for Unsized { #[automatically_derived] impl ::core::convert::From<[u32]> for Unsized { #[inline] - fn from(value: [u32]) -> Unsized { Self(value) } + fn from(value: [u32]) -> Self { Self(value) } } #[automatically_derived] impl ::core::hash::Hash for Unsized { @@ -695,7 +693,7 @@ impl ::core::marker::StructuralPartialEq for Unsized { } #[automatically_derived] impl ::core::cmp::PartialEq for Unsized { #[inline] - fn eq(&self, other: &Unsized) -> bool { self.0 == other.0 } + fn eq(&self, other: &Self) -> bool { self.0 == other.0 } } #[automatically_derived] impl ::core::cmp::Eq for Unsized { @@ -709,7 +707,7 @@ impl ::core::cmp::Eq for Unsized { #[automatically_derived] impl ::core::cmp::PartialOrd for Unsized { #[inline] - fn partial_cmp(&self, other: &Unsized) + fn partial_cmp(&self, other: &Self) -> ::core::option::Option<::core::cmp::Ordering> { ::core::option::Option::Some(::core::cmp::Ord::cmp(self, other)) } @@ -717,7 +715,7 @@ impl ::core::cmp::PartialOrd for Unsized { #[automatically_derived] impl ::core::cmp::Ord for Unsized { #[inline] - fn cmp(&self, other: &Unsized) -> ::core::cmp::Ordering { + fn cmp(&self, other: &Self) -> ::core::cmp::Ordering { ::core::cmp::Ord::cmp(&self.0, &other.0) } } @@ -736,7 +734,7 @@ struct Generic { impl ::core::clone::Clone for Generic where T::A: ::core::clone::Clone { #[inline] - fn clone(&self) -> Generic { + fn clone(&self) -> Self { Generic { t: ::core::clone::Clone::clone(&self.t), ta: ::core::clone::Clone::clone(&self.ta), @@ -762,7 +760,7 @@ impl ::core::default::Default for Generic where T::A: ::core::default::Default { #[inline] - fn default() -> Generic { + fn default() -> Self { Generic { t: ::core::default::Default::default(), ta: ::core::default::Default::default(), @@ -790,7 +788,7 @@ impl ::core::cmp::PartialEq for Generic where T::A: ::core::cmp::PartialEq { #[inline] - fn eq(&self, other: &Generic) -> bool { + fn eq(&self, other: &Self) -> bool { self.t == other.t && self.ta == other.ta && self.u == other.u } } @@ -811,7 +809,7 @@ impl ::core::cmp::PartialOrd for Generic where T::A: ::core::cmp::PartialOrd { #[inline] - fn partial_cmp(&self, other: &Generic) + fn partial_cmp(&self, other: &Self) -> ::core::option::Option<::core::cmp::Ordering> { match ::core::cmp::PartialOrd::partial_cmp(&self.t, &other.t) { ::core::option::Option::Some(::core::cmp::Ordering::Equal) => @@ -829,7 +827,7 @@ impl impl ::core::cmp::Ord for Generic where T::A: ::core::cmp::Ord { #[inline] - fn cmp(&self, other: &Generic) -> ::core::cmp::Ordering { + fn cmp(&self, other: &Self) -> ::core::cmp::Ordering { match ::core::cmp::Ord::cmp(&self.t, &other.t) { ::core::cmp::Ordering::Equal => match ::core::cmp::Ord::cmp(&self.ta, &other.ta) { @@ -855,7 +853,7 @@ impl where T::A: ::core::clone::Clone + ::core::marker::Copy { #[inline] - fn clone(&self) -> PackedGeneric { + fn clone(&self) -> Self { PackedGeneric(::core::clone::Clone::clone(&{ self.0 }), ::core::clone::Clone::clone(&{ self.1 }), ::core::clone::Clone::clone(&{ self.2 })) @@ -882,7 +880,7 @@ impl ::core::default::Default for PackedGeneric where T::A: ::core::default::Default { #[inline] - fn default() -> PackedGeneric { + fn default() -> Self { PackedGeneric(::core::default::Default::default(), ::core::default::Default::default(), ::core::default::Default::default()) @@ -911,7 +909,7 @@ impl where T::A: ::core::cmp::PartialEq + ::core::marker::Copy { #[inline] - fn eq(&self, other: &PackedGeneric) -> bool { + fn eq(&self, other: &Self) -> bool { ({ self.0 }) == ({ other.0 }) && ({ self.1 }) == ({ other.1 }) && ({ self.2 }) == ({ other.2 }) } @@ -935,7 +933,7 @@ impl where T::A: ::core::cmp::PartialOrd + ::core::marker::Copy { #[inline] - fn partial_cmp(&self, other: &PackedGeneric) + fn partial_cmp(&self, other: &Self) -> ::core::option::Option<::core::cmp::Ordering> { match ::core::cmp::PartialOrd::partial_cmp(&{ self.0 }, &{ other.0 }) { @@ -957,7 +955,7 @@ impl ::core::cmp::Ord for PackedGeneric where T::A: ::core::cmp::Ord + ::core::marker::Copy { #[inline] - fn cmp(&self, other: &PackedGeneric) -> ::core::cmp::Ordering { + fn cmp(&self, other: &Self) -> ::core::cmp::Ordering { match ::core::cmp::Ord::cmp(&{ self.0 }, &{ other.0 }) { ::core::cmp::Ordering::Equal => match ::core::cmp::Ord::cmp(&{ self.1 }, &{ other.1 }) { @@ -978,7 +976,7 @@ unsafe impl ::core::clone::TrivialClone for Enum0 { } #[automatically_derived] impl ::core::clone::Clone for Enum0 { #[inline] - fn clone(&self) -> Enum0 { *self } + fn clone(&self) -> Self { *self } } #[automatically_derived] impl ::core::marker::Copy for Enum0 { } @@ -1001,14 +999,14 @@ impl ::core::marker::StructuralPartialEq for Enum0 { } #[automatically_derived] impl ::core::cmp::PartialEq for Enum0 { #[inline] - fn eq(&self, other: &Enum0) -> bool { match *self {} } + fn eq(&self, other: &Self) -> bool { match *self {} } } #[automatically_derived] impl ::core::cmp::Eq for Enum0 { } #[automatically_derived] impl ::core::cmp::PartialOrd for Enum0 { #[inline] - fn partial_cmp(&self, other: &Enum0) + fn partial_cmp(&self, other: &Self) -> ::core::option::Option<::core::cmp::Ordering> { match *self {} } @@ -1016,7 +1014,7 @@ impl ::core::cmp::PartialOrd for Enum0 { #[automatically_derived] impl ::core::cmp::Ord for Enum0 { #[inline] - fn cmp(&self, other: &Enum0) -> ::core::cmp::Ordering { match *self {} } + fn cmp(&self, other: &Self) -> ::core::cmp::Ordering { match *self {} } } // A single-variant enum. @@ -1028,7 +1026,7 @@ enum Enum1 { #[automatically_derived] impl ::core::clone::Clone for Enum1 { #[inline] - fn clone(&self) -> Enum1 { + fn clone(&self) -> Self { match self { Enum1::Single { x: __self_0 } => Enum1::Single { x: ::core::clone::Clone::clone(__self_0) }, @@ -1061,7 +1059,7 @@ impl ::core::marker::StructuralPartialEq for Enum1 { } #[automatically_derived] impl ::core::cmp::PartialEq for Enum1 { #[inline] - fn eq(&self, other: &Enum1) -> bool { + fn eq(&self, other: &Self) -> bool { match (self, other) { (Enum1::Single { x: __self_0 }, Enum1::Single { x: __arg1_0 }) => __self_0 == __arg1_0, @@ -1080,7 +1078,7 @@ impl ::core::cmp::Eq for Enum1 { #[automatically_derived] impl ::core::cmp::PartialOrd for Enum1 { #[inline] - fn partial_cmp(&self, other: &Enum1) + fn partial_cmp(&self, other: &Self) -> ::core::option::Option<::core::cmp::Ordering> { ::core::option::Option::Some(::core::cmp::Ord::cmp(self, other)) } @@ -1088,7 +1086,7 @@ impl ::core::cmp::PartialOrd for Enum1 { #[automatically_derived] impl ::core::cmp::Ord for Enum1 { #[inline] - fn cmp(&self, other: &Enum1) -> ::core::cmp::Ordering { + fn cmp(&self, other: &Self) -> ::core::cmp::Ordering { match (self, other) { (Enum1::Single { x: __self_0 }, Enum1::Single { x: __arg1_0 }) => ::core::cmp::Ord::cmp(__self_0, __arg1_0), @@ -1105,7 +1103,7 @@ enum Fieldless1 { #[automatically_derived] impl ::core::clone::Clone for Fieldless1 { #[inline] - fn clone(&self) -> Fieldless1 { Fieldless1::A } + fn clone(&self) -> Self { Fieldless1::A } } #[automatically_derived] impl ::core::fmt::Debug for Fieldless1 { @@ -1117,7 +1115,7 @@ impl ::core::fmt::Debug for Fieldless1 { #[automatically_derived] impl ::core::default::Default for Fieldless1 { #[inline] - fn default() -> Fieldless1 { Self::A } + fn default() -> Self { Self::A } } #[automatically_derived] impl ::core::hash::Hash for Fieldless1 { @@ -1129,14 +1127,14 @@ impl ::core::marker::StructuralPartialEq for Fieldless1 { } #[automatically_derived] impl ::core::cmp::PartialEq for Fieldless1 { #[inline] - fn eq(&self, other: &Fieldless1) -> bool { true } + fn eq(&self, other: &Self) -> bool { true } } #[automatically_derived] impl ::core::cmp::Eq for Fieldless1 { } #[automatically_derived] impl ::core::cmp::PartialOrd for Fieldless1 { #[inline] - fn partial_cmp(&self, other: &Fieldless1) + fn partial_cmp(&self, other: &Self) -> ::core::option::Option<::core::cmp::Ordering> { ::core::option::Option::Some(::core::cmp::Ordering::Equal) } @@ -1144,7 +1142,7 @@ impl ::core::cmp::PartialOrd for Fieldless1 { #[automatically_derived] impl ::core::cmp::Ord for Fieldless1 { #[inline] - fn cmp(&self, other: &Fieldless1) -> ::core::cmp::Ordering { + fn cmp(&self, other: &Self) -> ::core::cmp::Ordering { ::core::cmp::Ordering::Equal } } @@ -1163,7 +1161,7 @@ unsafe impl ::core::clone::TrivialClone for Fieldless { } #[automatically_derived] impl ::core::clone::Clone for Fieldless { #[inline] - fn clone(&self) -> Fieldless { *self } + fn clone(&self) -> Self { *self } } #[automatically_derived] impl ::core::marker::Copy for Fieldless { } @@ -1182,7 +1180,7 @@ impl ::core::fmt::Debug for Fieldless { #[automatically_derived] impl ::core::default::Default for Fieldless { #[inline] - fn default() -> Fieldless { Self::A } + fn default() -> Self { Self::A } } #[automatically_derived] impl ::core::hash::Hash for Fieldless { @@ -1197,7 +1195,7 @@ impl ::core::marker::StructuralPartialEq for Fieldless { } #[automatically_derived] impl ::core::cmp::PartialEq for Fieldless { #[inline] - fn eq(&self, other: &Fieldless) -> bool { + fn eq(&self, other: &Self) -> bool { let __self_discr = ::core::intrinsics::discriminant_value(self); let __arg1_discr = ::core::intrinsics::discriminant_value(other); __self_discr == __arg1_discr @@ -1208,7 +1206,7 @@ impl ::core::cmp::Eq for Fieldless { } #[automatically_derived] impl ::core::cmp::PartialOrd for Fieldless { #[inline] - fn partial_cmp(&self, other: &Fieldless) + fn partial_cmp(&self, other: &Self) -> ::core::option::Option<::core::cmp::Ordering> { ::core::option::Option::Some(::core::cmp::Ord::cmp(self, other)) } @@ -1216,7 +1214,7 @@ impl ::core::cmp::PartialOrd for Fieldless { #[automatically_derived] impl ::core::cmp::Ord for Fieldless { #[inline] - fn cmp(&self, other: &Fieldless) -> ::core::cmp::Ordering { + fn cmp(&self, other: &Self) -> ::core::cmp::Ordering { let __self_discr = ::core::intrinsics::discriminant_value(self); let __arg1_discr = ::core::intrinsics::discriminant_value(other); ::core::cmp::Ord::cmp(&__self_discr, &__arg1_discr) @@ -1241,7 +1239,7 @@ unsafe impl ::core::clone::TrivialClone for Mixed { } #[automatically_derived] impl ::core::clone::Clone for Mixed { #[inline] - fn clone(&self) -> Mixed { + fn clone(&self) -> Self { let _: ::core::clone::AssertParamIsClone; let _: ::core::clone::AssertParamIsClone>; let _: ::core::clone::AssertParamIsClone>; @@ -1269,7 +1267,7 @@ impl ::core::fmt::Debug for Mixed { #[automatically_derived] impl ::core::default::Default for Mixed { #[inline] - fn default() -> Mixed { Self::P } + fn default() -> Self { Self::P } } #[automatically_derived] impl ::core::hash::Hash for Mixed { @@ -1292,7 +1290,7 @@ impl ::core::marker::StructuralPartialEq for Mixed { } #[automatically_derived] impl ::core::cmp::PartialEq for Mixed { #[inline] - fn eq(&self, other: &Mixed) -> bool { + fn eq(&self, other: &Self) -> bool { let __self_discr = ::core::intrinsics::discriminant_value(self); let __arg1_discr = ::core::intrinsics::discriminant_value(other); __self_discr == __arg1_discr && @@ -1320,7 +1318,7 @@ impl ::core::cmp::Eq for Mixed { #[automatically_derived] impl ::core::cmp::PartialOrd for Mixed { #[inline] - fn partial_cmp(&self, other: &Mixed) + fn partial_cmp(&self, other: &Self) -> ::core::option::Option<::core::cmp::Ordering> { ::core::option::Option::Some(::core::cmp::Ord::cmp(self, other)) } @@ -1328,7 +1326,7 @@ impl ::core::cmp::PartialOrd for Mixed { #[automatically_derived] impl ::core::cmp::Ord for Mixed { #[inline] - fn cmp(&self, other: &Mixed) -> ::core::cmp::Ordering { + fn cmp(&self, other: &Self) -> ::core::cmp::Ordering { let __self_discr = ::core::intrinsics::discriminant_value(self); let __arg1_discr = ::core::intrinsics::discriminant_value(other); match ::core::cmp::Ord::cmp(&__self_discr, &__arg1_discr) { @@ -1367,7 +1365,7 @@ impl ::core::marker::StructuralPartialEq for ReorderEnum { } #[automatically_derived] impl ::core::cmp::PartialEq for ReorderEnum { #[inline] - fn eq(&self, other: &ReorderEnum) -> bool { + fn eq(&self, other: &Self) -> bool { let __self_discr = ::core::intrinsics::discriminant_value(self); let __arg1_discr = ::core::intrinsics::discriminant_value(other); __self_discr == __arg1_discr && @@ -1387,7 +1385,7 @@ impl ::core::cmp::PartialEq for ReorderEnum { #[automatically_derived] impl ::core::cmp::PartialOrd for ReorderEnum { #[inline] - fn partial_cmp(&self, other: &ReorderEnum) + fn partial_cmp(&self, other: &Self) -> ::core::option::Option<::core::cmp::Ordering> { let __self_discr = ::core::intrinsics::discriminant_value(self); let __arg1_discr = ::core::intrinsics::discriminant_value(other); @@ -1427,7 +1425,7 @@ enum Fielded { X(u32), Y(bool), Z(Option), } #[automatically_derived] impl ::core::clone::Clone for Fielded { #[inline] - fn clone(&self) -> Fielded { + fn clone(&self) -> Self { match self { Fielded::X(__self_0) => Fielded::X(::core::clone::Clone::clone(__self_0)), @@ -1473,7 +1471,7 @@ impl ::core::marker::StructuralPartialEq for Fielded { } #[automatically_derived] impl ::core::cmp::PartialEq for Fielded { #[inline] - fn eq(&self, other: &Fielded) -> bool { + fn eq(&self, other: &Self) -> bool { let __self_discr = ::core::intrinsics::discriminant_value(self); let __arg1_discr = ::core::intrinsics::discriminant_value(other); __self_discr == __arg1_discr && @@ -1502,7 +1500,7 @@ impl ::core::cmp::Eq for Fielded { #[automatically_derived] impl ::core::cmp::PartialOrd for Fielded { #[inline] - fn partial_cmp(&self, other: &Fielded) + fn partial_cmp(&self, other: &Self) -> ::core::option::Option<::core::cmp::Ordering> { ::core::option::Option::Some(::core::cmp::Ord::cmp(self, other)) } @@ -1510,7 +1508,7 @@ impl ::core::cmp::PartialOrd for Fielded { #[automatically_derived] impl ::core::cmp::Ord for Fielded { #[inline] - fn cmp(&self, other: &Fielded) -> ::core::cmp::Ordering { + fn cmp(&self, other: &Self) -> ::core::cmp::Ordering { let __self_discr = ::core::intrinsics::discriminant_value(self); let __arg1_discr = ::core::intrinsics::discriminant_value(other); match ::core::cmp::Ord::cmp(&__self_discr, &__arg1_discr) { @@ -1535,7 +1533,7 @@ enum EnumGeneric { One(T), Two(U), } impl ::core::clone::Clone for EnumGeneric { #[inline] - fn clone(&self) -> EnumGeneric { + fn clone(&self) -> Self { match self { EnumGeneric::One(__self_0) => EnumGeneric::One(::core::clone::Clone::clone(__self_0)), @@ -1586,7 +1584,7 @@ impl impl ::core::cmp::PartialEq for EnumGeneric { #[inline] - fn eq(&self, other: &EnumGeneric) -> bool { + fn eq(&self, other: &Self) -> bool { let __self_discr = ::core::intrinsics::discriminant_value(self); let __arg1_discr = ::core::intrinsics::discriminant_value(other); __self_discr == __arg1_discr && @@ -1614,7 +1612,7 @@ impl ::core::cmp::Eq for impl ::core::cmp::PartialOrd for EnumGeneric { #[inline] - fn partial_cmp(&self, other: &EnumGeneric) + fn partial_cmp(&self, other: &Self) -> ::core::option::Option<::core::cmp::Ordering> { let __self_discr = ::core::intrinsics::discriminant_value(self); let __arg1_discr = ::core::intrinsics::discriminant_value(other); @@ -1633,7 +1631,7 @@ impl impl ::core::cmp::Ord for EnumGeneric { #[inline] - fn cmp(&self, other: &EnumGeneric) -> ::core::cmp::Ordering { + fn cmp(&self, other: &Self) -> ::core::cmp::Ordering { let __self_discr = ::core::intrinsics::discriminant_value(self); let __arg1_discr = ::core::intrinsics::discriminant_value(other); match ::core::cmp::Ord::cmp(&__self_discr, &__arg1_discr) { @@ -1662,7 +1660,7 @@ impl ::core::marker::StructuralPartialEq for NonCopyEnum { } #[automatically_derived] impl ::core::cmp::PartialEq for NonCopyEnum { #[inline] - fn eq(&self, other: &NonCopyEnum) -> bool { + fn eq(&self, other: &Self) -> bool { match (self, other) { (NonCopyEnum::NonCopyField(__self_0), NonCopyEnum::NonCopyField(__arg1_0)) => __self_0 == __arg1_0, @@ -1686,7 +1684,7 @@ unsafe impl ::core::clone::TrivialClone for Union { } #[automatically_derived] impl ::core::clone::Clone for Union { #[inline] - fn clone(&self) -> Union { + fn clone(&self) -> Self { let _: ::core::clone::AssertParamIsCopy; *self } @@ -1703,7 +1701,7 @@ unsafe impl ::core::clone::TrivialClone for FooCopyClone { } #[automatically_derived] impl ::core::clone::Clone for FooCopyClone { #[inline] - fn clone(&self) -> FooCopyClone { + fn clone(&self) -> Self { let _: ::core::clone::AssertParamIsClone; *self } @@ -1716,7 +1714,7 @@ unsafe impl ::core::clone::TrivialClone for FooCloneCopy { } #[automatically_derived] impl ::core::clone::Clone for FooCloneCopy { #[inline] - fn clone(&self) -> FooCloneCopy { + fn clone(&self) -> Self { let _: ::core::clone::AssertParamIsClone; *self } @@ -1731,7 +1729,7 @@ unsafe impl ::core::clone::TrivialClone for FooCopyAndClone { } #[automatically_derived] impl ::core::clone::Clone for FooCopyAndClone { #[inline] - fn clone(&self) -> FooCopyAndClone { + fn clone(&self) -> Self { let _: ::core::clone::AssertParamIsClone; *self } @@ -1748,7 +1746,7 @@ impl ::core::marker::Copy for FooCloneAndCopy { } #[automatically_derived] impl ::core::clone::Clone for FooCloneAndCopy { #[inline] - fn clone(&self) -> FooCloneAndCopy { + fn clone(&self) -> Self { FooCloneAndCopy(::core::clone::Clone::clone(&self.0)) } } @@ -1757,7 +1755,7 @@ struct FooPartialOrdOrd(i32); #[automatically_derived] impl ::core::cmp::PartialOrd for FooPartialOrdOrd { #[inline] - fn partial_cmp(&self, other: &FooPartialOrdOrd) + fn partial_cmp(&self, other: &Self) -> ::core::option::Option<::core::cmp::Ordering> { ::core::option::Option::Some(::core::cmp::Ord::cmp(self, other)) } @@ -1765,7 +1763,7 @@ impl ::core::cmp::PartialOrd for FooPartialOrdOrd { #[automatically_derived] impl ::core::cmp::Ord for FooPartialOrdOrd { #[inline] - fn cmp(&self, other: &FooPartialOrdOrd) -> ::core::cmp::Ordering { + fn cmp(&self, other: &Self) -> ::core::cmp::Ordering { ::core::cmp::Ord::cmp(&self.0, &other.0) } } @@ -1774,14 +1772,14 @@ struct FooOrdPartialOrd(i32); #[automatically_derived] impl ::core::cmp::Ord for FooOrdPartialOrd { #[inline] - fn cmp(&self, other: &FooOrdPartialOrd) -> ::core::cmp::Ordering { + fn cmp(&self, other: &Self) -> ::core::cmp::Ordering { ::core::cmp::Ord::cmp(&self.0, &other.0) } } #[automatically_derived] impl ::core::cmp::PartialOrd for FooOrdPartialOrd { #[inline] - fn partial_cmp(&self, other: &FooOrdPartialOrd) + fn partial_cmp(&self, other: &Self) -> ::core::option::Option<::core::cmp::Ordering> { ::core::option::Option::Some(::core::cmp::Ord::cmp(self, other)) } @@ -1791,7 +1789,7 @@ struct FooOrdBeforePartialOrd(i32); #[automatically_derived] impl ::core::cmp::PartialOrd for FooOrdBeforePartialOrd { #[inline] - fn partial_cmp(&self, other: &FooOrdBeforePartialOrd) + fn partial_cmp(&self, other: &Self) -> ::core::option::Option<::core::cmp::Ordering> { ::core::option::Option::Some(::core::cmp::Ord::cmp(self, other)) } @@ -1799,7 +1797,7 @@ impl ::core::cmp::PartialOrd for FooOrdBeforePartialOrd { #[automatically_derived] impl ::core::cmp::Ord for FooOrdBeforePartialOrd { #[inline] - fn cmp(&self, other: &FooOrdBeforePartialOrd) -> ::core::cmp::Ordering { + fn cmp(&self, other: &Self) -> ::core::cmp::Ordering { ::core::cmp::Ord::cmp(&self.0, &other.0) } } @@ -1809,14 +1807,14 @@ struct FooPartialOrdBeforeOrd(i32); #[automatically_derived] impl ::core::cmp::Ord for FooPartialOrdBeforeOrd { #[inline] - fn cmp(&self, other: &FooPartialOrdBeforeOrd) -> ::core::cmp::Ordering { + fn cmp(&self, other: &Self) -> ::core::cmp::Ordering { ::core::cmp::Ord::cmp(&self.0, &other.0) } } #[automatically_derived] impl ::core::cmp::PartialOrd for FooPartialOrdBeforeOrd { #[inline] - fn partial_cmp(&self, other: &FooPartialOrdBeforeOrd) + fn partial_cmp(&self, other: &Self) -> ::core::option::Option<::core::cmp::Ordering> { ::core::cmp::PartialOrd::partial_cmp(&self.0, &other.0) } @@ -1826,7 +1824,7 @@ struct UnitStruct; #[automatically_derived] impl ::core::cmp::PartialOrd for UnitStruct { #[inline] - fn partial_cmp(&self, other: &UnitStruct) + fn partial_cmp(&self, other: &Self) -> ::core::option::Option<::core::cmp::Ordering> { ::core::option::Option::Some(::core::cmp::Ordering::Equal) } @@ -1834,7 +1832,7 @@ impl ::core::cmp::PartialOrd for UnitStruct { #[automatically_derived] impl ::core::cmp::Ord for UnitStruct { #[inline] - fn cmp(&self, other: &UnitStruct) -> ::core::cmp::Ordering { + fn cmp(&self, other: &Self) -> ::core::cmp::Ordering { ::core::cmp::Ordering::Equal } } diff --git a/tests/ui/duplicate/multiple-types-with-same-name-and-derive-default-133965.rs b/tests/ui/duplicate/multiple-types-with-same-name-and-derive-default-133965.rs index f4193f18352d0..34ba998c1dc60 100644 --- a/tests/ui/duplicate/multiple-types-with-same-name-and-derive-default-133965.rs +++ b/tests/ui/duplicate/multiple-types-with-same-name-and-derive-default-133965.rs @@ -3,8 +3,6 @@ struct NonGeneric {} #[derive(Default)] -//~^ ERROR: struct takes 0 lifetime arguments but 1 lifetime argument was supplied -//~| ERROR: struct takes 0 generic arguments but 1 generic argument was supplied struct NonGeneric<'a, const N: usize> {} //~^ ERROR: struct takes 0 lifetime arguments but 1 lifetime argument was supplied //~| ERROR: struct takes 0 generic arguments but 1 generic argument was supplied diff --git a/tests/ui/duplicate/multiple-types-with-same-name-and-derive-default-133965.stderr b/tests/ui/duplicate/multiple-types-with-same-name-and-derive-default-133965.stderr index 0d6aaaf5186d3..d758cb13f9939 100644 --- a/tests/ui/duplicate/multiple-types-with-same-name-and-derive-default-133965.stderr +++ b/tests/ui/duplicate/multiple-types-with-same-name-and-derive-default-133965.stderr @@ -1,5 +1,5 @@ error[E0428]: the name `NonGeneric` is defined multiple times - --> $DIR/multiple-types-with-same-name-and-derive-default-133965.rs:8:1 + --> $DIR/multiple-types-with-same-name-and-derive-default-133965.rs:6:1 | LL | struct NonGeneric {} | ----------------- previous definition of the type `NonGeneric` here @@ -10,42 +10,7 @@ LL | struct NonGeneric<'a, const N: usize> {} = note: `NonGeneric` must be defined only once in the type namespace of this module error[E0107]: struct takes 0 lifetime arguments but 1 lifetime argument was supplied - --> $DIR/multiple-types-with-same-name-and-derive-default-133965.rs:5:10 - | -LL | #[derive(Default)] - | ^^^^^^^ expected 0 lifetime arguments -... -LL | struct NonGeneric<'a, const N: usize> {} - | -- help: remove the lifetime argument - | -note: struct defined here, with 0 lifetime parameters - --> $DIR/multiple-types-with-same-name-and-derive-default-133965.rs:3:8 - | -LL | struct NonGeneric {} - | ^^^^^^^^^^ - -error[E0107]: struct takes 0 generic arguments but 1 generic argument was supplied - --> $DIR/multiple-types-with-same-name-and-derive-default-133965.rs:5:10 - | -LL | #[derive(Default)] - | ^^^^^^^ expected 0 generic arguments - | -note: struct defined here, with 0 generic parameters - --> $DIR/multiple-types-with-same-name-and-derive-default-133965.rs:3:8 - | -LL | struct NonGeneric {} - | ^^^^^^^^^^ - -error[E0392]: lifetime parameter `'a` is never used - --> $DIR/multiple-types-with-same-name-and-derive-default-133965.rs:8:19 - | -LL | struct NonGeneric<'a, const N: usize> {} - | ^^ unused lifetime parameter - | - = help: consider removing `'a`, referring to it in a field, or using a marker such as `PhantomData` - -error[E0107]: struct takes 0 lifetime arguments but 1 lifetime argument was supplied - --> $DIR/multiple-types-with-same-name-and-derive-default-133965.rs:8:8 + --> $DIR/multiple-types-with-same-name-and-derive-default-133965.rs:6:8 | LL | struct NonGeneric<'a, const N: usize> {} | ^^^^^^^^^^ -- help: remove the lifetime argument @@ -59,7 +24,7 @@ LL | struct NonGeneric {} | ^^^^^^^^^^ error[E0107]: struct takes 0 generic arguments but 1 generic argument was supplied - --> $DIR/multiple-types-with-same-name-and-derive-default-133965.rs:8:8 + --> $DIR/multiple-types-with-same-name-and-derive-default-133965.rs:6:8 | LL | struct NonGeneric<'a, const N: usize> {} | ^^^^^^^^^^ - help: remove the unnecessary generic argument @@ -72,7 +37,15 @@ note: struct defined here, with 0 generic parameters LL | struct NonGeneric {} | ^^^^^^^^^^ -error: aborting due to 6 previous errors +error[E0392]: lifetime parameter `'a` is never used + --> $DIR/multiple-types-with-same-name-and-derive-default-133965.rs:6:19 + | +LL | struct NonGeneric<'a, const N: usize> {} + | ^^ unused lifetime parameter + | + = help: consider removing `'a`, referring to it in a field, or using a marker such as `PhantomData` + +error: aborting due to 4 previous errors Some errors have detailed explanations: E0107, E0392, E0428. For more information about an error, try `rustc --explain E0107`. diff --git a/tests/ui/duplicate/multiple-types-with-same-name-and-derive.rs b/tests/ui/duplicate/multiple-types-with-same-name-and-derive.rs index e946c0c5350ed..3caf5434cd008 100644 --- a/tests/ui/duplicate/multiple-types-with-same-name-and-derive.rs +++ b/tests/ui/duplicate/multiple-types-with-same-name-and-derive.rs @@ -8,12 +8,10 @@ struct NotSM; #[derive(PartialEq, Eq)] -//~^ ERROR: struct takes 0 generic arguments struct NotSM(T); //~^ ERROR: struct takes 0 generic arguments //~| ERROR: struct takes 0 generic arguments //~| ERROR: struct takes 0 generic arguments //~| ERROR: the name `NotSM` is defined multiple times -//~| ERROR: no field `0` fn main() {} diff --git a/tests/ui/duplicate/multiple-types-with-same-name-and-derive.stderr b/tests/ui/duplicate/multiple-types-with-same-name-and-derive.stderr index e80cf35d81e1d..e745b3ce8fc2f 100644 --- a/tests/ui/duplicate/multiple-types-with-same-name-and-derive.stderr +++ b/tests/ui/duplicate/multiple-types-with-same-name-and-derive.stderr @@ -1,5 +1,5 @@ error[E0428]: the name `NotSM` is defined multiple times - --> $DIR/multiple-types-with-same-name-and-derive.rs:12:1 + --> $DIR/multiple-types-with-same-name-and-derive.rs:11:1 | LL | struct NotSM; | ------------- previous definition of the type `NotSM` here @@ -10,7 +10,7 @@ LL | struct NotSM(T); = note: `NotSM` must be defined only once in the type namespace of this module error[E0107]: struct takes 0 generic arguments but 1 generic argument was supplied - --> $DIR/multiple-types-with-same-name-and-derive.rs:12:8 + --> $DIR/multiple-types-with-same-name-and-derive.rs:11:8 | LL | struct NotSM(T); | ^^^^^ expected 0 generic arguments @@ -22,19 +22,7 @@ LL | struct NotSM; | ^^^^^ error[E0107]: struct takes 0 generic arguments but 1 generic argument was supplied - --> $DIR/multiple-types-with-same-name-and-derive.rs:10:10 - | -LL | #[derive(PartialEq, Eq)] - | ^^^^^^^^^ expected 0 generic arguments - | -note: struct defined here, with 0 generic parameters - --> $DIR/multiple-types-with-same-name-and-derive.rs:8:8 - | -LL | struct NotSM; - | ^^^^^ - -error[E0107]: struct takes 0 generic arguments but 1 generic argument was supplied - --> $DIR/multiple-types-with-same-name-and-derive.rs:12:8 + --> $DIR/multiple-types-with-same-name-and-derive.rs:11:8 | LL | struct NotSM(T); | ^^^^^ expected 0 generic arguments @@ -47,7 +35,7 @@ LL | struct NotSM; = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error[E0107]: struct takes 0 generic arguments but 1 generic argument was supplied - --> $DIR/multiple-types-with-same-name-and-derive.rs:12:8 + --> $DIR/multiple-types-with-same-name-and-derive.rs:11:8 | LL | struct NotSM(T); | ^^^^^ expected 0 generic arguments @@ -59,13 +47,7 @@ LL | struct NotSM; | ^^^^^ = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -error[E0609]: no field `0` on type `&NotSM` - --> $DIR/multiple-types-with-same-name-and-derive.rs:12:17 - | -LL | struct NotSM(T); - | ^ unknown field - -error: aborting due to 6 previous errors +error: aborting due to 4 previous errors -Some errors have detailed explanations: E0107, E0428, E0609. +Some errors have detailed explanations: E0107, E0428. For more information about an error, try `rustc --explain E0107`. diff --git a/tests/ui/stats/macro-stats.stderr b/tests/ui/stats/macro-stats.stderr index c70895067eb5f..e3ef2add347dc 100644 --- a/tests/ui/stats/macro-stats.stderr +++ b/tests/ui/stats/macro-stats.stderr @@ -2,15 +2,15 @@ macro-stats ==================================================================== macro-stats MACRO EXPANSION STATS: macro_stats macro-stats Macro Name Uses Lines Avg Lines Bytes Avg Bytes macro-stats ----------------------------------------------------------------------------------- -macro-stats #[derive(Clone)] 8 67 8.4 1_879 234.9 +macro-stats #[derive(Clone)] 8 67 8.4 1_895 236.9 macro-stats #[derive(Hash)] 2 17 8.5 565 282.5 macro-stats q! 1 26 26.0 519 519.0 -macro-stats #[derive(Ord)] 1 15 15.0 503 503.0 -macro-stats #[derive(Default)] 2 16 8.0 403 201.5 +macro-stats #[derive(Ord)] 1 15 15.0 505 505.0 +macro-stats #[derive(Default)] 2 16 8.0 407 203.5 macro-stats #[derive(Eq)] 1 11 11.0 312 312.0 macro-stats #[derive(Debug)] 1 8 8.0 277 277.0 -macro-stats #[derive(PartialEq)] 1 9 9.0 267 267.0 -macro-stats #[derive(PartialOrd)] 1 8 8.0 254 254.0 +macro-stats #[derive(PartialEq)] 1 9 9.0 269 269.0 +macro-stats #[derive(PartialOrd)] 1 8 8.0 256 256.0 macro-stats #[derive(Copy)] 1 2 2.0 61 61.0 macro-stats p! 1 3 3.0 32 32.0 macro-stats trait_impl_tys! 1 2 2.0 28 28.0 diff --git a/tests/ui/traits/issue-106072.rs b/tests/ui/traits/issue-106072.rs index 6b04004621d82..74a8893d38b07 100644 --- a/tests/ui/traits/issue-106072.rs +++ b/tests/ui/traits/issue-106072.rs @@ -1,4 +1,4 @@ -#[derive(Clone)] //~ ERROR: expected a type, found a trait +#[derive(Clone)] struct Foo; //~ ERROR: expected a type, found a trait trait Foo {} //~ ERROR: the name `Foo` is defined multiple times fn main() {} diff --git a/tests/ui/traits/issue-106072.stderr b/tests/ui/traits/issue-106072.stderr index 57661fda73079..ccee54cecf498 100644 --- a/tests/ui/traits/issue-106072.stderr +++ b/tests/ui/traits/issue-106072.stderr @@ -16,13 +16,7 @@ LL | #[derive(Clone)] LL | struct Foo; | ^^^ -error[E0782]: expected a type, found a trait - --> $DIR/issue-106072.rs:1:10 - | -LL | #[derive(Clone)] - | ^^^^^ - -error: aborting due to 3 previous errors +error: aborting due to 2 previous errors Some errors have detailed explanations: E0428, E0782. For more information about an error, try `rustc --explain E0428`. From 072a61a39fed3c98c3fdc9cdfa1cc3fd914909d1 Mon Sep 17 00:00:00 2001 From: cyrgani Date: Thu, 17 Sep 2026 20:19:51 +0000 Subject: [PATCH 9/9] remove only recursively used arguments --- .../src/deriving/generic/mod.rs | 35 ++++++------------ .../src/deriving/generic/ty.rs | 36 +++++-------------- 2 files changed, 19 insertions(+), 52 deletions(-) diff --git a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs index baab6552052ed..050b2e793f501 100644 --- a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs +++ b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs @@ -571,7 +571,7 @@ impl<'a> TraitDef<'a> { methods: impl Iterator>, is_packed: bool, ) -> Box { - let trait_path = self.path.to_path(cx, self.span, type_ident, generics); + let trait_path = self.path.to_path(cx, self.span); // Transform associated types from `deriving::ty::Ty` into `ast::AssocItem` let associated_types = self.associated_types.iter().map(|&(ident, ref type_def)| { @@ -589,7 +589,7 @@ impl<'a> TraitDef<'a> { generics: Generics::default(), after_where_clause: ast::WhereClause::default(), bounds: ThinVec::new(), - ty: Some(type_def.to_ty(cx, self.span, type_ident, generics)), + ty: Some(type_def.to_ty(cx, self.span)), })), tokens: None, }) @@ -613,9 +613,7 @@ impl<'a> TraitDef<'a> { let bounds: ThinVec<_> = self .additional_bounds .iter() - .map(|p| { - cx.trait_bound(p.to_path(cx, span, type_ident, generics), self.is_const) - }) + .map(|p| cx.trait_bound(p.to_path(cx, span), self.is_const)) .chain( // Add a bound for the current trait. self.skip_path_as_bound.not().then(|| { @@ -628,10 +626,7 @@ impl<'a> TraitDef<'a> { // Add a `Copy` bound if required. if is_packed && self.needs_copy_as_bound_if_packed { let p = deriving::path_std!(marker::Copy); - Some(cx.trait_bound( - p.to_path(cx, span, type_ident, generics), - self.is_const, - )) + Some(cx.trait_bound(p.to_path(cx, span), self.is_const)) } else { None } @@ -697,12 +692,7 @@ impl<'a> TraitDef<'a> { let mut bounds: ThinVec<_> = self .additional_bounds .iter() - .map(|p| { - cx.trait_bound( - p.to_path(cx, self.span, type_ident, generics), - self.is_const, - ) - }) + .map(|p| cx.trait_bound(p.to_path(cx, self.span), self.is_const)) .collect(); // Require the current trait. @@ -713,10 +703,7 @@ impl<'a> TraitDef<'a> { // Add a `Copy` bound if required. if is_packed && self.needs_copy_as_bound_if_packed { let p = deriving::path_std!(marker::Copy); - bounds.push(cx.trait_bound( - p.to_path(cx, self.span, type_ident, generics), - self.is_const, - )); + bounds.push(cx.trait_bound(p.to_path(cx, self.span), self.is_const)); } if !bounds.is_empty() { @@ -862,7 +849,7 @@ impl<'a> TraitDef<'a> { ) }; - method_def.create_method(cx, self, type_ident, generics, body) + method_def.create_method(cx, self, body) }); self.create_derived_impl(cx, type_ident, generics, field_tys, methods, is_packed) @@ -905,7 +892,7 @@ impl<'a> TraitDef<'a> { ) }; - method_def.create_method(cx, self, type_ident, generics, body) + method_def.create_method(cx, self, body) }); let is_packed = false; // enums are never packed @@ -969,8 +956,6 @@ impl<'a> MethodDef<'a> { &self, cx: &ExtCtxt<'_>, trait_: &TraitDef<'_>, - type_ident: Ident, - generics: &Generics, body: BlockOrExpr, ) -> Option> { // `assert_fields_are_eq` has an empty default implementation @@ -992,7 +977,7 @@ impl<'a> MethodDef<'a> { let args = self_arg .into_iter() .chain(self.nonself_args.iter().map(|(ty, name)| { - let ast_ty = ty.to_ty(cx, span, type_ident, generics); + let ast_ty = ty.to_ty(cx, span); let ident = Ident::new(*name, span); cx.param(span, ident, ast_ty) })) @@ -1001,7 +986,7 @@ impl<'a> MethodDef<'a> { let ret_type = if let Ty::Unit = &self.ret_ty { ast::FnRetTy::Default(span) } else { - ast::FnRetTy::Ty(self.ret_ty.to_ty(cx, span, type_ident, generics)) + ast::FnRetTy::Ty(self.ret_ty.to_ty(cx, span)) }; let method_ident = Ident::new(self.name, span); diff --git a/compiler/rustc_builtin_macros/src/deriving/generic/ty.rs b/compiler/rustc_builtin_macros/src/deriving/generic/ty.rs index 108166788d8b6..9efe0b109f17d 100644 --- a/compiler/rustc_builtin_macros/src/deriving/generic/ty.rs +++ b/compiler/rustc_builtin_macros/src/deriving/generic/ty.rs @@ -4,7 +4,7 @@ use std::iter::once; pub(crate) use Ty::*; -use rustc_ast::{self as ast, GenericArg, Generics, TyKind}; +use rustc_ast::{self as ast, GenericArg, TyKind}; use rustc_expand::base::ExtCtxt; use rustc_span::{DUMMY_SP, Ident, Span, Symbol, kw}; use thin_vec::ThinVec; @@ -35,15 +35,9 @@ impl Path { Path { path, params, kind } } - pub(crate) fn to_path( - &self, - cx: &ExtCtxt<'_>, - span: Span, - self_ty: Ident, - self_generics: &Generics, - ) -> ast::Path { + pub(crate) fn to_path(&self, cx: &ExtCtxt<'_>, span: Span) -> ast::Path { let idents = self.path.iter().map(|s| Ident::new(*s, span)); - let tys = self.params.iter().map(|t| t.to_ty(cx, span, self_ty, self_generics)); + let tys = self.params.iter().map(|t| t.to_ty(cx, span)); let params = tys.map(GenericArg::Type).collect(); let idents = if let PathKind::Std = self.kind { @@ -76,20 +70,14 @@ pub(crate) fn self_ref() -> Ty { } impl Ty { - pub(crate) fn to_ty( - &self, - cx: &ExtCtxt<'_>, - span: Span, - self_ty: Ident, - self_generics: &Generics, - ) -> Box { + pub(crate) fn to_ty(&self, cx: &ExtCtxt<'_>, span: Span) -> Box { match self { Ref(ty, mutbl) => { - let raw_ty = ty.to_ty(cx, span, self_ty, self_generics); + let raw_ty = ty.to_ty(cx, span); cx.ty_ref(span, raw_ty, None, *mutbl) } - Path(p) => cx.ty_path(p.to_path(cx, span, self_ty, self_generics)), - Self_ => cx.ty_path(self.to_path(cx, span, self_ty, self_generics)), + Path(p) => cx.ty_path(p.to_path(cx, span)), + Self_ => cx.ty_path(self.to_path(cx, span)), Unit => { let ty = ast::TyKind::Tup(ThinVec::new()); cx.ty(span, ty) @@ -98,16 +86,10 @@ impl Ty { } } - pub(crate) fn to_path( - &self, - cx: &ExtCtxt<'_>, - span: Span, - self_ty: Ident, - generics: &Generics, - ) -> ast::Path { + pub(crate) fn to_path(&self, cx: &ExtCtxt<'_>, span: Span) -> ast::Path { match self { Self_ => cx.path_ident(span, Ident::new(kw::SelfUpper, span)), - Path(p) => p.to_path(cx, span, self_ty, generics), + Path(p) => p.to_path(cx, span), AstTy(ty) => match &ty.kind { TyKind::Path(_, path) => path.clone(), _ => cx.dcx().span_bug(span, "non-path in a path in generic `derive`"),