Skip to content

Commit 4ae9488

Browse files
committed
Provide better names for builtin deriving-generated attributes
1 parent 21dae95 commit 4ae9488

File tree

10 files changed

+19
-15
lines changed

10 files changed

+19
-15
lines changed

src/libsyntax_ext/deriving/cmp/ord.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub fn expand_deriving_ord(cx: &mut ExtCtxt,
3838
name: "cmp",
3939
generics: LifetimeBounds::empty(),
4040
explicit_self: borrowed_explicit_self(),
41-
args: vec![borrowed_self()],
41+
args: vec![(borrowed_self(), "other")],
4242
ret_ty: Literal(path_std!(cx, cmp::Ordering)),
4343
attributes: attrs,
4444
is_unsafe: false,

src/libsyntax_ext/deriving/cmp/partial_eq.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ pub fn expand_deriving_partial_eq(cx: &mut ExtCtxt,
7171
name: $name,
7272
generics: LifetimeBounds::empty(),
7373
explicit_self: borrowed_explicit_self(),
74-
args: vec![borrowed_self()],
74+
args: vec![(borrowed_self(), "_other")],
7575
ret_ty: Literal(path_local!(bool)),
7676
attributes: attrs,
7777
is_unsafe: false,

src/libsyntax_ext/deriving/cmp/partial_ord.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub fn expand_deriving_partial_ord(cx: &mut ExtCtxt,
3434
name: $name,
3535
generics: LifetimeBounds::empty(),
3636
explicit_self: borrowed_explicit_self(),
37-
args: vec![borrowed_self()],
37+
args: vec![(borrowed_self(), "other")],
3838
ret_ty: Literal(path_local!(bool)),
3939
attributes: attrs,
4040
is_unsafe: false,
@@ -59,7 +59,7 @@ pub fn expand_deriving_partial_ord(cx: &mut ExtCtxt,
5959
name: "partial_cmp",
6060
generics: LifetimeBounds::empty(),
6161
explicit_self: borrowed_explicit_self(),
62-
args: vec![borrowed_self()],
62+
args: vec![(borrowed_self(), "other")],
6363
ret_ty,
6464
attributes: attrs,
6565
is_unsafe: false,

src/libsyntax_ext/deriving/debug.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub fn expand_deriving_debug(cx: &mut ExtCtxt,
4040
name: "fmt",
4141
generics: LifetimeBounds::empty(),
4242
explicit_self: borrowed_explicit_self(),
43-
args: vec![fmtr],
43+
args: vec![(fmtr, "_f")],
4444
ret_ty: Literal(path_std!(cx, fmt::Result)),
4545
attributes: Vec::new(),
4646
is_unsafe: false,

src/libsyntax_ext/deriving/decodable.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ fn expand_deriving_decodable_imp(cx: &mut ExtCtxt,
6767
PathKind::Global)])],
6868
},
6969
explicit_self: None,
70-
args: vec![Ptr(Box::new(Literal(Path::new_local(typaram))),
71-
Borrowed(None, Mutability::Mutable))],
70+
args: vec![(Ptr(Box::new(Literal(Path::new_local(typaram))),
71+
Borrowed(None, Mutability::Mutable)), "d")],
7272
ret_ty:
7373
Literal(Path::new_(pathvec_std!(cx, result::Result),
7474
None,

src/libsyntax_ext/deriving/encodable.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ fn expand_deriving_encodable_imp(cx: &mut ExtCtxt,
148148
],
149149
},
150150
explicit_self: borrowed_explicit_self(),
151-
args: vec![Ptr(Box::new(Literal(Path::new_local(typaram))),
152-
Borrowed(None, Mutability::Mutable))],
151+
args: vec![(Ptr(Box::new(Literal(Path::new_local(typaram))),
152+
Borrowed(None, Mutability::Mutable)), "s")],
153153
ret_ty: Literal(Path::new_(
154154
pathvec_std!(cx, result::Result),
155155
None,

src/libsyntax_ext/deriving/generic/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ pub struct MethodDef<'a> {
252252
pub explicit_self: Option<Option<PtrTy<'a>>>,
253253

254254
/// Arguments other than the self argument
255-
pub args: Vec<Ty<'a>>,
255+
pub args: Vec<(Ty<'a>, &'a str)>,
256256

257257
/// Return type
258258
pub ret_ty: Ty<'a>,
@@ -915,9 +915,9 @@ impl<'a> MethodDef<'a> {
915915
explicit_self
916916
});
917917

918-
for (i, ty) in self.args.iter().enumerate() {
918+
for (ty, name) in self.args.iter() {
919919
let ast_ty = ty.to_ty(cx, trait_.span, type_ident, generics);
920-
let ident = cx.ident_of(&format!("__arg_{}", i));
920+
let ident = cx.ident_of(name).gensym();
921921
arg_tys.push((ident, ast_ty));
922922

923923
let arg_expr = cx.expr_ident(trait_.span, ident);

src/libsyntax_ext/deriving/hash.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ pub fn expand_deriving_hash(cx: &mut ExtCtxt,
4444
bounds: vec![(typaram, vec![path_std!(cx, hash::Hasher)])],
4545
},
4646
explicit_self: borrowed_explicit_self(),
47-
args: vec![Ptr(Box::new(Literal(arg)),
48-
Borrowed(None, Mutability::Mutable))],
47+
args: vec![(Ptr(Box::new(Literal(arg)),
48+
Borrowed(None, Mutability::Mutable)), "_state")],
4949
ret_ty: nil_ty(),
5050
attributes: vec![],
5151
is_unsafe: false,

src/libsyntax_pos/symbol.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ impl Ident {
5353
pub fn modern(self) -> Ident {
5454
Ident::new(self.name, self.span.modern())
5555
}
56+
57+
pub fn gensym(self) -> Ident {
58+
Ident::new(self.name.gensymed(), self.span)
59+
}
5660
}
5761

5862
impl PartialEq for Ident {

src/test/run-pass-fulldeps/auxiliary/custom_derive_partial_eq.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ fn expand_deriving_partial_eq(cx: &mut ExtCtxt, span: Span, mitem: &MetaItem, it
5858
name: "eq",
5959
generics: LifetimeBounds::empty(),
6060
explicit_self: borrowed_explicit_self(),
61-
args: vec![borrowed_self()],
61+
args: vec![(borrowed_self(), "other")],
6262
ret_ty: Literal(deriving::generic::ty::Path::new_local("bool")),
6363
attributes: attrs,
6464
is_unsafe: false,

0 commit comments

Comments
 (0)