Skip to content

Provide better names for builtin deriving-generated attributes #49986

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Apr 25, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/libsyntax_ext/deriving/cmp/ord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub fn expand_deriving_ord(cx: &mut ExtCtxt,
name: "cmp",
generics: LifetimeBounds::empty(),
explicit_self: borrowed_explicit_self(),
args: vec![borrowed_self()],
args: vec![(borrowed_self(), "other")],
ret_ty: Literal(path_std!(cx, cmp::Ordering)),
attributes: attrs,
is_unsafe: false,
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax_ext/deriving/cmp/partial_eq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub fn expand_deriving_partial_eq(cx: &mut ExtCtxt,
name: $name,
generics: LifetimeBounds::empty(),
explicit_self: borrowed_explicit_self(),
args: vec![borrowed_self()],
args: vec![(borrowed_self(), "_other")],
ret_ty: Literal(path_local!(bool)),
attributes: attrs,
is_unsafe: false,
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax_ext/deriving/cmp/partial_ord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub fn expand_deriving_partial_ord(cx: &mut ExtCtxt,
name: $name,
generics: LifetimeBounds::empty(),
explicit_self: borrowed_explicit_self(),
args: vec![borrowed_self()],
args: vec![(borrowed_self(), "other")],
ret_ty: Literal(path_local!(bool)),
attributes: attrs,
is_unsafe: false,
Expand All @@ -59,7 +59,7 @@ pub fn expand_deriving_partial_ord(cx: &mut ExtCtxt,
name: "partial_cmp",
generics: LifetimeBounds::empty(),
explicit_self: borrowed_explicit_self(),
args: vec![borrowed_self()],
args: vec![(borrowed_self(), "other")],
ret_ty,
attributes: attrs,
is_unsafe: false,
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax_ext/deriving/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub fn expand_deriving_debug(cx: &mut ExtCtxt,
name: "fmt",
generics: LifetimeBounds::empty(),
explicit_self: borrowed_explicit_self(),
args: vec![fmtr],
args: vec![(fmtr, "_f")],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probs should be fmt

(check what the trait uses)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The trait uses "f" (I took all the names from the traits)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah. Probably should be fmt then

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I know why it's short; it's to encourage implementors to keep it short. Leave it f then.

ret_ty: Literal(path_std!(cx, fmt::Result)),
attributes: Vec::new(),
is_unsafe: false,
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax_ext/deriving/decodable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ fn expand_deriving_decodable_imp(cx: &mut ExtCtxt,
PathKind::Global)])],
},
explicit_self: None,
args: vec![Ptr(Box::new(Literal(Path::new_local(typaram))),
Borrowed(None, Mutability::Mutable))],
args: vec![(Ptr(Box::new(Literal(Path::new_local(typaram))),
Borrowed(None, Mutability::Mutable)), "d")],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"decoder"?

Copy link
Contributor Author

@zofrex zofrex Apr 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also from the trait. Relatedly... are these (decodable/encodable) even used? I couldn't find any references to these in the docs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are, they're from a deprecated builtin thing. See the rustc_serialize crate.

ret_ty:
Literal(Path::new_(pathvec_std!(cx, result::Result),
None,
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax_ext/deriving/encodable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ fn expand_deriving_encodable_imp(cx: &mut ExtCtxt,
],
},
explicit_self: borrowed_explicit_self(),
args: vec![Ptr(Box::new(Literal(Path::new_local(typaram))),
Borrowed(None, Mutability::Mutable))],
args: vec![(Ptr(Box::new(Literal(Path::new_local(typaram))),
Borrowed(None, Mutability::Mutable)), "s")],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"encoder"?

ret_ty: Literal(Path::new_(
pathvec_std!(cx, result::Result),
None,
Expand Down
6 changes: 3 additions & 3 deletions src/libsyntax_ext/deriving/generic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ pub struct MethodDef<'a> {
pub explicit_self: Option<Option<PtrTy<'a>>>,

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

/// Return type
pub ret_ty: Ty<'a>,
Expand Down Expand Up @@ -915,9 +915,9 @@ impl<'a> MethodDef<'a> {
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 ident = cx.ident_of(&format!("__arg_{}", i));
let ident = cx.ident_of(name).gensym();
arg_tys.push((ident, ast_ty));

let arg_expr = cx.expr_ident(trait_.span, ident);
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax_ext/deriving/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ pub fn expand_deriving_hash(cx: &mut ExtCtxt,
bounds: vec![(typaram, vec![path_std!(cx, hash::Hasher)])],
},
explicit_self: borrowed_explicit_self(),
args: vec![Ptr(Box::new(Literal(arg)),
Borrowed(None, Mutability::Mutable))],
args: vec![(Ptr(Box::new(Literal(arg)),
Borrowed(None, Mutability::Mutable)), "_state")],
ret_ty: nil_ty(),
attributes: vec![],
is_unsafe: false,
Expand Down
4 changes: 4 additions & 0 deletions src/libsyntax_pos/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ impl Ident {
pub fn modern(self) -> Ident {
Ident::new(self.name, self.span.modern())
}

pub fn gensym(self) -> Ident {
Ident::new(self.name.gensymed(), self.span)
}
}

impl PartialEq for Ident {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ fn expand_deriving_partial_eq(cx: &mut ExtCtxt, span: Span, mitem: &MetaItem, it
name: "eq",
generics: LifetimeBounds::empty(),
explicit_self: borrowed_explicit_self(),
args: vec![borrowed_self()],
args: vec![(borrowed_self(), "other")],
ret_ty: Literal(deriving::generic::ty::Path::new_local("bool")),
attributes: attrs,
is_unsafe: false,
Expand Down