Skip to content

Commit 0578697

Browse files
committed
Minor updates based on review comments.
1 parent 16a286b commit 0578697

File tree

1 file changed

+10
-15
lines changed
  • compiler/rustc_builtin_macros/src/deriving/generic

1 file changed

+10
-15
lines changed

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

+10-15
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,8 @@ pub struct MethodDef<'a> {
245245
pub struct Substructure<'a> {
246246
/// ident of self
247247
pub type_ident: Ident,
248-
/// verbatim access to any non-selflike arguments
248+
/// Verbatim access to any non-selflike arguments, i.e. arguments that
249+
/// don't have type `&Self`.
249250
pub nonselflike_args: &'a [P<Expr>],
250251
pub fields: &'a SubstructureFields<'a>,
251252
}
@@ -934,10 +935,9 @@ impl<'a> MethodDef<'a> {
934935

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

937-
match *ty {
938-
// for static methods, just treat any Self
939-
// arguments as a normal arg
940-
Ref(ref ty, _) if matches!(**ty, Self_) && !self.is_static() => {
938+
match ty {
939+
// Selflike (`&Self`) arguments only occur in non-static methods.
940+
Ref(box Self_, _) if !self.is_static() => {
941941
selflike_args.push(cx.expr_deref(span, arg_expr))
942942
}
943943
Self_ => cx.span_bug(span, "`Self` in non-return position"),
@@ -1459,11 +1459,8 @@ impl<'a> TraitDef<'a> {
14591459
prefixes
14601460
.iter()
14611461
.map(|prefix| {
1462-
let pieces: Vec<_> = struct_def
1463-
.fields()
1464-
.iter()
1465-
.enumerate()
1466-
.map(|(i, struct_field)| {
1462+
let pieces_iter =
1463+
struct_def.fields().iter().enumerate().map(|(i, struct_field)| {
14671464
let sp = struct_field.span.with_ctxt(self.span.ctxt());
14681465
let binding_mode = if use_temporaries {
14691466
ast::BindingMode::ByValue(ast::Mutability::Not)
@@ -1477,14 +1474,12 @@ impl<'a> TraitDef<'a> {
14771474
struct_field.ident,
14781475
cx.pat(path.span, PatKind::Ident(binding_mode, path, None)),
14791476
)
1480-
})
1481-
.collect();
1477+
});
14821478

14831479
let struct_path = struct_path.clone();
14841480
match *struct_def {
14851481
VariantData::Struct(..) => {
1486-
let field_pats = pieces
1487-
.into_iter()
1482+
let field_pats = pieces_iter
14881483
.map(|(sp, ident, pat)| {
14891484
if ident.is_none() {
14901485
cx.span_bug(
@@ -1506,7 +1501,7 @@ impl<'a> TraitDef<'a> {
15061501
cx.pat_struct(self.span, struct_path, field_pats)
15071502
}
15081503
VariantData::Tuple(..) => {
1509-
let subpats = pieces.into_iter().map(|(_, _, subpat)| subpat).collect();
1504+
let subpats = pieces_iter.map(|(_, _, subpat)| subpat).collect();
15101505
cx.pat_tuple_struct(self.span, struct_path, subpats)
15111506
}
15121507
VariantData::Unit(..) => cx.pat_path(self.span, struct_path),

0 commit comments

Comments
 (0)