Skip to content

Commit d3057b5

Browse files
committed
Rename FieldInfo fields.
Use `self_exprs` and `other_selflike_exprs` in a manner similar to the previous commit.
1 parent 32c9ffb commit d3057b5

File tree

8 files changed

+59
-45
lines changed

8 files changed

+59
-45
lines changed

compiler/rustc_builtin_macros/src/deriving/clone.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ fn cs_clone(
161161
let all_fields;
162162
let fn_path = cx.std_path(&[sym::clone, sym::Clone, sym::clone]);
163163
let subcall = |cx: &mut ExtCtxt<'_>, field: &FieldInfo<'_>| {
164-
let args = vec![cx.expr_addr_of(field.span, field.self_.clone())];
164+
let args = vec![cx.expr_addr_of(field.span, field.self_expr.clone())];
165165
cx.expr_call_global(field.span, fn_path.clone(), args)
166166
};
167167

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,19 @@ pub fn cs_cmp(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>) -> Bl
7474
// foldr nests the if-elses correctly, leaving the first field
7575
// as the outermost one, and the last as the innermost.
7676
false,
77-
|cx, span, old, self_f, other_fs| {
77+
|cx, span, old, self_expr, other_selflike_exprs| {
7878
// match new {
7979
// ::std::cmp::Ordering::Equal => old,
8080
// cmp => cmp
8181
// }
8282
let new = {
83-
let [other_f] = other_fs else {
83+
let [other_expr] = other_selflike_exprs else {
8484
cx.span_bug(span, "not exactly 2 arguments in `derive(Ord)`");
8585
};
86-
let args =
87-
vec![cx.expr_addr_of(span, self_f), cx.expr_addr_of(span, other_f.clone())];
86+
let args = vec![
87+
cx.expr_addr_of(span, self_expr),
88+
cx.expr_addr_of(span, other_expr.clone()),
89+
];
8890
cx.expr_call_global(span, cmp_path.clone(), args)
8991
};
9092

@@ -94,13 +96,15 @@ pub fn cs_cmp(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>) -> Bl
9496
cx.expr_match(span, new, vec![eq_arm, neq_arm])
9597
},
9698
|cx, args| match args {
97-
Some((span, self_f, other_fs)) => {
99+
Some((span, self_expr, other_selflike_exprs)) => {
98100
let new = {
99-
let [other_f] = other_fs else {
101+
let [other_expr] = other_selflike_exprs else {
100102
cx.span_bug(span, "not exactly 2 arguments in `derive(Ord)`");
101103
};
102-
let args =
103-
vec![cx.expr_addr_of(span, self_f), cx.expr_addr_of(span, other_f.clone())];
104+
let args = vec![
105+
cx.expr_addr_of(span, self_expr),
106+
cx.expr_addr_of(span, other_expr.clone()),
107+
];
104108
cx.expr_call_global(span, cmp_path.clone(), args)
105109
};
106110

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,28 @@ pub fn expand_deriving_partial_eq(
2323
combiner: BinOpKind,
2424
base: bool,
2525
) -> BlockOrExpr {
26-
let op = |cx: &mut ExtCtxt<'_>, span: Span, self_f: P<Expr>, other_fs: &[P<Expr>]| {
27-
let [other_f] = other_fs else {
26+
let op = |cx: &mut ExtCtxt<'_>,
27+
span: Span,
28+
self_expr: P<Expr>,
29+
other_selflike_exprs: &[P<Expr>]| {
30+
let [other_expr] = other_selflike_exprs else {
2831
cx.span_bug(span, "not exactly 2 arguments in `derive(PartialEq)`");
2932
};
3033

31-
cx.expr_binary(span, op, self_f, other_f.clone())
34+
cx.expr_binary(span, op, self_expr, other_expr.clone())
3235
};
3336

3437
let expr = cs_fold(
3538
true, // use foldl
36-
|cx, span, subexpr, self_f, other_fs| {
37-
let eq = op(cx, span, self_f, other_fs);
39+
|cx, span, subexpr, self_expr, other_selflike_exprs| {
40+
let eq = op(cx, span, self_expr, other_selflike_exprs);
3841
cx.expr_binary(span, combiner, subexpr, eq)
3942
},
4043
|cx, args| {
4144
match args {
42-
Some((span, self_f, other_fs)) => {
45+
Some((span, self_expr, other_selflike_exprs)) => {
4346
// Special-case the base case to generate cleaner code.
44-
op(cx, span, self_f, other_fs)
47+
op(cx, span, self_expr, other_selflike_exprs)
4548
}
4649
None => cx.expr_bool(span, base),
4750
}

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,19 +72,21 @@ pub fn cs_partial_cmp(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_
7272
// foldr nests the if-elses correctly, leaving the first field
7373
// as the outermost one, and the last as the innermost.
7474
false,
75-
|cx, span, old, self_f, other_fs| {
75+
|cx, span, old, self_expr, other_selflike_exprs| {
7676
// match new {
7777
// Some(::std::cmp::Ordering::Equal) => old,
7878
// cmp => cmp
7979
// }
8080

8181
let new = {
82-
let [other_f] = other_fs else {
82+
let [other_expr] = other_selflike_exprs else {
8383
cx.span_bug(span, "not exactly 2 arguments in `derive(PartialOrd)`");
8484
};
8585

86-
let args =
87-
vec![cx.expr_addr_of(span, self_f), cx.expr_addr_of(span, other_f.clone())];
86+
let args = vec![
87+
cx.expr_addr_of(span, self_expr),
88+
cx.expr_addr_of(span, other_expr.clone()),
89+
];
8890

8991
cx.expr_call_global(span, partial_cmp_path.clone(), args)
9092
};
@@ -95,13 +97,15 @@ pub fn cs_partial_cmp(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_
9597
cx.expr_match(span, new, vec![eq_arm, neq_arm])
9698
},
9799
|cx: &mut ExtCtxt<'_>, args: Option<(Span, P<Expr>, &[P<Expr>])>| match args {
98-
Some((span, self_f, other_fs)) => {
100+
Some((span, self_expr, other_selflike_exprs)) => {
99101
let new = {
100-
let [other_f] = other_fs else {
102+
let [other_expr] = other_selflike_exprs else {
101103
cx.span_bug(span, "not exactly 2 arguments in `derive(Ord)`");
102104
};
103-
let args =
104-
vec![cx.expr_addr_of(span, self_f), cx.expr_addr_of(span, other_f.clone())];
105+
let args = vec![
106+
cx.expr_addr_of(span, self_expr),
107+
cx.expr_addr_of(span, other_expr.clone()),
108+
];
105109
cx.expr_call_global(span, partial_cmp_path.clone(), args)
106110
};
107111

compiler/rustc_builtin_macros/src/deriving/debug.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ fn show_substructure(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>
9696
args.push(name);
9797
}
9898
// Use double indirection to make sure this works for unsized types
99-
let field = cx.expr_addr_of(field.span, field.self_.clone());
99+
let field = cx.expr_addr_of(field.span, field.self_expr.clone());
100100
let field = cx.expr_addr_of(field.span, field);
101101
args.push(field);
102102
}
@@ -116,7 +116,7 @@ fn show_substructure(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>
116116
}
117117

118118
// Use double indirection to make sure this works for unsized types
119-
let value_ref = cx.expr_addr_of(field.span, field.self_.clone());
119+
let value_ref = cx.expr_addr_of(field.span, field.self_expr.clone());
120120
value_exprs.push(cx.expr_addr_of(field.span, value_ref));
121121
}
122122

compiler/rustc_builtin_macros/src/deriving/encodable.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,12 @@ fn encodable_substructure(
168168
let fn_emit_struct_field_path =
169169
cx.def_site_path(&[sym::rustc_serialize, sym::Encoder, sym::emit_struct_field]);
170170
let mut stmts = Vec::new();
171-
for (i, &FieldInfo { name, ref self_, span, .. }) in fields.iter().enumerate() {
171+
for (i, &FieldInfo { name, ref self_expr, span, .. }) in fields.iter().enumerate() {
172172
let name = match name {
173173
Some(id) => id.name,
174174
None => Symbol::intern(&format!("_field{}", i)),
175175
};
176-
let self_ref = cx.expr_addr_of(span, self_.clone());
176+
let self_ref = cx.expr_addr_of(span, self_expr.clone());
177177
let enc = cx.expr_call(span, fn_path.clone(), vec![self_ref, blkencoder.clone()]);
178178
let lambda = cx.lambda1(span, enc, blkarg);
179179
let call = cx.expr_call_global(
@@ -237,8 +237,8 @@ fn encodable_substructure(
237237
let mut stmts = Vec::new();
238238
if !fields.is_empty() {
239239
let last = fields.len() - 1;
240-
for (i, &FieldInfo { ref self_, span, .. }) in fields.iter().enumerate() {
241-
let self_ref = cx.expr_addr_of(span, self_.clone());
240+
for (i, &FieldInfo { ref self_expr, span, .. }) in fields.iter().enumerate() {
241+
let self_ref = cx.expr_addr_of(span, self_expr.clone());
242242
let enc =
243243
cx.expr_call(span, fn_path.clone(), vec![self_ref, blkencoder.clone()]);
244244
let lambda = cx.lambda1(span, enc, blkarg);

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

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,10 @@ pub struct FieldInfo<'a> {
258258
pub name: Option<Ident>,
259259
/// The expression corresponding to this field of `self`
260260
/// (specifically, a reference to it).
261-
pub self_: P<Expr>,
261+
pub self_expr: P<Expr>,
262262
/// The expressions corresponding to references to this field in
263-
/// the other `Self` arguments.
264-
pub other: Vec<P<Expr>>,
263+
/// the other selflike arguments.
264+
pub other_selflike_exprs: Vec<P<Expr>>,
265265
/// The attributes on the field
266266
pub attrs: &'a [ast::Attribute],
267267
}
@@ -1080,13 +1080,13 @@ impl<'a> MethodDef<'a> {
10801080
let fields = if !raw_fields.is_empty() {
10811081
let mut raw_fields = raw_fields.into_iter().map(|v| v.into_iter());
10821082
let first_field = raw_fields.next().unwrap();
1083-
let mut other_fields: Vec<vec::IntoIter<_>> = raw_fields.collect();
1083+
let mut nonself_fields: Vec<vec::IntoIter<_>> = raw_fields.collect();
10841084
first_field
1085-
.map(|(span, opt_id, field, attrs)| FieldInfo {
1085+
.map(|(span, opt_id, expr, attrs)| FieldInfo {
10861086
span: span.with_ctxt(trait_.span.ctxt()),
10871087
name: opt_id,
1088-
self_: field,
1089-
other: other_fields
1088+
self_expr: expr,
1089+
other_selflike_exprs: nonself_fields
10901090
.iter_mut()
10911091
.map(|l| {
10921092
let (.., ex, _) = l.next().unwrap();
@@ -1289,7 +1289,7 @@ impl<'a> MethodDef<'a> {
12891289
// and pull out getter for same field in each
12901290
// of them (using `field_index` tracked above).
12911291
// That is the heart of the transposition.
1292-
let others = selflike_pats_idents
1292+
let other_selflike_exprs = selflike_pats_idents
12931293
.iter()
12941294
.map(|fields| {
12951295
let (_, _opt_ident, ref other_getter_expr, _) = fields[field_index];
@@ -1307,8 +1307,8 @@ impl<'a> MethodDef<'a> {
13071307
FieldInfo {
13081308
span,
13091309
name: opt_ident,
1310-
self_: self_getter_expr,
1311-
other: others,
1310+
self_expr: self_getter_expr,
1311+
other_selflike_exprs,
13121312
attrs,
13131313
}
13141314
})
@@ -1712,24 +1712,25 @@ where
17121712
let (base, rest) = match (all_fields.is_empty(), use_foldl) {
17131713
(false, true) => {
17141714
let (first, rest) = all_fields.split_first().unwrap();
1715-
let args = (first.span, first.self_.clone(), &first.other[..]);
1715+
let args =
1716+
(first.span, first.self_expr.clone(), &first.other_selflike_exprs[..]);
17161717
(b(cx, Some(args)), rest)
17171718
}
17181719
(false, false) => {
17191720
let (last, rest) = all_fields.split_last().unwrap();
1720-
let args = (last.span, last.self_.clone(), &last.other[..]);
1721+
let args = (last.span, last.self_expr.clone(), &last.other_selflike_exprs[..]);
17211722
(b(cx, Some(args)), rest)
17221723
}
17231724
(true, _) => (b(cx, None), &all_fields[..]),
17241725
};
17251726

17261727
if use_foldl {
17271728
rest.iter().fold(base, |old, field| {
1728-
f(cx, field.span, old, field.self_.clone(), &field.other)
1729+
f(cx, field.span, old, field.self_expr.clone(), &field.other_selflike_exprs)
17291730
})
17301731
} else {
17311732
rest.iter().rev().fold(base, |old, field| {
1732-
f(cx, field.span, old, field.self_.clone(), &field.other)
1733+
f(cx, field.span, old, field.self_expr.clone(), &field.other_selflike_exprs)
17331734
})
17341735
}
17351736
}

compiler/rustc_builtin_macros/src/deriving/hash.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ fn hash_substructure(
8282
};
8383

8484
stmts.extend(
85-
fields.iter().map(|FieldInfo { ref self_, span, .. }| call_hash(*span, self_.clone())),
85+
fields
86+
.iter()
87+
.map(|FieldInfo { ref self_expr, span, .. }| call_hash(*span, self_expr.clone())),
8688
);
8789
BlockOrExpr::new_stmts(stmts)
8890
}

0 commit comments

Comments
 (0)