Skip to content

Commit fd4fa62

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 4982f91 commit fd4fa62

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
@@ -826,7 +826,7 @@ impl<'a> MethodDef<'a> {
826826

827827
for (i, ty) in self.args.iter().enumerate() {
828828
let ast_ty = ty.to_ty(cx, trait_.span, type_ident, generics);
829-
let ident = cx.ident_of(&format!("__arg_{}", i));
829+
let ident = cx.ident_of(&format!("arg_{}", i));
830830
arg_tys.push((ident, ast_ty));
831831

832832
let arg_expr = cx.expr_ident(trait_.span, ident);
@@ -911,12 +911,12 @@ impl<'a> MethodDef<'a> {
911911
///
912912
/// // equivalent to:
913913
/// impl PartialEq for A {
914-
/// fn eq(&self, __arg_1: &A) -> bool {
914+
/// fn eq(&self, arg_1: &A) -> bool {
915915
/// match *self {
916-
/// A {x: ref __self_0_0, y: ref __self_0_1} => {
917-
/// match *__arg_1 {
918-
/// A {x: ref __self_1_0, y: ref __self_1_1} => {
919-
/// __self_0_0.eq(__self_1_0) && __self_0_1.eq(__self_1_1)
916+
/// A {x: ref self_0_0, y: ref self_0_1} => {
917+
/// match *arg_1 {
918+
/// A {x: ref self_1_0, y: ref self_1_1} => {
919+
/// self_0_0.eq(self_1_0) && self_0_1.eq(self_1_1)
920920
/// }
921921
/// }
922922
/// }
@@ -942,7 +942,7 @@ impl<'a> MethodDef<'a> {
942942
trait_.create_struct_pattern(cx,
943943
struct_path,
944944
struct_def,
945-
&format!("__self_{}",
945+
&format!("self_{}",
946946
i),
947947
ast::Mutability::Immutable);
948948
patterns.push(pat);
@@ -1020,25 +1020,25 @@ impl<'a> MethodDef<'a> {
10201020
/// // is equivalent to
10211021
///
10221022
/// impl PartialEq for A {
1023-
/// fn eq(&self, __arg_1: &A) -> ::bool {
1024-
/// match (&*self, &*__arg_1) {
1023+
/// fn eq(&self, arg_1: &A) -> ::bool {
1024+
/// match (&*self, &*arg_1) {
10251025
/// (&A1, &A1) => true,
1026-
/// (&A2(ref __self_0),
1027-
/// &A2(ref __arg_1_0)) => (*__self_0).eq(&(*__arg_1_0)),
1026+
/// (&A2(ref self_0),
1027+
/// &A2(ref arg_1_0)) => (*self_0).eq(&(*arg_1_0)),
10281028
/// _ => {
1029-
/// let __self_vi = match *self { A1(..) => 0, A2(..) => 1 };
1030-
/// let __arg_1_vi = match *__arg_1 { A1(..) => 0, A2(..) => 1 };
1029+
/// let self_vi = match *self { A1(..) => 0, A2(..) => 1 };
1030+
/// let arg_1_vi = match *arg_1 { A1(..) => 0, A2(..) => 1 };
10311031
/// false
10321032
/// }
10331033
/// }
10341034
/// }
10351035
/// }
10361036
/// ```
10371037
///
1038-
/// (Of course `__self_vi` and `__arg_1_vi` are unused for
1038+
/// (Of course `self_vi` and `arg_1_vi` are unused for
10391039
/// `PartialEq`, and those subcomputations will hopefully be removed
1040-
/// as their results are unused. The point of `__self_vi` and
1041-
/// `__arg_1_vi` is for `PartialOrd`; see #15503.)
1040+
/// as their results are unused. The point of `self_vi` and
1041+
/// `arg_1_vi` is for `PartialOrd`; see #15503.)
10421042
fn expand_enum_method_body<'b>(&self,
10431043
cx: &mut ExtCtxt,
10441044
trait_: &TraitDef<'b>,
@@ -1069,14 +1069,14 @@ impl<'a> MethodDef<'a> {
10691069
/// for each of the self-args, carried in precomputed variables.
10701070
10711071
/// ```{.text}
1072-
/// let __self0_vi = unsafe {
1072+
/// let self0_vi = unsafe {
10731073
/// std::intrinsics::discriminant_value(&self) } as i32;
1074-
/// let __self1_vi = unsafe {
1075-
/// std::intrinsics::discriminant_value(&__arg1) } as i32;
1076-
/// let __self2_vi = unsafe {
1077-
/// std::intrinsics::discriminant_value(&__arg2) } as i32;
1074+
/// let self1_vi = unsafe {
1075+
/// std::intrinsics::discriminant_value(&arg1) } as i32;
1076+
/// let self2_vi = unsafe {
1077+
/// std::intrinsics::discriminant_value(&arg2) } as i32;
10781078
///
1079-
/// if __self0_vi == __self1_vi && __self0_vi == __self2_vi && ... {
1079+
/// if self0_vi == self1_vi && self0_vi == self2_vi && ... {
10801080
/// match (...) {
10811081
/// (Variant1, Variant1, ...) => Body1
10821082
/// (Variant2, Variant2, ...) => Body2,
@@ -1104,9 +1104,9 @@ impl<'a> MethodDef<'a> {
11041104
let self_arg_names = self_args.iter().enumerate()
11051105
.map(|(arg_count, _self_arg)| {
11061106
if arg_count == 0 {
1107-
"__self".to_string()
1107+
"self".to_string()
11081108
} else {
1109-
format!("__arg_{}", arg_count)
1109+
format!("arg_{}", arg_count)
11101110
}
11111111
})
11121112
.collect::<Vec<String>>();
@@ -1243,17 +1243,17 @@ impl<'a> MethodDef<'a> {
12431243
// with three Self args, builds three statements:
12441244
//
12451245
// ```
1246-
// let __self0_vi = unsafe {
1246+
// let self0_vi = unsafe {
12471247
// std::intrinsics::discriminant_value(&self) } as i32;
1248-
// let __self1_vi = unsafe {
1249-
// std::intrinsics::discriminant_value(&__arg1) } as i32;
1250-
// let __self2_vi = unsafe {
1251-
// std::intrinsics::discriminant_value(&__arg2) } as i32;
1248+
// let self1_vi = unsafe {
1249+
// std::intrinsics::discriminant_value(&arg1) } as i32;
1250+
// let self2_vi = unsafe {
1251+
// std::intrinsics::discriminant_value(&arg2) } as i32;
12521252
// ```
12531253
let mut index_let_stmts: Vec<ast::Stmt> = Vec::new();
12541254

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

12591259
let target_type_name =
@@ -1312,7 +1312,7 @@ impl<'a> MethodDef<'a> {
13121312
// down to desired l-values, but we cannot actually deref
13131313
// them when they are fed as r-values into a tuple
13141314
// expression; here add a layer of borrowing, turning
1315-
// `(*self, *__arg_0, ...)` into `(&*self, &*__arg_0, ...)`.
1315+
// `(*self, *arg_0, ...)` into `(&*self, &*arg_0, ...)`.
13161316
let borrowed_self_args = self_args.move_map(|self_arg| cx.expr_addr_of(sp, self_arg));
13171317
let match_arg = cx.expr(sp, ast::ExprKind::Tup(borrowed_self_args));
13181318

@@ -1326,7 +1326,7 @@ impl<'a> MethodDef<'a> {
13261326
// }
13271327
// }
13281328
// else {
1329-
// <delegated expression referring to __self0_vi, et al.>
1329+
// <delegated expression referring to self0_vi, et al.>
13301330
// }
13311331
let all_match = cx.expr_match(sp, match_arg, match_arms);
13321332
let arm_expr = cx.expr_if(sp, discriminant_test, all_match, Some(arm_expr));
@@ -1350,8 +1350,8 @@ impl<'a> MethodDef<'a> {
13501350
// error-prone, since the catch-all as defined above would
13511351
// generate code like this:
13521352
//
1353-
// _ => { let __self0 = match *self { };
1354-
// let __self1 = match *__arg_0 { };
1353+
// _ => { let self0 = match *self { };
1354+
// let self1 = match *arg_0 { };
13551355
// <catch-all-expr> }
13561356
//
13571357
// Which is yields bindings for variables which type
@@ -1390,7 +1390,7 @@ impl<'a> MethodDef<'a> {
13901390
// down to desired l-values, but we cannot actually deref
13911391
// them when they are fed as r-values into a tuple
13921392
// expression; here add a layer of borrowing, turning
1393-
// `(*self, *__arg_0, ...)` into `(&*self, &*__arg_0, ...)`.
1393+
// `(*self, *arg_0, ...)` into `(&*self, &*arg_0, ...)`.
13941394
let borrowed_self_args = self_args.move_map(|self_arg| cx.expr_addr_of(sp, self_arg));
13951395
let match_arg = cx.expr(sp, ast::ExprKind::Tup(borrowed_self_args));
13961396
cx.expr_match(sp, match_arg, match_arms)
@@ -1604,8 +1604,8 @@ pub fn cs_fold<F>(use_foldl: bool,
16041604
/// process the collected results. i.e.
16051605
///
16061606
/// ```ignore
1607-
/// f(cx, span, vec![self_1.method(__arg_1_1, __arg_2_1),
1608-
/// self_2.method(__arg_1_2, __arg_2_2)])
1607+
/// f(cx, span, vec![self_1.method(arg_1_1, arg_2_1),
1608+
/// self_2.method(arg_1_2, arg_2_2)])
16091609
/// ```
16101610
#[inline]
16111611
pub fn cs_same_method<F>(f: F,

0 commit comments

Comments
 (0)