Skip to content

Commit b12b4e4

Browse files
committed
Auto merge of #32294 - Manishearth:derive-fix, r=alexcrichton
Re-add double underscores in derive (fixes #32292) @durka, sanity-check, please? <s>Don't merge this yet, I need to add a test and test it locally.</s> ready for review
2 parents be989ac + 52e064c commit b12b4e4

File tree

4 files changed

+61
-43
lines changed

4 files changed

+61
-43
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("cmp");
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-
cmp => cmp
82+
__cmp => __cmp
8383
},
84-
cmp => cmp
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-
// cmp => cmp
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("cmp");
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-
cmp => cmp
127+
__cmp => __cmp
128128
},
129-
cmp => cmp
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-
// cmp => cmp
139+
// __cmp => __cmp
140140
// }
141141

142142
let new = {

src/libsyntax_ext/deriving/generic/mod.rs

+35-35
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
@@ -843,7 +843,7 @@ impl<'a> MethodDef<'a> {
843843

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

849849
let arg_expr = cx.expr_ident(trait_.span, ident);
@@ -929,12 +929,12 @@ impl<'a> MethodDef<'a> {
929929
///
930930
/// // equivalent to:
931931
/// impl PartialEq for A {
932-
/// fn eq(&self, arg_1: &A) -> bool {
932+
/// fn eq(&self, __arg_1: &A) -> bool {
933933
/// match *self {
934-
/// A {x: ref self_0_0, y: ref self_0_1} => {
935-
/// match *arg_1 {
936-
/// A {x: ref self_1_0, y: ref self_1_1} => {
937-
/// self_0_0.eq(self_1_0) && self_0_1.eq(self_1_1)
934+
/// A {x: ref __self_0_0, y: ref __self_0_1} => {
935+
/// match *__arg_1 {
936+
/// A {x: ref __self_1_0, y: ref __self_1_1} => {
937+
/// __self_0_0.eq(__self_1_0) && __self_0_1.eq(__self_1_1)
938938
/// }
939939
/// }
940940
/// }
@@ -960,7 +960,7 @@ impl<'a> MethodDef<'a> {
960960
trait_.create_struct_pattern(cx,
961961
struct_path,
962962
struct_def,
963-
&format!("self_{}",
963+
&format!("__self_{}",
964964
i),
965965
ast::Mutability::Immutable);
966966
patterns.push(pat);
@@ -1038,25 +1038,25 @@ impl<'a> MethodDef<'a> {
10381038
/// // is equivalent to
10391039
///
10401040
/// impl PartialEq for A {
1041-
/// fn eq(&self, arg_1: &A) -> ::bool {
1042-
/// match (&*self, &*arg_1) {
1041+
/// fn eq(&self, __arg_1: &A) -> ::bool {
1042+
/// match (&*self, &*__arg_1) {
10431043
/// (&A1, &A1) => true,
10441044
/// (&A2(ref self_0),
1045-
/// &A2(ref arg_1_0)) => (*self_0).eq(&(*arg_1_0)),
1045+
/// &A2(ref __arg_1_0)) => (*self_0).eq(&(*__arg_1_0)),
10461046
/// _ => {
1047-
/// let self_vi = match *self { A1(..) => 0, A2(..) => 1 };
1048-
/// let arg_1_vi = match *arg_1 { A1(..) => 0, A2(..) => 1 };
1047+
/// let __self_vi = match *self { A1(..) => 0, A2(..) => 1 };
1048+
/// let __arg_1_vi = match *__arg_1 { A1(..) => 0, A2(..) => 1 };
10491049
/// false
10501050
/// }
10511051
/// }
10521052
/// }
10531053
/// }
10541054
/// ```
10551055
///
1056-
/// (Of course `self_vi` and `arg_1_vi` are unused for
1056+
/// (Of course `__self_vi` and `__arg_1_vi` are unused for
10571057
/// `PartialEq`, and those subcomputations will hopefully be removed
1058-
/// as their results are unused. The point of `self_vi` and
1059-
/// `arg_1_vi` is for `PartialOrd`; see #15503.)
1058+
/// as their results are unused. The point of `__self_vi` and
1059+
/// `__arg_1_vi` is for `PartialOrd`; see #15503.)
10601060
fn expand_enum_method_body<'b>(&self,
10611061
cx: &mut ExtCtxt,
10621062
trait_: &TraitDef<'b>,
@@ -1087,14 +1087,14 @@ impl<'a> MethodDef<'a> {
10871087
/// for each of the self-args, carried in precomputed variables.
10881088
10891089
/// ```{.text}
1090-
/// let self0_vi = unsafe {
1090+
/// let __self0_vi = unsafe {
10911091
/// std::intrinsics::discriminant_value(&self) } as i32;
1092-
/// let self1_vi = unsafe {
1092+
/// let __self1_vi = unsafe {
10931093
/// std::intrinsics::discriminant_value(&arg1) } as i32;
1094-
/// let self2_vi = unsafe {
1094+
/// let __self2_vi = unsafe {
10951095
/// std::intrinsics::discriminant_value(&arg2) } as i32;
10961096
///
1097-
/// if self0_vi == self1_vi && self0_vi == self2_vi && ... {
1097+
/// if __self0_vi == __self1_vi && __self0_vi == __self2_vi && ... {
10981098
/// match (...) {
10991099
/// (Variant1, Variant1, ...) => Body1
11001100
/// (Variant2, Variant2, ...) => Body2,
@@ -1122,9 +1122,9 @@ impl<'a> MethodDef<'a> {
11221122
let self_arg_names = self_args.iter().enumerate()
11231123
.map(|(arg_count, _self_arg)| {
11241124
if arg_count == 0 {
1125-
"self".to_string()
1125+
"__self".to_string()
11261126
} else {
1127-
format!("arg_{}", arg_count)
1127+
format!("__arg_{}", arg_count)
11281128
}
11291129
})
11301130
.collect::<Vec<String>>();
@@ -1261,17 +1261,17 @@ impl<'a> MethodDef<'a> {
12611261
// with three Self args, builds three statements:
12621262
//
12631263
// ```
1264-
// let self0_vi = unsafe {
1264+
// let __self0_vi = unsafe {
12651265
// std::intrinsics::discriminant_value(&self) } as i32;
1266-
// let self1_vi = unsafe {
1266+
// let __self1_vi = unsafe {
12671267
// std::intrinsics::discriminant_value(&arg1) } as i32;
1268-
// let self2_vi = unsafe {
1268+
// let __self2_vi = unsafe {
12691269
// std::intrinsics::discriminant_value(&arg2) } as i32;
12701270
// ```
12711271
let mut index_let_stmts: Vec<ast::Stmt> = Vec::new();
12721272

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

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

@@ -1335,7 +1335,7 @@ impl<'a> MethodDef<'a> {
13351335
// }
13361336
// }
13371337
// else {
1338-
// <delegated expression referring to self0_vi, et al.>
1338+
// <delegated expression referring to __self0_vi, et al.>
13391339
// }
13401340
let all_match = cx.expr_match(sp, match_arg, match_arms);
13411341
let arm_expr = cx.expr_if(sp, discriminant_test, all_match, Some(arm_expr));
@@ -1359,8 +1359,8 @@ impl<'a> MethodDef<'a> {
13591359
// error-prone, since the catch-all as defined above would
13601360
// generate code like this:
13611361
//
1362-
// _ => { let self0 = match *self { };
1363-
// let self1 = match *arg_0 { };
1362+
// _ => { let __self0 = match *self { };
1363+
// let __self1 = match *__arg_0 { };
13641364
// <catch-all-expr> }
13651365
//
13661366
// Which is yields bindings for variables which type
@@ -1399,7 +1399,7 @@ impl<'a> MethodDef<'a> {
13991399
// down to desired l-values, but we cannot actually deref
14001400
// them when they are fed as r-values into a tuple
14011401
// expression; here add a layer of borrowing, turning
1402-
// `(*self, *arg_0, ...)` into `(&*self, &*arg_0, ...)`.
1402+
// `(*self, *__arg_0, ...)` into `(&*self, &*__arg_0, ...)`.
14031403
let borrowed_self_args = self_args.move_map(|self_arg| cx.expr_addr_of(sp, self_arg));
14041404
let match_arg = cx.expr(sp, ast::ExprKind::Tup(borrowed_self_args));
14051405
cx.expr_match(sp, match_arg, match_arms)
@@ -1613,8 +1613,8 @@ pub fn cs_fold<F>(use_foldl: bool,
16131613
/// process the collected results. i.e.
16141614
///
16151615
/// ```ignore
1616-
/// f(cx, span, vec![self_1.method(arg_1_1, arg_2_1),
1617-
/// self_2.method(arg_1_2, arg_2_2)])
1616+
/// f(cx, span, vec![self_1.method(__arg_1_1, __arg_2_1),
1617+
/// self_2.method(__arg_1_2, __arg_2_2)])
16181618
/// ```
16191619
#[inline]
16201620
pub fn cs_same_method<F>(f: F,

src/test/run-pass/issue-32292.rs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![deny(warnings)]
12+
13+
#[derive(Hash, Ord, PartialOrd, Eq, PartialEq, Debug, Clone, Copy)]
14+
struct Foo;
15+
16+
fn main() {
17+
let _ = Foo;
18+
}

0 commit comments

Comments
 (0)