Skip to content

Commit 3c19df6

Browse files
committed
derive: remove most __ strings FIXME(#2810)
This changes local variable names in all derives to remove leading double-underscores. As far as I can tell, this doesn't break anything because there is no user code in these generated functions except for struct, field and type parameter names, and this doesn't cause shadowing of those. But I am still a bit nervous.
1 parent 9f89853 commit 3c19df6

File tree

3 files changed

+48
-48
lines changed

3 files changed

+48
-48
lines changed

src/libsyntax_ext/deriving/cmp/ord.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ pub fn ordering_collapsed(cx: &mut ExtCtxt,
6464

6565
pub fn cs_cmp(cx: &mut ExtCtxt, span: Span,
6666
substr: &Substructure) -> P<Expr> {
67-
let test_id = cx.ident_of("__test");
67+
let test_id = cx.ident_of("cmp");
6868
let equals_path = cx.path_global(span,
6969
cx.std_path(&["cmp", "Ordering", "Equal"]));
7070

@@ -79,9 +79,9 @@ pub fn cs_cmp(cx: &mut ExtCtxt, span: Span,
7979
::std::cmp::Ordering::Equal => {
8080
...
8181
}
82-
__test => __test
82+
cmp => cmp
8383
},
84-
__test => __test
84+
cmp => cmp
8585
}
8686
*/
8787
cs_fold(
@@ -91,7 +91,7 @@ pub fn cs_cmp(cx: &mut ExtCtxt, span: Span,
9191
|cx, span, old, self_f, other_fs| {
9292
// match new {
9393
// ::std::cmp::Ordering::Equal => old,
94-
// __test => __test
94+
// cmp => cmp
9595
// }
9696

9797
let new = {

src/libsyntax_ext/deriving/cmp/partial_ord.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ pub fn some_ordering_collapsed(cx: &mut ExtCtxt,
107107

108108
pub fn cs_partial_cmp(cx: &mut ExtCtxt, span: Span,
109109
substr: &Substructure) -> P<Expr> {
110-
let test_id = cx.ident_of("__test");
110+
let test_id = cx.ident_of("cmp");
111111
let ordering = cx.path_global(span,
112112
cx.std_path(&["cmp", "Ordering", "Equal"]));
113113
let ordering_expr = cx.expr_path(ordering.clone());
@@ -124,9 +124,9 @@ pub fn cs_partial_cmp(cx: &mut ExtCtxt, span: Span,
124124
::std::option::Option::Some(::std::cmp::Ordering::Equal) => {
125125
...
126126
}
127-
__test => __test
127+
cmp => cmp
128128
},
129-
__test => __test
129+
cmp => cmp
130130
}
131131
*/
132132
cs_fold(
@@ -136,7 +136,7 @@ pub fn cs_partial_cmp(cx: &mut ExtCtxt, span: Span,
136136
|cx, span, old, self_f, other_fs| {
137137
// match new {
138138
// Some(::std::cmp::Ordering::Equal) => old,
139-
// __test => __test
139+
// cmp => cmp
140140
// }
141141

142142
let new = {

src/libsyntax_ext/deriving/generic/mod.rs

+40-40
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
@@ -842,7 +842,7 @@ impl<'a> MethodDef<'a> {
842842

843843
for (i, ty) in self.args.iter().enumerate() {
844844
let ast_ty = ty.to_ty(cx, trait_.span, type_ident, generics);
845-
let ident = cx.ident_of(&format!("__arg_{}", i));
845+
let ident = cx.ident_of(&format!("arg_{}", i));
846846
arg_tys.push((ident, ast_ty));
847847

848848
let arg_expr = cx.expr_ident(trait_.span, ident);
@@ -927,12 +927,12 @@ impl<'a> MethodDef<'a> {
927927
///
928928
/// // equivalent to:
929929
/// impl PartialEq for A {
930-
/// fn eq(&self, __arg_1: &A) -> bool {
930+
/// fn eq(&self, arg_1: &A) -> bool {
931931
/// match *self {
932-
/// A {x: ref __self_0_0, y: ref __self_0_1} => {
933-
/// match *__arg_1 {
934-
/// A {x: ref __self_1_0, y: ref __self_1_1} => {
935-
/// __self_0_0.eq(__self_1_0) && __self_0_1.eq(__self_1_1)
932+
/// A {x: ref self_0_0, y: ref self_0_1} => {
933+
/// match *arg_1 {
934+
/// A {x: ref self_1_0, y: ref self_1_1} => {
935+
/// self_0_0.eq(self_1_0) && self_0_1.eq(self_1_1)
936936
/// }
937937
/// }
938938
/// }
@@ -958,7 +958,7 @@ impl<'a> MethodDef<'a> {
958958
trait_.create_struct_pattern(cx,
959959
struct_path,
960960
struct_def,
961-
&format!("__self_{}",
961+
&format!("self_{}",
962962
i),
963963
ast::Mutability::Immutable);
964964
patterns.push(pat);
@@ -1036,25 +1036,25 @@ impl<'a> MethodDef<'a> {
10361036
/// // is equivalent to
10371037
///
10381038
/// impl PartialEq for A {
1039-
/// fn eq(&self, __arg_1: &A) -> ::bool {
1040-
/// match (&*self, &*__arg_1) {
1039+
/// fn eq(&self, arg_1: &A) -> ::bool {
1040+
/// match (&*self, &*arg_1) {
10411041
/// (&A1, &A1) => true,
1042-
/// (&A2(ref __self_0),
1043-
/// &A2(ref __arg_1_0)) => (*__self_0).eq(&(*__arg_1_0)),
1042+
/// (&A2(ref self_0),
1043+
/// &A2(ref arg_1_0)) => (*self_0).eq(&(*arg_1_0)),
10441044
/// _ => {
1045-
/// let __self_vi = match *self { A1(..) => 0, A2(..) => 1 };
1046-
/// let __arg_1_vi = match *__arg_1 { A1(..) => 0, A2(..) => 1 };
1045+
/// let self_vi = match *self { A1(..) => 0, A2(..) => 1 };
1046+
/// let arg_1_vi = match *arg_1 { A1(..) => 0, A2(..) => 1 };
10471047
/// false
10481048
/// }
10491049
/// }
10501050
/// }
10511051
/// }
10521052
/// ```
10531053
///
1054-
/// (Of course `__self_vi` and `__arg_1_vi` are unused for
1054+
/// (Of course `self_vi` and `arg_1_vi` are unused for
10551055
/// `PartialEq`, and those subcomputations will hopefully be removed
1056-
/// as their results are unused. The point of `__self_vi` and
1057-
/// `__arg_1_vi` is for `PartialOrd`; see #15503.)
1056+
/// as their results are unused. The point of `self_vi` and
1057+
/// `arg_1_vi` is for `PartialOrd`; see #15503.)
10581058
fn expand_enum_method_body<'b>(&self,
10591059
cx: &mut ExtCtxt,
10601060
trait_: &TraitDef<'b>,
@@ -1085,14 +1085,14 @@ impl<'a> MethodDef<'a> {
10851085
/// for each of the self-args, carried in precomputed variables.
10861086
10871087
/// ```{.text}
1088-
/// let __self0_vi = unsafe {
1088+
/// let self0_vi = unsafe {
10891089
/// std::intrinsics::discriminant_value(&self) } as i32;
1090-
/// let __self1_vi = unsafe {
1091-
/// std::intrinsics::discriminant_value(&__arg1) } as i32;
1092-
/// let __self2_vi = unsafe {
1093-
/// std::intrinsics::discriminant_value(&__arg2) } as i32;
1090+
/// let self1_vi = unsafe {
1091+
/// std::intrinsics::discriminant_value(&arg1) } as i32;
1092+
/// let self2_vi = unsafe {
1093+
/// std::intrinsics::discriminant_value(&arg2) } as i32;
10941094
///
1095-
/// if __self0_vi == __self1_vi && __self0_vi == __self2_vi && ... {
1095+
/// if self0_vi == self1_vi && self0_vi == self2_vi && ... {
10961096
/// match (...) {
10971097
/// (Variant1, Variant1, ...) => Body1
10981098
/// (Variant2, Variant2, ...) => Body2,
@@ -1120,9 +1120,9 @@ impl<'a> MethodDef<'a> {
11201120
let self_arg_names = self_args.iter().enumerate()
11211121
.map(|(arg_count, _self_arg)| {
11221122
if arg_count == 0 {
1123-
"__self".to_string()
1123+
"self".to_string()
11241124
} else {
1125-
format!("__arg_{}", arg_count)
1125+
format!("arg_{}", arg_count)
11261126
}
11271127
})
11281128
.collect::<Vec<String>>();
@@ -1259,17 +1259,17 @@ impl<'a> MethodDef<'a> {
12591259
// with three Self args, builds three statements:
12601260
//
12611261
// ```
1262-
// let __self0_vi = unsafe {
1262+
// let self0_vi = unsafe {
12631263
// std::intrinsics::discriminant_value(&self) } as i32;
1264-
// let __self1_vi = unsafe {
1265-
// std::intrinsics::discriminant_value(&__arg1) } as i32;
1266-
// let __self2_vi = unsafe {
1267-
// std::intrinsics::discriminant_value(&__arg2) } as i32;
1264+
// let self1_vi = unsafe {
1265+
// std::intrinsics::discriminant_value(&arg1) } as i32;
1266+
// let self2_vi = unsafe {
1267+
// std::intrinsics::discriminant_value(&arg2) } as i32;
12681268
// ```
12691269
let mut index_let_stmts: Vec<ast::Stmt> = Vec::new();
12701270

12711271
//We also build an expression which checks whether all discriminants are equal
1272-
// discriminant_test = __self0_vi == __self1_vi && __self0_vi == __self2_vi && ...
1272+
// discriminant_test = self0_vi == self1_vi && self0_vi == self2_vi && ...
12731273
let mut discriminant_test = cx.expr_bool(sp, true);
12741274

12751275
let target_type_name =
@@ -1319,7 +1319,7 @@ impl<'a> MethodDef<'a> {
13191319
// down to desired l-values, but we cannot actually deref
13201320
// them when they are fed as r-values into a tuple
13211321
// expression; here add a layer of borrowing, turning
1322-
// `(*self, *__arg_0, ...)` into `(&*self, &*__arg_0, ...)`.
1322+
// `(*self, *arg_0, ...)` into `(&*self, &*arg_0, ...)`.
13231323
let borrowed_self_args = self_args.move_map(|self_arg| cx.expr_addr_of(sp, self_arg));
13241324
let match_arg = cx.expr(sp, ast::ExprKind::Tup(borrowed_self_args));
13251325

@@ -1333,7 +1333,7 @@ impl<'a> MethodDef<'a> {
13331333
// }
13341334
// }
13351335
// else {
1336-
// <delegated expression referring to __self0_vi, et al.>
1336+
// <delegated expression referring to self0_vi, et al.>
13371337
// }
13381338
let all_match = cx.expr_match(sp, match_arg, match_arms);
13391339
let arm_expr = cx.expr_if(sp, discriminant_test, all_match, Some(arm_expr));
@@ -1357,8 +1357,8 @@ impl<'a> MethodDef<'a> {
13571357
// error-prone, since the catch-all as defined above would
13581358
// generate code like this:
13591359
//
1360-
// _ => { let __self0 = match *self { };
1361-
// let __self1 = match *__arg_0 { };
1360+
// _ => { let self0 = match *self { };
1361+
// let self1 = match *arg_0 { };
13621362
// <catch-all-expr> }
13631363
//
13641364
// Which is yields bindings for variables which type
@@ -1397,7 +1397,7 @@ impl<'a> MethodDef<'a> {
13971397
// down to desired l-values, but we cannot actually deref
13981398
// them when they are fed as r-values into a tuple
13991399
// expression; here add a layer of borrowing, turning
1400-
// `(*self, *__arg_0, ...)` into `(&*self, &*__arg_0, ...)`.
1400+
// `(*self, *arg_0, ...)` into `(&*self, &*arg_0, ...)`.
14011401
let borrowed_self_args = self_args.move_map(|self_arg| cx.expr_addr_of(sp, self_arg));
14021402
let match_arg = cx.expr(sp, ast::ExprKind::Tup(borrowed_self_args));
14031403
cx.expr_match(sp, match_arg, match_arms)
@@ -1611,8 +1611,8 @@ pub fn cs_fold<F>(use_foldl: bool,
16111611
/// process the collected results. i.e.
16121612
///
16131613
/// ```ignore
1614-
/// f(cx, span, vec![self_1.method(__arg_1_1, __arg_2_1),
1615-
/// self_2.method(__arg_1_2, __arg_2_2)])
1614+
/// f(cx, span, vec![self_1.method(arg_1_1, arg_2_1),
1615+
/// self_2.method(arg_1_2, arg_2_2)])
16161616
/// ```
16171617
#[inline]
16181618
pub fn cs_same_method<F>(f: F,

0 commit comments

Comments
 (0)