]> git.lizzy.rs Git - rust.git/commitdiff
derive: remove most __ strings FIXME(#2810)
authorAlex Burka <aburka@seas.upenn.edu>
Tue, 8 Mar 2016 00:07:06 +0000 (19:07 -0500)
committerAlex Burka <aburka@seas.upenn.edu>
Mon, 14 Mar 2016 20:49:18 +0000 (16:49 -0400)
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.

src/libsyntax_ext/deriving/cmp/ord.rs
src/libsyntax_ext/deriving/cmp/partial_ord.rs
src/libsyntax_ext/deriving/generic/mod.rs

index f4082e0b123bf7b0ac3ee7acebb305055a663c82..a69d57423a22cf296687e1981afa286abd48ccbf 100644 (file)
@@ -64,7 +64,7 @@ pub fn ordering_collapsed(cx: &mut ExtCtxt,
 
 pub fn cs_cmp(cx: &mut ExtCtxt, span: Span,
               substr: &Substructure) -> P<Expr> {
-    let test_id = cx.ident_of("__test");
+    let test_id = cx.ident_of("cmp");
     let equals_path = cx.path_global(span,
                                      cx.std_path(&["cmp", "Ordering", "Equal"]));
 
@@ -79,9 +79,9 @@ pub fn cs_cmp(cx: &mut ExtCtxt, span: Span,
                 ::std::cmp::Ordering::Equal => {
                     ...
                 }
-                __test => __test
+                cmp => cmp
             },
-        __test => __test
+        cmp => cmp
     }
     */
     cs_fold(
@@ -91,7 +91,7 @@ pub fn cs_cmp(cx: &mut ExtCtxt, span: Span,
         |cx, span, old, self_f, other_fs| {
             // match new {
             //     ::std::cmp::Ordering::Equal => old,
-            //     __test => __test
+            //     cmp => cmp
             // }
 
             let new = {
index 3353addebc971e748dd998c66329ff8416641f93..b3864a6c2e79e3e609a1b9ad5b553ee9cc0d810d 100644 (file)
@@ -107,7 +107,7 @@ pub fn some_ordering_collapsed(cx: &mut ExtCtxt,
 
 pub fn cs_partial_cmp(cx: &mut ExtCtxt, span: Span,
               substr: &Substructure) -> P<Expr> {
-    let test_id = cx.ident_of("__test");
+    let test_id = cx.ident_of("cmp");
     let ordering = cx.path_global(span,
                                   cx.std_path(&["cmp", "Ordering", "Equal"]));
     let ordering_expr = cx.expr_path(ordering.clone());
@@ -124,9 +124,9 @@ pub fn cs_partial_cmp(cx: &mut ExtCtxt, span: Span,
                 ::std::option::Option::Some(::std::cmp::Ordering::Equal) => {
                     ...
                 }
-                __test => __test
+                cmp => cmp
             },
-        __test => __test
+        cmp => cmp
     }
     */
     cs_fold(
@@ -136,7 +136,7 @@ pub fn cs_partial_cmp(cx: &mut ExtCtxt, span: Span,
         |cx, span, old, self_f, other_fs| {
             // match new {
             //     Some(::std::cmp::Ordering::Equal) => old,
-            //     __test => __test
+            //     cmp => cmp
             // }
 
             let new = {
index c0237a5d29a4103dbf8e535ba9800cc474929fca..f72fa98b482ab36bdf91fc6351a31d9056e73687 100644 (file)
 //!
 //! ```{.text}
 //! EnumNonMatchingCollapsed(
-//!     vec![<ident of self>, <ident of __arg_1>],
+//!     vec![<ident of self>, <ident of arg_1>],
 //!     &[<ast::Variant for C0>, <ast::Variant for C1>],
-//!     &[<ident for self index value>, <ident of __arg_1 index value>])
+//!     &[<ident for self index value>, <ident of arg_1 index value>])
 //! ```
 //!
 //! It is the same for when the arguments are flipped to `C1 {x}` and
 //! `C0(a)`; the only difference is what the values of the identifiers
-//! <ident for self index value> and <ident of __arg_1 index value> will
+//! <ident for self index value> and <ident of arg_1 index value> will
 //! be in the generated code.
 //!
 //! `EnumNonMatchingCollapsed` deliberately provides far less information
@@ -826,7 +826,7 @@ fn split_self_nonself_args(&self,
 
         for (i, ty) in self.args.iter().enumerate() {
             let ast_ty = ty.to_ty(cx, trait_.span, type_ident, generics);
-            let ident = cx.ident_of(&format!("__arg_{}", i));
+            let ident = cx.ident_of(&format!("arg_{}", i));
             arg_tys.push((ident, ast_ty));
 
             let arg_expr = cx.expr_ident(trait_.span, ident);
@@ -911,12 +911,12 @@ fn create_method(&self,
     ///
     /// // equivalent to:
     /// impl PartialEq for A {
-    ///     fn eq(&self, __arg_1: &A) -> bool {
+    ///     fn eq(&self, arg_1: &A) -> bool {
     ///         match *self {
-    ///             A {x: ref __self_0_0, y: ref __self_0_1} => {
-    ///                 match *__arg_1 {
-    ///                     A {x: ref __self_1_0, y: ref __self_1_1} => {
-    ///                         __self_0_0.eq(__self_1_0) && __self_0_1.eq(__self_1_1)
+    ///             A {x: ref self_0_0, y: ref self_0_1} => {
+    ///                 match *arg_1 {
+    ///                     A {x: ref self_1_0, y: ref self_1_1} => {
+    ///                         self_0_0.eq(self_1_0) && self_0_1.eq(self_1_1)
     ///                     }
     ///                 }
     ///             }
@@ -942,7 +942,7 @@ fn expand_struct_method_body<'b>(&self,
                 trait_.create_struct_pattern(cx,
                                              struct_path,
                                              struct_def,
-                                             &format!("__self_{}",
+                                             &format!("self_{}",
                                                      i),
                                              ast::Mutability::Immutable);
             patterns.push(pat);
@@ -1020,14 +1020,14 @@ fn expand_static_struct_method_body(&self,
     /// // is equivalent to
     ///
     /// impl PartialEq for A {
-    ///     fn eq(&self, __arg_1: &A) -> ::bool {
-    ///         match (&*self, &*__arg_1) {
+    ///     fn eq(&self, arg_1: &A) -> ::bool {
+    ///         match (&*self, &*arg_1) {
     ///             (&A1, &A1) => true,
-    ///             (&A2(ref __self_0),
-    ///              &A2(ref __arg_1_0)) => (*__self_0).eq(&(*__arg_1_0)),
+    ///             (&A2(ref self_0),
+    ///              &A2(ref arg_1_0)) => (*self_0).eq(&(*arg_1_0)),
     ///             _ => {
-    ///                 let __self_vi = match *self { A1(..) => 0, A2(..) => 1 };
-    ///                 let __arg_1_vi = match *__arg_1 { A1(..) => 0, A2(..) => 1 };
+    ///                 let self_vi = match *self { A1(..) => 0, A2(..) => 1 };
+    ///                 let arg_1_vi = match *arg_1 { A1(..) => 0, A2(..) => 1 };
     ///                 false
     ///             }
     ///         }
@@ -1035,10 +1035,10 @@ fn expand_static_struct_method_body(&self,
     /// }
     /// ```
     ///
-    /// (Of course `__self_vi` and `__arg_1_vi` are unused for
+    /// (Of course `self_vi` and `arg_1_vi` are unused for
     /// `PartialEq`, and those subcomputations will hopefully be removed
-    /// as their results are unused.  The point of `__self_vi` and
-    /// `__arg_1_vi` is for `PartialOrd`; see #15503.)
+    /// as their results are unused.  The point of `self_vi` and
+    /// `arg_1_vi` is for `PartialOrd`; see #15503.)
     fn expand_enum_method_body<'b>(&self,
                                cx: &mut ExtCtxt,
                                trait_: &TraitDef<'b>,
@@ -1069,14 +1069,14 @@ fn expand_enum_method_body<'b>(&self,
     /// for each of the self-args, carried in precomputed variables.
 
     /// ```{.text}
-    /// let __self0_vi = unsafe {
+    /// let self0_vi = unsafe {
     ///     std::intrinsics::discriminant_value(&self) } as i32;
-    /// let __self1_vi = unsafe {
-    ///     std::intrinsics::discriminant_value(&__arg1) } as i32;
-    /// let __self2_vi = unsafe {
-    ///     std::intrinsics::discriminant_value(&__arg2) } as i32;
+    /// let self1_vi = unsafe {
+    ///     std::intrinsics::discriminant_value(&arg1) } as i32;
+    /// let self2_vi = unsafe {
+    ///     std::intrinsics::discriminant_value(&arg2) } as i32;
     ///
-    /// if __self0_vi == __self1_vi && __self0_vi == __self2_vi && ... {
+    /// if self0_vi == self1_vi && self0_vi == self2_vi && ... {
     ///     match (...) {
     ///         (Variant1, Variant1, ...) => Body1
     ///         (Variant2, Variant2, ...) => Body2,
@@ -1104,9 +1104,9 @@ fn build_enum_match_tuple<'b>(
         let self_arg_names = self_args.iter().enumerate()
             .map(|(arg_count, _self_arg)| {
                 if arg_count == 0 {
-                    "__self".to_string()
+                    "self".to_string()
                 } else {
-                    format!("__arg_{}", arg_count)
+                    format!("arg_{}", arg_count)
                 }
             })
             .collect::<Vec<String>>();
@@ -1243,17 +1243,17 @@ fn build_enum_match_tuple<'b>(
             // with three Self args, builds three statements:
             //
             // ```
-            // let __self0_vi = unsafe {
+            // let self0_vi = unsafe {
             //     std::intrinsics::discriminant_value(&self) } as i32;
-            // let __self1_vi = unsafe {
-            //     std::intrinsics::discriminant_value(&__arg1) } as i32;
-            // let __self2_vi = unsafe {
-            //     std::intrinsics::discriminant_value(&__arg2) } as i32;
+            // let self1_vi = unsafe {
+            //     std::intrinsics::discriminant_value(&arg1) } as i32;
+            // let self2_vi = unsafe {
+            //     std::intrinsics::discriminant_value(&arg2) } as i32;
             // ```
             let mut index_let_stmts: Vec<ast::Stmt> = Vec::new();
 
             //We also build an expression which checks whether all discriminants are equal
-            // discriminant_test = __self0_vi == __self1_vi && __self0_vi == __self2_vi && ...
+            // discriminant_test = self0_vi == self1_vi && self0_vi == self2_vi && ...
             let mut discriminant_test = cx.expr_bool(sp, true);
 
             let target_type_name =
@@ -1312,7 +1312,7 @@ fn build_enum_match_tuple<'b>(
             // down to desired l-values, but we cannot actually deref
             // them when they are fed as r-values into a tuple
             // expression; here add a layer of borrowing, turning
-            // `(*self, *__arg_0, ...)` into `(&*self, &*__arg_0, ...)`.
+            // `(*self, *arg_0, ...)` into `(&*self, &*arg_0, ...)`.
             let borrowed_self_args = self_args.move_map(|self_arg| cx.expr_addr_of(sp, self_arg));
             let match_arg = cx.expr(sp, ast::ExprKind::Tup(borrowed_self_args));
 
@@ -1326,7 +1326,7 @@ fn build_enum_match_tuple<'b>(
             //      }
             //  }
             //  else {
-            //      <delegated expression referring to __self0_vi, et al.>
+            //      <delegated expression referring to self0_vi, et al.>
             //  }
             let all_match = cx.expr_match(sp, match_arg, match_arms);
             let arm_expr = cx.expr_if(sp, discriminant_test, all_match, Some(arm_expr));
@@ -1350,8 +1350,8 @@ fn build_enum_match_tuple<'b>(
             // error-prone, since the catch-all as defined above would
             // generate code like this:
             //
-            //     _ => { let __self0 = match *self { };
-            //            let __self1 = match *__arg_0 { };
+            //     _ => { let self0 = match *self { };
+            //            let self1 = match *arg_0 { };
             //            <catch-all-expr> }
             //
             // Which is yields bindings for variables which type
@@ -1390,7 +1390,7 @@ fn build_enum_match_tuple<'b>(
             // down to desired l-values, but we cannot actually deref
             // them when they are fed as r-values into a tuple
             // expression; here add a layer of borrowing, turning
-            // `(*self, *__arg_0, ...)` into `(&*self, &*__arg_0, ...)`.
+            // `(*self, *arg_0, ...)` into `(&*self, &*arg_0, ...)`.
             let borrowed_self_args = self_args.move_map(|self_arg| cx.expr_addr_of(sp, self_arg));
             let match_arg = cx.expr(sp, ast::ExprKind::Tup(borrowed_self_args));
             cx.expr_match(sp, match_arg, match_arms)
@@ -1604,8 +1604,8 @@ pub fn cs_fold<F>(use_foldl: bool,
 /// process the collected results. i.e.
 ///
 /// ```ignore
-/// f(cx, span, vec![self_1.method(__arg_1_1, __arg_2_1),
-///                  self_2.method(__arg_1_2, __arg_2_2)])
+/// f(cx, span, vec![self_1.method(arg_1_1, arg_2_1),
+///                  self_2.method(arg_1_2, arg_2_2)])
 /// ```
 #[inline]
 pub fn cs_same_method<F>(f: F,