Skip to content
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

Some Symbol related improvements #74357

Merged
merged 6 commits into from
Jul 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions src/librustc_builtin_macros/deriving/bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ pub fn expand_deriving_copy(
let trait_def = TraitDef {
span,
attributes: Vec::new(),
path: path_std!(cx, marker::Copy),
path: path_std!(marker::Copy),
additional_bounds: Vec::new(),
generics: LifetimeBounds::empty(),
generics: Bounds::empty(),
is_unsafe: false,
supports_unions: true,
methods: Vec::new(),
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_builtin_macros/deriving/clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub fn expand_deriving_clone(
}
}
ItemKind::Union(..) => {
bounds = vec![Literal(path_std!(cx, marker::Copy))];
bounds = vec![Literal(path_std!(marker::Copy))];
is_shallow = true;
substructure = combine_substructure(Box::new(|c, s, sub| {
cs_clone_shallow("Clone", c, s, sub, true)
Expand All @@ -78,14 +78,14 @@ pub fn expand_deriving_clone(
let trait_def = TraitDef {
span,
attributes: Vec::new(),
path: path_std!(cx, clone::Clone),
path: path_std!(clone::Clone),
additional_bounds: bounds,
generics: LifetimeBounds::empty(),
generics: Bounds::empty(),
is_unsafe: false,
supports_unions: true,
methods: vec![MethodDef {
name: sym::clone,
generics: LifetimeBounds::empty(),
generics: Bounds::empty(),
explicit_self: borrowed_explicit_self(),
args: Vec::new(),
ret_ty: Self_,
Expand Down
14 changes: 4 additions & 10 deletions src/librustc_builtin_macros/deriving/cmp/eq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ pub fn expand_deriving_eq(
let trait_def = TraitDef {
span,
attributes: Vec::new(),
path: path_std!(cx, cmp::Eq),
path: path_std!(cmp::Eq),
additional_bounds: Vec::new(),
generics: LifetimeBounds::empty(),
generics: Bounds::empty(),
is_unsafe: false,
supports_unions: true,
methods: vec![MethodDef {
name: sym::assert_receiver_is_total_eq,
generics: LifetimeBounds::empty(),
generics: Bounds::empty(),
explicit_self: borrowed_explicit_self(),
args: vec![],
ret_ty: nil_ty(),
Expand All @@ -43,13 +43,7 @@ pub fn expand_deriving_eq(
associated_types: Vec::new(),
};

super::inject_impl_of_structural_trait(
cx,
span,
item,
path_std!(cx, marker::StructuralEq),
push,
);
super::inject_impl_of_structural_trait(cx, span, item, path_std!(marker::StructuralEq), push);

trait_def.expand_ext(cx, mitem, item, push, true)
}
Expand Down
10 changes: 5 additions & 5 deletions src/librustc_builtin_macros/deriving/cmp/ord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ pub fn expand_deriving_ord(
let trait_def = TraitDef {
span,
attributes: Vec::new(),
path: path_std!(cx, cmp::Ord),
path: path_std!(cmp::Ord),
additional_bounds: Vec::new(),
generics: LifetimeBounds::empty(),
generics: Bounds::empty(),
is_unsafe: false,
supports_unions: false,
methods: vec![MethodDef {
name: sym::cmp,
generics: LifetimeBounds::empty(),
generics: Bounds::empty(),
explicit_self: borrowed_explicit_self(),
args: vec![(borrowed_self(), "other")],
ret_ty: Literal(path_std!(cx, cmp::Ordering)),
args: vec![(borrowed_self(), sym::other)],
ret_ty: Literal(path_std!(cmp::Ordering)),
attributes: attrs,
is_unsafe: false,
unify_fieldless_variants: true,
Expand Down
10 changes: 5 additions & 5 deletions src/librustc_builtin_macros/deriving/cmp/partial_eq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ pub fn expand_deriving_partial_eq(
let attrs = vec![cx.attribute(inline)];
MethodDef {
name: $name,
generics: LifetimeBounds::empty(),
generics: Bounds::empty(),
explicit_self: borrowed_explicit_self(),
args: vec![(borrowed_self(), "other")],
args: vec![(borrowed_self(), sym::other)],
ret_ty: Literal(path_local!(bool)),
attributes: attrs,
is_unsafe: false,
Expand All @@ -85,7 +85,7 @@ pub fn expand_deriving_partial_eq(
cx,
span,
item,
path_std!(cx, marker::StructuralPartialEq),
path_std!(marker::StructuralPartialEq),
push,
);

Expand All @@ -100,9 +100,9 @@ pub fn expand_deriving_partial_eq(
let trait_def = TraitDef {
span,
attributes: Vec::new(),
path: path_std!(cx, cmp::PartialEq),
path: path_std!(cmp::PartialEq),
additional_bounds: Vec::new(),
generics: LifetimeBounds::empty(),
generics: Bounds::empty(),
is_unsafe: false,
supports_unions: false,
methods,
Expand Down
16 changes: 8 additions & 8 deletions src/librustc_builtin_macros/deriving/cmp/partial_ord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ pub fn expand_deriving_partial_ord(
let attrs = vec![cx.attribute(inline)];
MethodDef {
name: $name,
generics: LifetimeBounds::empty(),
generics: Bounds::empty(),
explicit_self: borrowed_explicit_self(),
args: vec![(borrowed_self(), "other")],
args: vec![(borrowed_self(), sym::other)],
ret_ty: Literal(path_local!(bool)),
attributes: attrs,
is_unsafe: false,
Expand All @@ -37,9 +37,9 @@ pub fn expand_deriving_partial_ord(
}};
}

let ordering_ty = Literal(path_std!(cx, cmp::Ordering));
let ordering_ty = Literal(path_std!(cmp::Ordering));
let ret_ty = Literal(Path::new_(
pathvec_std!(cx, option::Option),
pathvec_std!(option::Option),
None,
vec![Box::new(ordering_ty)],
PathKind::Std,
Expand All @@ -50,9 +50,9 @@ pub fn expand_deriving_partial_ord(

let partial_cmp_def = MethodDef {
name: sym::partial_cmp,
generics: LifetimeBounds::empty(),
generics: Bounds::empty(),
explicit_self: borrowed_explicit_self(),
args: vec![(borrowed_self(), "other")],
args: vec![(borrowed_self(), sym::other)],
ret_ty,
attributes: attrs,
is_unsafe: false,
Expand Down Expand Up @@ -80,9 +80,9 @@ pub fn expand_deriving_partial_ord(
let trait_def = TraitDef {
span,
attributes: vec![],
path: path_std!(cx, cmp::PartialOrd),
path: path_std!(cmp::PartialOrd),
additional_bounds: vec![],
generics: LifetimeBounds::empty(),
generics: Bounds::empty(),
is_unsafe: false,
supports_unions: false,
methods,
Expand Down
21 changes: 11 additions & 10 deletions src/librustc_builtin_macros/deriving/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@ pub fn expand_deriving_debug(
) {
// &mut ::std::fmt::Formatter
let fmtr =
Ptr(Box::new(Literal(path_std!(cx, fmt::Formatter))), Borrowed(None, ast::Mutability::Mut));
Ptr(Box::new(Literal(path_std!(fmt::Formatter))), Borrowed(None, ast::Mutability::Mut));

let trait_def = TraitDef {
span,
attributes: Vec::new(),
path: path_std!(cx, fmt::Debug),
path: path_std!(fmt::Debug),
additional_bounds: Vec::new(),
generics: LifetimeBounds::empty(),
generics: Bounds::empty(),
is_unsafe: false,
supports_unions: false,
methods: vec![MethodDef {
name: sym::fmt,
generics: LifetimeBounds::empty(),
generics: Bounds::empty(),
explicit_self: borrowed_explicit_self(),
args: vec![(fmtr, "f")],
ret_ty: Literal(path_std!(cx, fmt::Result)),
args: vec![(fmtr, sym::f)],
ret_ty: Literal(path_std!(fmt::Result)),
attributes: Vec::new(),
is_unsafe: false,
unify_fieldless_variants: false,
Expand Down Expand Up @@ -62,7 +62,7 @@ fn show_substructure(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>
// We want to make sure we have the ctxt set so that we can use unstable methods
let span = cx.with_def_site_ctxt(span);
let name = cx.expr_lit(span, ast::LitKind::Str(ident.name, ast::StrStyle::Cooked));
let builder = cx.ident_of("debug_trait_builder", span);
let builder = Ident::new(sym::debug_trait_builder, span);
let builder_expr = cx.expr_ident(span, builder);

let fmt = substr.nonself_args[0].clone();
Expand All @@ -71,7 +71,8 @@ fn show_substructure(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>
match vdata {
ast::VariantData::Tuple(..) | ast::VariantData::Unit(..) => {
// tuple struct/"normal" variant
let expr = cx.expr_method_call(span, fmt, cx.ident_of("debug_tuple", span), vec![name]);
let expr =
cx.expr_method_call(span, fmt, Ident::new(sym::debug_tuple, span), vec![name]);
stmts.push(cx.stmt_let(span, true, builder, expr));

for field in fields {
Expand All @@ -94,7 +95,7 @@ fn show_substructure(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>
ast::VariantData::Struct(..) => {
// normal struct/struct variant
let expr =
cx.expr_method_call(span, fmt, cx.ident_of("debug_struct", span), vec![name]);
cx.expr_method_call(span, fmt, Ident::new(sym::debug_struct, span), vec![name]);
stmts.push(cx.stmt_let(DUMMY_SP, true, builder, expr));

for field in fields {
Expand All @@ -117,7 +118,7 @@ fn show_substructure(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>
}
}

let expr = cx.expr_method_call(span, builder_expr, cx.ident_of("finish", span), vec![]);
let expr = cx.expr_method_call(span, builder_expr, Ident::new(sym::finish, span), vec![]);

stmts.push(cx.stmt_expr(expr));
let block = cx.block(span, stmts);
Expand Down
43 changes: 21 additions & 22 deletions src/librustc_builtin_macros/deriving/decodable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use rustc_ast::ast;
use rustc_ast::ast::{Expr, MetaItem, Mutability};
use rustc_ast::ptr::P;
use rustc_expand::base::{Annotatable, ExtCtxt};
use rustc_span::symbol::{sym, Symbol};
use rustc_span::symbol::{sym, Ident, Symbol};
use rustc_span::Span;

pub fn expand_deriving_rustc_decodable(
Expand All @@ -18,38 +18,37 @@ pub fn expand_deriving_rustc_decodable(
item: &Annotatable,
push: &mut dyn FnMut(Annotatable),
) {
let krate = "rustc_serialize";
let typaram = "__D";
let krate = sym::rustc_serialize;
let typaram = sym::__D;

let trait_def = TraitDef {
span,
attributes: Vec::new(),
path: Path::new_(vec![krate, "Decodable"], None, vec![], PathKind::Global),
path: Path::new_(vec![krate, sym::Decodable], None, vec![], PathKind::Global),
additional_bounds: Vec::new(),
generics: LifetimeBounds::empty(),
generics: Bounds::empty(),
is_unsafe: false,
supports_unions: false,
methods: vec![MethodDef {
name: sym::decode,
generics: LifetimeBounds {
lifetimes: Vec::new(),
generics: Bounds {
bounds: vec![(
typaram,
vec![Path::new_(vec![krate, "Decoder"], None, vec![], PathKind::Global)],
vec![Path::new_(vec![krate, sym::Decoder], None, vec![], PathKind::Global)],
)],
},
explicit_self: None,
args: vec![(
Ptr(Box::new(Literal(Path::new_local(typaram))), Borrowed(None, Mutability::Mut)),
"d",
sym::d,
)],
ret_ty: Literal(Path::new_(
pathvec_std!(cx, result::Result),
pathvec_std!(result::Result),
None,
vec![
Box::new(Self_),
Box::new(Literal(Path::new_(
vec![typaram, "Error"],
vec![typaram, sym::Error],
None,
vec![],
PathKind::Local,
Expand All @@ -74,17 +73,17 @@ fn decodable_substructure(
cx: &mut ExtCtxt<'_>,
trait_span: Span,
substr: &Substructure<'_>,
krate: &str,
krate: Symbol,
) -> P<Expr> {
let decoder = substr.nonself_args[0].clone();
let recurse = vec![
cx.ident_of(krate, trait_span),
cx.ident_of("Decodable", trait_span),
cx.ident_of("decode", trait_span),
Ident::new(krate, trait_span),
Ident::new(sym::Decodable, trait_span),
Ident::new(sym::decode, trait_span),
];
let exprdecode = cx.expr_path(cx.path_global(trait_span, recurse));
// throw an underscore in front to suppress unused variable warnings
let blkarg = cx.ident_of("_d", trait_span);
let blkarg = Ident::new(sym::_d, trait_span);
let blkdecoder = cx.expr_ident(trait_span, blkarg);

match *substr.fields {
Expand All @@ -93,7 +92,7 @@ fn decodable_substructure(
Unnamed(ref fields, _) => fields.len(),
Named(ref fields) => fields.len(),
};
let read_struct_field = cx.ident_of("read_struct_field", trait_span);
let read_struct_field = Ident::new(sym::read_struct_field, trait_span);

let path = cx.path_ident(trait_span, substr.type_ident);
let result =
Expand All @@ -116,7 +115,7 @@ fn decodable_substructure(
cx.expr_method_call(
trait_span,
decoder,
cx.ident_of("read_struct", trait_span),
Ident::new(sym::read_struct, trait_span),
vec![
cx.expr_str(trait_span, substr.type_ident.name),
cx.expr_usize(trait_span, nfields),
Expand All @@ -125,11 +124,11 @@ fn decodable_substructure(
)
}
StaticEnum(_, ref fields) => {
let variant = cx.ident_of("i", trait_span);
let variant = Ident::new(sym::i, trait_span);

let mut arms = Vec::with_capacity(fields.len() + 1);
let mut variants = Vec::with_capacity(fields.len());
let rvariant_arg = cx.ident_of("read_enum_variant_arg", trait_span);
let rvariant_arg = Ident::new(sym::read_enum_variant_arg, trait_span);

for (i, &(ident, v_span, ref parts)) in fields.iter().enumerate() {
variants.push(cx.expr_str(v_span, ident.name));
Expand Down Expand Up @@ -164,13 +163,13 @@ fn decodable_substructure(
let result = cx.expr_method_call(
trait_span,
blkdecoder,
cx.ident_of("read_enum_variant", trait_span),
Ident::new(sym::read_enum_variant, trait_span),
vec![variant_vec, lambda],
);
cx.expr_method_call(
trait_span,
decoder,
cx.ident_of("read_enum", trait_span),
Ident::new(sym::read_enum, trait_span),
vec![
cx.expr_str(trait_span, substr.type_ident.name),
cx.lambda1(trait_span, result, blkarg),
Expand Down
7 changes: 3 additions & 4 deletions src/librustc_builtin_macros/deriving/default.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::deriving::generic::ty::*;
use crate::deriving::generic::*;
use crate::deriving::path_std;

use rustc_ast::ast::{Expr, MetaItem};
use rustc_ast::ptr::P;
Expand All @@ -21,14 +20,14 @@ pub fn expand_deriving_default(
let trait_def = TraitDef {
span,
attributes: Vec::new(),
path: path_std!(cx, default::Default),
path: Path::new(vec![kw::Default, sym::Default]),
additional_bounds: Vec::new(),
generics: LifetimeBounds::empty(),
generics: Bounds::empty(),
is_unsafe: false,
supports_unions: false,
methods: vec![MethodDef {
name: kw::Default,
generics: LifetimeBounds::empty(),
generics: Bounds::empty(),
explicit_self: None,
args: Vec::new(),
ret_ty: Self_,
Expand Down
Loading