Skip to content

Commit 6aecb1c

Browse files
committed
Don't use underscores for argument names in #[derive()] expansions
1 parent 74abffe commit 6aecb1c

File tree

2 files changed

+22
-22
lines changed

2 files changed

+22
-22
lines changed

src/libsyntax_ext/deriving/generic/mod.rs

+20-20
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,14 @@
156156
//!
157157
//! ```{.text}
158158
//! EnumNonMatchingCollapsed(
159-
//! vec![<ident of self>, <ident of __arg_1>],
159+
//! vec![<ident of self>, <ident of arg_1>],
160160
//! &[<ast::Variant for C0>, <ast::Variant for C1>],
161-
//! &[<ident for self index value>, <ident of __arg_1 index value>])
161+
//! &[<ident for self index value>, <ident of arg_1 index value>])
162162
//! ```
163163
//!
164164
//! It is the same for when the arguments are flipped to `C1 {x}` and
165165
//! `C0(a)`; the only difference is what the values of the identifiers
166-
//! <ident for self index value> and <ident of __arg_1 index value> will
166+
//! <ident for self index value> and <ident of arg_1 index value> will
167167
//! be in the generated code.
168168
//!
169169
//! `EnumNonMatchingCollapsed` deliberately provides far less information
@@ -912,7 +912,7 @@ impl<'a> MethodDef<'a> {
912912

913913
for (i, ty) in self.args.iter().enumerate() {
914914
let ast_ty = ty.to_ty(cx, trait_.span, type_ident, generics);
915-
let ident = cx.ident_of(&format!("__arg_{}", i));
915+
let ident = cx.ident_of(&format!("arg_{}", i));
916916
arg_tys.push((ident, ast_ty));
917917

918918
let arg_expr = cx.expr_ident(trait_.span, ident);
@@ -999,10 +999,10 @@ impl<'a> MethodDef<'a> {
999999
///
10001000
/// // equivalent to:
10011001
/// impl PartialEq for A {
1002-
/// fn eq(&self, __arg_1: &A) -> bool {
1002+
/// fn eq(&self, arg_1: &A) -> bool {
10031003
/// match *self {
10041004
/// A {x: ref __self_0_0, y: ref __self_0_1} => {
1005-
/// match *__arg_1 {
1005+
/// match *arg_1 {
10061006
/// A {x: ref __self_1_0, y: ref __self_1_1} => {
10071007
/// __self_0_0.eq(__self_1_0) && __self_0_1.eq(__self_1_1)
10081008
/// }
@@ -1015,10 +1015,10 @@ impl<'a> MethodDef<'a> {
10151015
/// // or if A is repr(packed) - note fields are matched by-value
10161016
/// // instead of by-reference.
10171017
/// impl PartialEq for A {
1018-
/// fn eq(&self, __arg_1: &A) -> bool {
1018+
/// fn eq(&self, arg_1: &A) -> bool {
10191019
/// match *self {
10201020
/// A {x: __self_0_0, y: __self_0_1} => {
1021-
/// match __arg_1 {
1021+
/// match arg_1 {
10221022
/// A {x: __self_1_0, y: __self_1_1} => {
10231023
/// __self_0_0.eq(&__self_1_0) && __self_0_1.eq(&__self_1_1)
10241024
/// }
@@ -1129,25 +1129,25 @@ impl<'a> MethodDef<'a> {
11291129
/// // is equivalent to
11301130
///
11311131
/// impl PartialEq for A {
1132-
/// fn eq(&self, __arg_1: &A) -> ::bool {
1133-
/// match (&*self, &*__arg_1) {
1132+
/// fn eq(&self, arg_1: &A) -> ::bool {
1133+
/// match (&*self, &*arg_1) {
11341134
/// (&A1, &A1) => true,
11351135
/// (&A2(ref self_0),
1136-
/// &A2(ref __arg_1_0)) => (*self_0).eq(&(*__arg_1_0)),
1136+
/// &A2(ref arg_1_0)) => (*self_0).eq(&(*arg_1_0)),
11371137
/// _ => {
11381138
/// let __self_vi = match *self { A1(..) => 0, A2(..) => 1 };
1139-
/// let __arg_1_vi = match *__arg_1 { A1(..) => 0, A2(..) => 1 };
1139+
/// let arg_1_vi = match *arg_1 { A1(..) => 0, A2(..) => 1 };
11401140
/// false
11411141
/// }
11421142
/// }
11431143
/// }
11441144
/// }
11451145
/// ```
11461146
///
1147-
/// (Of course `__self_vi` and `__arg_1_vi` are unused for
1147+
/// (Of course `__self_vi` and `arg_1_vi` are unused for
11481148
/// `PartialEq`, and those subcomputations will hopefully be removed
11491149
/// as their results are unused. The point of `__self_vi` and
1150-
/// `__arg_1_vi` is for `PartialOrd`; see #15503.)
1150+
/// `arg_1_vi` is for `PartialOrd`; see #15503.)
11511151
fn expand_enum_method_body<'b>(&self,
11521152
cx: &mut ExtCtxt,
11531153
trait_: &TraitDef<'b>,
@@ -1220,7 +1220,7 @@ impl<'a> MethodDef<'a> {
12201220
if arg_count == 0 {
12211221
"__self".to_string()
12221222
} else {
1223-
format!("__arg_{}", arg_count)
1223+
format!("arg_{}", arg_count)
12241224
}
12251225
})
12261226
.collect::<Vec<String>>();
@@ -1442,7 +1442,7 @@ impl<'a> MethodDef<'a> {
14421442
// down to desired places, but we cannot actually deref
14431443
// them when they are fed as r-values into a tuple
14441444
// expression; here add a layer of borrowing, turning
1445-
// `(*self, *__arg_0, ...)` into `(&*self, &*__arg_0, ...)`.
1445+
// `(*self, *arg_0, ...)` into `(&*self, &*arg_0, ...)`.
14461446
let borrowed_self_args = self_args.move_map(|self_arg| cx.expr_addr_of(sp, self_arg));
14471447
let match_arg = cx.expr(sp, ast::ExprKind::Tup(borrowed_self_args));
14481448

@@ -1481,7 +1481,7 @@ impl<'a> MethodDef<'a> {
14811481
// generate code like this:
14821482
//
14831483
// _ => { let __self0 = match *self { };
1484-
// let __self1 = match *__arg_0 { };
1484+
// let __self1 = match *arg_0 { };
14851485
// <catch-all-expr> }
14861486
//
14871487
// Which is yields bindings for variables which type
@@ -1519,7 +1519,7 @@ impl<'a> MethodDef<'a> {
15191519
// down to desired places, but we cannot actually deref
15201520
// them when they are fed as r-values into a tuple
15211521
// expression; here add a layer of borrowing, turning
1522-
// `(*self, *__arg_0, ...)` into `(&*self, &*__arg_0, ...)`.
1522+
// `(*self, *arg_0, ...)` into `(&*self, &*arg_0, ...)`.
15231523
let borrowed_self_args = self_args.move_map(|self_arg| cx.expr_addr_of(sp, self_arg));
15241524
let match_arg = cx.expr(sp, ast::ExprKind::Tup(borrowed_self_args));
15251525
cx.expr_match(sp, match_arg, match_arms)
@@ -1720,8 +1720,8 @@ pub fn cs_fold<F>(use_foldl: bool,
17201720
/// process the collected results. i.e.
17211721
///
17221722
/// ```ignore (only-for-syntax-highlight)
1723-
/// f(cx, span, vec![self_1.method(__arg_1_1, __arg_2_1),
1724-
/// self_2.method(__arg_1_2, __arg_2_2)])
1723+
/// f(cx, span, vec![self_1.method(arg_1_1, arg_2_1),
1724+
/// self_2.method(arg_1_2, arg_2_2)])
17251725
/// ```
17261726
#[inline]
17271727
pub fn cs_same_method<F>(f: F,

src/libsyntax_ext/format.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ impl<'a, 'b> Context<'a, 'b> {
560560
// of each variable because we don't want to move out of the arguments
561561
// passed to this function.
562562
for (i, e) in self.args.into_iter().enumerate() {
563-
let name = self.ecx.ident_of(&format!("__arg{}", i));
563+
let name = self.ecx.ident_of(&format!("arg{}", i));
564564
let span =
565565
DUMMY_SP.with_ctxt(e.span.ctxt().apply_mark(self.ecx.current_expansion.mark));
566566
pats.push(self.ecx.pat_ident(span, name));
@@ -571,7 +571,7 @@ impl<'a, 'b> Context<'a, 'b> {
571571
}
572572
for pos in self.count_args {
573573
let name = self.ecx.ident_of(&match pos {
574-
Exact(i) => format!("__arg{}", i),
574+
Exact(i) => format!("arg{}", i),
575575
_ => panic!("should never happen"),
576576
});
577577
let span = match pos {

0 commit comments

Comments
 (0)