1
Fork 0

Provide better names for builtin deriving-generated attributes

This commit is contained in:
James Sanderson 2018-04-15 20:51:10 +01:00
parent 21dae950be
commit 4ae9488ce8
10 changed files with 19 additions and 15 deletions

View file

@ -38,7 +38,7 @@ pub fn expand_deriving_ord(cx: &mut ExtCtxt,
name: "cmp", name: "cmp",
generics: LifetimeBounds::empty(), generics: LifetimeBounds::empty(),
explicit_self: borrowed_explicit_self(), explicit_self: borrowed_explicit_self(),
args: vec![borrowed_self()], args: vec![(borrowed_self(), "other")],
ret_ty: Literal(path_std!(cx, cmp::Ordering)), ret_ty: Literal(path_std!(cx, cmp::Ordering)),
attributes: attrs, attributes: attrs,
is_unsafe: false, is_unsafe: false,

View file

@ -71,7 +71,7 @@ pub fn expand_deriving_partial_eq(cx: &mut ExtCtxt,
name: $name, name: $name,
generics: LifetimeBounds::empty(), generics: LifetimeBounds::empty(),
explicit_self: borrowed_explicit_self(), explicit_self: borrowed_explicit_self(),
args: vec![borrowed_self()], args: vec![(borrowed_self(), "_other")],
ret_ty: Literal(path_local!(bool)), ret_ty: Literal(path_local!(bool)),
attributes: attrs, attributes: attrs,
is_unsafe: false, is_unsafe: false,

View file

@ -34,7 +34,7 @@ pub fn expand_deriving_partial_ord(cx: &mut ExtCtxt,
name: $name, name: $name,
generics: LifetimeBounds::empty(), generics: LifetimeBounds::empty(),
explicit_self: borrowed_explicit_self(), explicit_self: borrowed_explicit_self(),
args: vec![borrowed_self()], args: vec![(borrowed_self(), "other")],
ret_ty: Literal(path_local!(bool)), ret_ty: Literal(path_local!(bool)),
attributes: attrs, attributes: attrs,
is_unsafe: false, is_unsafe: false,
@ -59,7 +59,7 @@ pub fn expand_deriving_partial_ord(cx: &mut ExtCtxt,
name: "partial_cmp", name: "partial_cmp",
generics: LifetimeBounds::empty(), generics: LifetimeBounds::empty(),
explicit_self: borrowed_explicit_self(), explicit_self: borrowed_explicit_self(),
args: vec![borrowed_self()], args: vec![(borrowed_self(), "other")],
ret_ty, ret_ty,
attributes: attrs, attributes: attrs,
is_unsafe: false, is_unsafe: false,

View file

@ -40,7 +40,7 @@ pub fn expand_deriving_debug(cx: &mut ExtCtxt,
name: "fmt", name: "fmt",
generics: LifetimeBounds::empty(), generics: LifetimeBounds::empty(),
explicit_self: borrowed_explicit_self(), explicit_self: borrowed_explicit_self(),
args: vec![fmtr], args: vec![(fmtr, "_f")],
ret_ty: Literal(path_std!(cx, fmt::Result)), ret_ty: Literal(path_std!(cx, fmt::Result)),
attributes: Vec::new(), attributes: Vec::new(),
is_unsafe: false, is_unsafe: false,

View file

@ -67,8 +67,8 @@ fn expand_deriving_decodable_imp(cx: &mut ExtCtxt,
PathKind::Global)])], PathKind::Global)])],
}, },
explicit_self: None, explicit_self: None,
args: vec![Ptr(Box::new(Literal(Path::new_local(typaram))), args: vec![(Ptr(Box::new(Literal(Path::new_local(typaram))),
Borrowed(None, Mutability::Mutable))], Borrowed(None, Mutability::Mutable)), "d")],
ret_ty: ret_ty:
Literal(Path::new_(pathvec_std!(cx, result::Result), Literal(Path::new_(pathvec_std!(cx, result::Result),
None, None,

View file

@ -148,8 +148,8 @@ fn expand_deriving_encodable_imp(cx: &mut ExtCtxt,
], ],
}, },
explicit_self: borrowed_explicit_self(), explicit_self: borrowed_explicit_self(),
args: vec![Ptr(Box::new(Literal(Path::new_local(typaram))), args: vec![(Ptr(Box::new(Literal(Path::new_local(typaram))),
Borrowed(None, Mutability::Mutable))], Borrowed(None, Mutability::Mutable)), "s")],
ret_ty: Literal(Path::new_( ret_ty: Literal(Path::new_(
pathvec_std!(cx, result::Result), pathvec_std!(cx, result::Result),
None, None,

View file

@ -252,7 +252,7 @@ pub struct MethodDef<'a> {
pub explicit_self: Option<Option<PtrTy<'a>>>, pub explicit_self: Option<Option<PtrTy<'a>>>,
/// Arguments other than the self argument /// Arguments other than the self argument
pub args: Vec<Ty<'a>>, pub args: Vec<(Ty<'a>, &'a str)>,
/// Return type /// Return type
pub ret_ty: Ty<'a>, pub ret_ty: Ty<'a>,
@ -915,9 +915,9 @@ impl<'a> MethodDef<'a> {
explicit_self explicit_self
}); });
for (i, ty) in self.args.iter().enumerate() { for (ty, name) in self.args.iter() {
let ast_ty = ty.to_ty(cx, trait_.span, type_ident, generics); 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(name).gensym();
arg_tys.push((ident, ast_ty)); arg_tys.push((ident, ast_ty));
let arg_expr = cx.expr_ident(trait_.span, ident); let arg_expr = cx.expr_ident(trait_.span, ident);

View file

@ -44,8 +44,8 @@ pub fn expand_deriving_hash(cx: &mut ExtCtxt,
bounds: vec![(typaram, vec![path_std!(cx, hash::Hasher)])], bounds: vec![(typaram, vec![path_std!(cx, hash::Hasher)])],
}, },
explicit_self: borrowed_explicit_self(), explicit_self: borrowed_explicit_self(),
args: vec![Ptr(Box::new(Literal(arg)), args: vec![(Ptr(Box::new(Literal(arg)),
Borrowed(None, Mutability::Mutable))], Borrowed(None, Mutability::Mutable)), "_state")],
ret_ty: nil_ty(), ret_ty: nil_ty(),
attributes: vec![], attributes: vec![],
is_unsafe: false, is_unsafe: false,

View file

@ -53,6 +53,10 @@ impl Ident {
pub fn modern(self) -> Ident { pub fn modern(self) -> Ident {
Ident::new(self.name, self.span.modern()) Ident::new(self.name, self.span.modern())
} }
pub fn gensym(self) -> Ident {
Ident::new(self.name.gensymed(), self.span)
}
} }
impl PartialEq for Ident { impl PartialEq for Ident {

View file

@ -58,7 +58,7 @@ fn expand_deriving_partial_eq(cx: &mut ExtCtxt, span: Span, mitem: &MetaItem, it
name: "eq", name: "eq",
generics: LifetimeBounds::empty(), generics: LifetimeBounds::empty(),
explicit_self: borrowed_explicit_self(), explicit_self: borrowed_explicit_self(),
args: vec![borrowed_self()], args: vec![(borrowed_self(), "other")],
ret_ty: Literal(deriving::generic::ty::Path::new_local("bool")), ret_ty: Literal(deriving::generic::ty::Path::new_local("bool")),
attributes: attrs, attributes: attrs,
is_unsafe: false, is_unsafe: false,