Skip to content

Commit c60b051

Browse files
authored
Rollup merge of #74357 - nnethercote:symbol-related-improvements, r=oli-obk
Some `Symbol` related improvements These commits make things nicer and avoid some `Symbol::as_str()` calls. r? @oli-obk
2 parents 0e70884 + a4ba181 commit c60b051

File tree

30 files changed

+396
-303
lines changed

30 files changed

+396
-303
lines changed

src/librustc_builtin_macros/deriving/bounds.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ pub fn expand_deriving_copy(
1616
let trait_def = TraitDef {
1717
span,
1818
attributes: Vec::new(),
19-
path: path_std!(cx, marker::Copy),
19+
path: path_std!(marker::Copy),
2020
additional_bounds: Vec::new(),
21-
generics: LifetimeBounds::empty(),
21+
generics: Bounds::empty(),
2222
is_unsafe: false,
2323
supports_unions: true,
2424
methods: Vec::new(),

src/librustc_builtin_macros/deriving/clone.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub fn expand_deriving_clone(
5656
}
5757
}
5858
ItemKind::Union(..) => {
59-
bounds = vec![Literal(path_std!(cx, marker::Copy))];
59+
bounds = vec![Literal(path_std!(marker::Copy))];
6060
is_shallow = true;
6161
substructure = combine_substructure(Box::new(|c, s, sub| {
6262
cs_clone_shallow("Clone", c, s, sub, true)
@@ -78,14 +78,14 @@ pub fn expand_deriving_clone(
7878
let trait_def = TraitDef {
7979
span,
8080
attributes: Vec::new(),
81-
path: path_std!(cx, clone::Clone),
81+
path: path_std!(clone::Clone),
8282
additional_bounds: bounds,
83-
generics: LifetimeBounds::empty(),
83+
generics: Bounds::empty(),
8484
is_unsafe: false,
8585
supports_unions: true,
8686
methods: vec![MethodDef {
8787
name: sym::clone,
88-
generics: LifetimeBounds::empty(),
88+
generics: Bounds::empty(),
8989
explicit_self: borrowed_explicit_self(),
9090
args: Vec::new(),
9191
ret_ty: Self_,

src/librustc_builtin_macros/deriving/cmp/eq.rs

+4-10
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ pub fn expand_deriving_eq(
2222
let trait_def = TraitDef {
2323
span,
2424
attributes: Vec::new(),
25-
path: path_std!(cx, cmp::Eq),
25+
path: path_std!(cmp::Eq),
2626
additional_bounds: Vec::new(),
27-
generics: LifetimeBounds::empty(),
27+
generics: Bounds::empty(),
2828
is_unsafe: false,
2929
supports_unions: true,
3030
methods: vec![MethodDef {
3131
name: sym::assert_receiver_is_total_eq,
32-
generics: LifetimeBounds::empty(),
32+
generics: Bounds::empty(),
3333
explicit_self: borrowed_explicit_self(),
3434
args: vec![],
3535
ret_ty: nil_ty(),
@@ -43,13 +43,7 @@ pub fn expand_deriving_eq(
4343
associated_types: Vec::new(),
4444
};
4545

46-
super::inject_impl_of_structural_trait(
47-
cx,
48-
span,
49-
item,
50-
path_std!(cx, marker::StructuralEq),
51-
push,
52-
);
46+
super::inject_impl_of_structural_trait(cx, span, item, path_std!(marker::StructuralEq), push);
5347

5448
trait_def.expand_ext(cx, mitem, item, push, true)
5549
}

src/librustc_builtin_macros/deriving/cmp/ord.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@ pub fn expand_deriving_ord(
2020
let trait_def = TraitDef {
2121
span,
2222
attributes: Vec::new(),
23-
path: path_std!(cx, cmp::Ord),
23+
path: path_std!(cmp::Ord),
2424
additional_bounds: Vec::new(),
25-
generics: LifetimeBounds::empty(),
25+
generics: Bounds::empty(),
2626
is_unsafe: false,
2727
supports_unions: false,
2828
methods: vec![MethodDef {
2929
name: sym::cmp,
30-
generics: LifetimeBounds::empty(),
30+
generics: Bounds::empty(),
3131
explicit_self: borrowed_explicit_self(),
32-
args: vec![(borrowed_self(), "other")],
33-
ret_ty: Literal(path_std!(cx, cmp::Ordering)),
32+
args: vec![(borrowed_self(), sym::other)],
33+
ret_ty: Literal(path_std!(cmp::Ordering)),
3434
attributes: attrs,
3535
is_unsafe: false,
3636
unify_fieldless_variants: true,

src/librustc_builtin_macros/deriving/cmp/partial_eq.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ pub fn expand_deriving_partial_eq(
6969
let attrs = vec![cx.attribute(inline)];
7070
MethodDef {
7171
name: $name,
72-
generics: LifetimeBounds::empty(),
72+
generics: Bounds::empty(),
7373
explicit_self: borrowed_explicit_self(),
74-
args: vec![(borrowed_self(), "other")],
74+
args: vec![(borrowed_self(), sym::other)],
7575
ret_ty: Literal(path_local!(bool)),
7676
attributes: attrs,
7777
is_unsafe: false,
@@ -85,7 +85,7 @@ pub fn expand_deriving_partial_eq(
8585
cx,
8686
span,
8787
item,
88-
path_std!(cx, marker::StructuralPartialEq),
88+
path_std!(marker::StructuralPartialEq),
8989
push,
9090
);
9191

@@ -100,9 +100,9 @@ pub fn expand_deriving_partial_eq(
100100
let trait_def = TraitDef {
101101
span,
102102
attributes: Vec::new(),
103-
path: path_std!(cx, cmp::PartialEq),
103+
path: path_std!(cmp::PartialEq),
104104
additional_bounds: Vec::new(),
105-
generics: LifetimeBounds::empty(),
105+
generics: Bounds::empty(),
106106
is_unsafe: false,
107107
supports_unions: false,
108108
methods,

src/librustc_builtin_macros/deriving/cmp/partial_ord.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ pub fn expand_deriving_partial_ord(
2323
let attrs = vec![cx.attribute(inline)];
2424
MethodDef {
2525
name: $name,
26-
generics: LifetimeBounds::empty(),
26+
generics: Bounds::empty(),
2727
explicit_self: borrowed_explicit_self(),
28-
args: vec![(borrowed_self(), "other")],
28+
args: vec![(borrowed_self(), sym::other)],
2929
ret_ty: Literal(path_local!(bool)),
3030
attributes: attrs,
3131
is_unsafe: false,
@@ -37,9 +37,9 @@ pub fn expand_deriving_partial_ord(
3737
}};
3838
}
3939

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

5151
let partial_cmp_def = MethodDef {
5252
name: sym::partial_cmp,
53-
generics: LifetimeBounds::empty(),
53+
generics: Bounds::empty(),
5454
explicit_self: borrowed_explicit_self(),
55-
args: vec![(borrowed_self(), "other")],
55+
args: vec![(borrowed_self(), sym::other)],
5656
ret_ty,
5757
attributes: attrs,
5858
is_unsafe: false,
@@ -80,9 +80,9 @@ pub fn expand_deriving_partial_ord(
8080
let trait_def = TraitDef {
8181
span,
8282
attributes: vec![],
83-
path: path_std!(cx, cmp::PartialOrd),
83+
path: path_std!(cmp::PartialOrd),
8484
additional_bounds: vec![],
85-
generics: LifetimeBounds::empty(),
85+
generics: Bounds::empty(),
8686
is_unsafe: false,
8787
supports_unions: false,
8888
methods,

src/librustc_builtin_macros/deriving/debug.rs

+11-10
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,22 @@ pub fn expand_deriving_debug(
1818
) {
1919
// &mut ::std::fmt::Formatter
2020
let fmtr =
21-
Ptr(Box::new(Literal(path_std!(cx, fmt::Formatter))), Borrowed(None, ast::Mutability::Mut));
21+
Ptr(Box::new(Literal(path_std!(fmt::Formatter))), Borrowed(None, ast::Mutability::Mut));
2222

2323
let trait_def = TraitDef {
2424
span,
2525
attributes: Vec::new(),
26-
path: path_std!(cx, fmt::Debug),
26+
path: path_std!(fmt::Debug),
2727
additional_bounds: Vec::new(),
28-
generics: LifetimeBounds::empty(),
28+
generics: Bounds::empty(),
2929
is_unsafe: false,
3030
supports_unions: false,
3131
methods: vec![MethodDef {
3232
name: sym::fmt,
33-
generics: LifetimeBounds::empty(),
33+
generics: Bounds::empty(),
3434
explicit_self: borrowed_explicit_self(),
35-
args: vec![(fmtr, "f")],
36-
ret_ty: Literal(path_std!(cx, fmt::Result)),
35+
args: vec![(fmtr, sym::f)],
36+
ret_ty: Literal(path_std!(fmt::Result)),
3737
attributes: Vec::new(),
3838
is_unsafe: false,
3939
unify_fieldless_variants: false,
@@ -62,7 +62,7 @@ fn show_substructure(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>
6262
// We want to make sure we have the ctxt set so that we can use unstable methods
6363
let span = cx.with_def_site_ctxt(span);
6464
let name = cx.expr_lit(span, ast::LitKind::Str(ident.name, ast::StrStyle::Cooked));
65-
let builder = cx.ident_of("debug_trait_builder", span);
65+
let builder = Ident::new(sym::debug_trait_builder, span);
6666
let builder_expr = cx.expr_ident(span, builder);
6767

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

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

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

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

122123
stmts.push(cx.stmt_expr(expr));
123124
let block = cx.block(span, stmts);

src/librustc_builtin_macros/deriving/decodable.rs

+21-22
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_ast::ast;
88
use rustc_ast::ast::{Expr, MetaItem, Mutability};
99
use rustc_ast::ptr::P;
1010
use rustc_expand::base::{Annotatable, ExtCtxt};
11-
use rustc_span::symbol::{sym, Symbol};
11+
use rustc_span::symbol::{sym, Ident, Symbol};
1212
use rustc_span::Span;
1313

1414
pub fn expand_deriving_rustc_decodable(
@@ -18,38 +18,37 @@ pub fn expand_deriving_rustc_decodable(
1818
item: &Annotatable,
1919
push: &mut dyn FnMut(Annotatable),
2020
) {
21-
let krate = "rustc_serialize";
22-
let typaram = "__D";
21+
let krate = sym::rustc_serialize;
22+
let typaram = sym::__D;
2323

2424
let trait_def = TraitDef {
2525
span,
2626
attributes: Vec::new(),
27-
path: Path::new_(vec![krate, "Decodable"], None, vec![], PathKind::Global),
27+
path: Path::new_(vec![krate, sym::Decodable], None, vec![], PathKind::Global),
2828
additional_bounds: Vec::new(),
29-
generics: LifetimeBounds::empty(),
29+
generics: Bounds::empty(),
3030
is_unsafe: false,
3131
supports_unions: false,
3232
methods: vec![MethodDef {
3333
name: sym::decode,
34-
generics: LifetimeBounds {
35-
lifetimes: Vec::new(),
34+
generics: Bounds {
3635
bounds: vec![(
3736
typaram,
38-
vec![Path::new_(vec![krate, "Decoder"], None, vec![], PathKind::Global)],
37+
vec![Path::new_(vec![krate, sym::Decoder], None, vec![], PathKind::Global)],
3938
)],
4039
},
4140
explicit_self: None,
4241
args: vec![(
4342
Ptr(Box::new(Literal(Path::new_local(typaram))), Borrowed(None, Mutability::Mut)),
44-
"d",
43+
sym::d,
4544
)],
4645
ret_ty: Literal(Path::new_(
47-
pathvec_std!(cx, result::Result),
46+
pathvec_std!(result::Result),
4847
None,
4948
vec![
5049
Box::new(Self_),
5150
Box::new(Literal(Path::new_(
52-
vec![typaram, "Error"],
51+
vec![typaram, sym::Error],
5352
None,
5453
vec![],
5554
PathKind::Local,
@@ -74,17 +73,17 @@ fn decodable_substructure(
7473
cx: &mut ExtCtxt<'_>,
7574
trait_span: Span,
7675
substr: &Substructure<'_>,
77-
krate: &str,
76+
krate: Symbol,
7877
) -> P<Expr> {
7978
let decoder = substr.nonself_args[0].clone();
8079
let recurse = vec![
81-
cx.ident_of(krate, trait_span),
82-
cx.ident_of("Decodable", trait_span),
83-
cx.ident_of("decode", trait_span),
80+
Ident::new(krate, trait_span),
81+
Ident::new(sym::Decodable, trait_span),
82+
Ident::new(sym::decode, trait_span),
8483
];
8584
let exprdecode = cx.expr_path(cx.path_global(trait_span, recurse));
8685
// throw an underscore in front to suppress unused variable warnings
87-
let blkarg = cx.ident_of("_d", trait_span);
86+
let blkarg = Ident::new(sym::_d, trait_span);
8887
let blkdecoder = cx.expr_ident(trait_span, blkarg);
8988

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

9897
let path = cx.path_ident(trait_span, substr.type_ident);
9998
let result =
@@ -116,7 +115,7 @@ fn decodable_substructure(
116115
cx.expr_method_call(
117116
trait_span,
118117
decoder,
119-
cx.ident_of("read_struct", trait_span),
118+
Ident::new(sym::read_struct, trait_span),
120119
vec![
121120
cx.expr_str(trait_span, substr.type_ident.name),
122121
cx.expr_usize(trait_span, nfields),
@@ -125,11 +124,11 @@ fn decodable_substructure(
125124
)
126125
}
127126
StaticEnum(_, ref fields) => {
128-
let variant = cx.ident_of("i", trait_span);
127+
let variant = Ident::new(sym::i, trait_span);
129128

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

134133
for (i, &(ident, v_span, ref parts)) in fields.iter().enumerate() {
135134
variants.push(cx.expr_str(v_span, ident.name));
@@ -164,13 +163,13 @@ fn decodable_substructure(
164163
let result = cx.expr_method_call(
165164
trait_span,
166165
blkdecoder,
167-
cx.ident_of("read_enum_variant", trait_span),
166+
Ident::new(sym::read_enum_variant, trait_span),
168167
vec![variant_vec, lambda],
169168
);
170169
cx.expr_method_call(
171170
trait_span,
172171
decoder,
173-
cx.ident_of("read_enum", trait_span),
172+
Ident::new(sym::read_enum, trait_span),
174173
vec![
175174
cx.expr_str(trait_span, substr.type_ident.name),
176175
cx.lambda1(trait_span, result, blkarg),

src/librustc_builtin_macros/deriving/default.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::deriving::generic::ty::*;
22
use crate::deriving::generic::*;
3-
use crate::deriving::path_std;
43

54
use rustc_ast::ast::{Expr, MetaItem};
65
use rustc_ast::ptr::P;
@@ -21,14 +20,14 @@ pub fn expand_deriving_default(
2120
let trait_def = TraitDef {
2221
span,
2322
attributes: Vec::new(),
24-
path: path_std!(cx, default::Default),
23+
path: Path::new(vec![kw::Default, sym::Default]),
2524
additional_bounds: Vec::new(),
26-
generics: LifetimeBounds::empty(),
25+
generics: Bounds::empty(),
2726
is_unsafe: false,
2827
supports_unions: false,
2928
methods: vec![MethodDef {
3029
name: kw::Default,
31-
generics: LifetimeBounds::empty(),
30+
generics: Bounds::empty(),
3231
explicit_self: None,
3332
args: Vec::new(),
3433
ret_ty: Self_,

0 commit comments

Comments
 (0)