Skip to content

Commit

Permalink
Minor updates based on review comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
nnethercote committed Jul 9, 2022
1 parent 16a286b commit 0578697
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions compiler/rustc_builtin_macros/src/deriving/generic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,8 @@ pub struct MethodDef<'a> {
pub struct Substructure<'a> {
/// ident of self
pub type_ident: Ident,
/// verbatim access to any non-selflike arguments
/// Verbatim access to any non-selflike arguments, i.e. arguments that
/// don't have type `&Self`.
pub nonselflike_args: &'a [P<Expr>],
pub fields: &'a SubstructureFields<'a>,
}
Expand Down Expand Up @@ -934,10 +935,9 @@ impl<'a> MethodDef<'a> {

let arg_expr = cx.expr_ident(span, ident);

match *ty {
// for static methods, just treat any Self
// arguments as a normal arg
Ref(ref ty, _) if matches!(**ty, Self_) && !self.is_static() => {
match ty {
// Selflike (`&Self`) arguments only occur in non-static methods.
Ref(box Self_, _) if !self.is_static() => {
selflike_args.push(cx.expr_deref(span, arg_expr))
}
Self_ => cx.span_bug(span, "`Self` in non-return position"),
Expand Down Expand Up @@ -1459,11 +1459,8 @@ impl<'a> TraitDef<'a> {
prefixes
.iter()
.map(|prefix| {
let pieces: Vec<_> = struct_def
.fields()
.iter()
.enumerate()
.map(|(i, struct_field)| {
let pieces_iter =
struct_def.fields().iter().enumerate().map(|(i, struct_field)| {
let sp = struct_field.span.with_ctxt(self.span.ctxt());
let binding_mode = if use_temporaries {
ast::BindingMode::ByValue(ast::Mutability::Not)
Expand All @@ -1477,14 +1474,12 @@ impl<'a> TraitDef<'a> {
struct_field.ident,
cx.pat(path.span, PatKind::Ident(binding_mode, path, None)),
)
})
.collect();
});

let struct_path = struct_path.clone();
match *struct_def {
VariantData::Struct(..) => {
let field_pats = pieces
.into_iter()
let field_pats = pieces_iter
.map(|(sp, ident, pat)| {
if ident.is_none() {
cx.span_bug(
Expand All @@ -1506,7 +1501,7 @@ impl<'a> TraitDef<'a> {
cx.pat_struct(self.span, struct_path, field_pats)
}
VariantData::Tuple(..) => {
let subpats = pieces.into_iter().map(|(_, _, subpat)| subpat).collect();
let subpats = pieces_iter.map(|(_, _, subpat)| subpat).collect();
cx.pat_tuple_struct(self.span, struct_path, subpats)
}
VariantData::Unit(..) => cx.pat_path(self.span, struct_path),
Expand Down

0 comments on commit 0578697

Please sign in to comment.