Skip to content

Commit b6d522a

Browse files
committed
syntax: Pre-intern names of all built-in macros
They always end up interned anyway
1 parent 1ee0ce8 commit b6d522a

File tree

6 files changed

+45
-27
lines changed

6 files changed

+45
-27
lines changed

src/libsyntax/ext/derive.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ pub fn add_derived_markers<T>(cx: &mut ExtCtxt<'_>, span: Span, traits: &[ast::P
6363

6464
let span = span.with_ctxt(cx.backtrace());
6565
item.visit_attrs(|attrs| {
66-
if names.contains(&Symbol::intern("Eq")) && names.contains(&Symbol::intern("PartialEq")) {
67-
let meta = cx.meta_word(span, Symbol::intern("structural_match"));
66+
if names.contains(&sym::Eq) && names.contains(&sym::PartialEq) {
67+
let meta = cx.meta_word(span, sym::structural_match);
6868
attrs.push(cx.attribute(span, meta));
6969
}
70-
if names.contains(&Symbol::intern("Copy")) {
70+
if names.contains(&sym::Copy) {
7171
let meta = cx.meta_word(span, sym::rustc_copy_clone_marker);
7272
attrs.push(cx.attribute(span, meta));
7373
}

src/libsyntax/parse/lexer/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ impl<'a> StringReader<'a> {
613613
if num_digits == 0 {
614614
self.err_span_(start_bpos, self.pos, "no valid digits found for number");
615615

616-
return (token::Integer, Symbol::intern("0"));
616+
return (token::Integer, sym::integer(0));
617617
}
618618

619619
// might be a float, but don't be greedy if this is actually an

src/libsyntax_ext/deriving/mod.rs

+17-17
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ impl MultiItemModifier for BuiltinDerive {
6161
}
6262

6363
macro_rules! derive_traits {
64-
($( [$deprecation:expr] $name:expr => $func:path, )+) => {
64+
($( [$deprecation:expr] $name:ident => $func:path, )+) => {
6565
pub fn is_builtin_trait(name: ast::Name) -> bool {
66-
match &*name.as_str() {
67-
$( $name )|+ => true,
66+
match name {
67+
$( sym::$name )|+ => true,
6868
_ => false,
6969
}
7070
}
@@ -80,7 +80,7 @@ macro_rules! derive_traits {
8080

8181
$(
8282
resolver.add_builtin(
83-
ast::Ident::with_empty_ctxt(Symbol::intern($name)),
83+
ast::Ident::with_empty_ctxt(sym::$name),
8484
Lrc::new(SyntaxExtension {
8585
deprecation: $deprecation.map(|msg| Deprecation {
8686
since: Some(Symbol::intern("1.0.0")),
@@ -100,40 +100,40 @@ macro_rules! derive_traits {
100100

101101
derive_traits! {
102102
[None]
103-
"Clone" => clone::expand_deriving_clone,
103+
Clone => clone::expand_deriving_clone,
104104

105105
[None]
106-
"Hash" => hash::expand_deriving_hash,
106+
Hash => hash::expand_deriving_hash,
107107

108108
[None]
109-
"RustcEncodable" => encodable::expand_deriving_rustc_encodable,
109+
RustcEncodable => encodable::expand_deriving_rustc_encodable,
110110

111111
[None]
112-
"RustcDecodable" => decodable::expand_deriving_rustc_decodable,
112+
RustcDecodable => decodable::expand_deriving_rustc_decodable,
113113

114114
[None]
115-
"PartialEq" => partial_eq::expand_deriving_partial_eq,
115+
PartialEq => partial_eq::expand_deriving_partial_eq,
116116
[None]
117-
"Eq" => eq::expand_deriving_eq,
117+
Eq => eq::expand_deriving_eq,
118118
[None]
119-
"PartialOrd" => partial_ord::expand_deriving_partial_ord,
119+
PartialOrd => partial_ord::expand_deriving_partial_ord,
120120
[None]
121-
"Ord" => ord::expand_deriving_ord,
121+
Ord => ord::expand_deriving_ord,
122122

123123
[None]
124-
"Debug" => debug::expand_deriving_debug,
124+
Debug => debug::expand_deriving_debug,
125125

126126
[None]
127-
"Default" => default::expand_deriving_default,
127+
Default => default::expand_deriving_default,
128128

129129
[None]
130-
"Copy" => bounds::expand_deriving_copy,
130+
Copy => bounds::expand_deriving_copy,
131131

132132
// deprecated
133133
[Some("derive(Encodable) is deprecated in favor of derive(RustcEncodable)")]
134-
"Encodable" => encodable::expand_deriving_encodable,
134+
Encodable => encodable::expand_deriving_encodable,
135135
[Some("derive(Decodable) is deprecated in favor of derive(RustcDecodable)")]
136-
"Decodable" => decodable::expand_deriving_decodable,
136+
Decodable => decodable::expand_deriving_decodable,
137137
}
138138

139139
/// Construct a name for the inner type parameter that can't collide with any type parameters of

src/libsyntax_ext/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,14 @@ pub fn register_builtins(resolver: &mut dyn syntax::ext::base::Resolver,
7474
};
7575
macro_rules! register {
7676
($( $name:ident: $f:expr, )*) => { $(
77-
register(Symbol::intern(stringify!($name)), SyntaxExtension::default(
77+
register(sym::$name, SyntaxExtension::default(
7878
SyntaxExtensionKind::LegacyBang(Box::new($f as MacroExpanderFn)), edition
7979
));
8080
)* }
8181
}
8282
macro_rules! register_unstable {
8383
($( [$feature:expr, $reason:expr, $issue:expr] $name:ident: $f:expr, )*) => { $(
84-
register(Symbol::intern(stringify!($name)), SyntaxExtension {
84+
register(sym::$name, SyntaxExtension {
8585
stability: Some(Stability::unstable(
8686
$feature, Some(Symbol::intern($reason)), $issue
8787
)),
@@ -144,7 +144,7 @@ pub fn register_builtins(resolver: &mut dyn syntax::ext::base::Resolver,
144144

145145
// format_args uses `unstable` things internally.
146146
let allow_internal_unstable = Some([sym::fmt_internals][..].into());
147-
register(Symbol::intern("format_args"), SyntaxExtension {
147+
register(sym::format_args, SyntaxExtension {
148148
allow_internal_unstable: allow_internal_unstable.clone(),
149149
..SyntaxExtension::default(
150150
SyntaxExtensionKind::LegacyBang(Box::new(format::expand_format_args)), edition

src/libsyntax_ext/proc_macro_server.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -548,10 +548,10 @@ impl server::Literal for Rustc<'_> {
548548
self.lit(token::Float, Symbol::intern(n), None)
549549
}
550550
fn f32(&mut self, n: &str) -> Self::Literal {
551-
self.lit(token::Float, Symbol::intern(n), Some(Symbol::intern("f32")))
551+
self.lit(token::Float, Symbol::intern(n), Some(sym::f32))
552552
}
553553
fn f64(&mut self, n: &str) -> Self::Literal {
554-
self.lit(token::Float, Symbol::intern(n), Some(Symbol::intern("f64")))
554+
self.lit(token::Float, Symbol::intern(n), Some(sym::f64))
555555
}
556556
fn string(&mut self, string: &str) -> Self::Literal {
557557
let mut escaped = String::new();

src/libsyntax_pos/symbol.rs

+19-1
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ symbols! {
141141
ArgumentV1,
142142
arm_target_feature,
143143
asm,
144+
assert,
144145
associated_consts,
145146
associated_type_bounds,
146147
associated_type_defaults,
@@ -184,8 +185,10 @@ symbols! {
184185
cmp,
185186
cmpxchg16b_target_feature,
186187
cold,
188+
column,
187189
compile_error,
188190
compiler_builtins,
191+
concat,
189192
concat_idents,
190193
conservative_impl_trait,
191194
console,
@@ -203,6 +206,7 @@ symbols! {
203206
contents,
204207
context,
205208
convert,
209+
Copy,
206210
copy_closures,
207211
core,
208212
core_intrinsics,
@@ -217,8 +221,10 @@ symbols! {
217221
custom_inner_attributes,
218222
custom_test_frameworks,
219223
c_variadic,
224+
Debug,
220225
declare_lint_pass,
221226
decl_macro,
227+
Decodable,
222228
Default,
223229
default_lib_allocator,
224230
default_type_parameter_fallback,
@@ -253,9 +259,12 @@ symbols! {
253259
eh_personality,
254260
eh_unwind_resume,
255261
enable,
262+
Encodable,
263+
env,
256264
eq,
257265
err,
258266
Err,
267+
Eq,
259268
Equal,
260269
except,
261270
exclusive_range_pattern,
@@ -284,6 +293,7 @@ symbols! {
284293
fmt_internals,
285294
fn_must_use,
286295
forbid,
296+
format_args,
287297
format_args_nl,
288298
from,
289299
From,
@@ -335,6 +345,8 @@ symbols! {
335345
index_mut,
336346
in_band_lifetimes,
337347
include,
348+
include_bytes,
349+
include_str,
338350
inclusive_range_syntax,
339351
infer_outlives_requirements,
340352
infer_static_outlives_requirements,
@@ -363,6 +375,7 @@ symbols! {
363375
lhs,
364376
lib,
365377
lifetime,
378+
line,
366379
link,
367380
linkage,
368381
link_args,
@@ -402,6 +415,7 @@ symbols! {
402415
mips_target_feature,
403416
mmx_target_feature,
404417
module,
418+
module_path,
405419
more_struct_aliases,
406420
movbe_target_feature,
407421
must_use,
@@ -447,6 +461,7 @@ symbols! {
447461
optin_builtin_traits,
448462
option,
449463
Option,
464+
option_env,
450465
opt_out_copy,
451466
or,
452467
Ord,
@@ -462,6 +477,7 @@ symbols! {
462477
parent_trait,
463478
partial_cmp,
464479
param_attrs,
480+
PartialEq,
465481
PartialOrd,
466482
passes,
467483
pat,
@@ -532,6 +548,8 @@ symbols! {
532548
rust_2018_preview,
533549
rust_begin_unwind,
534550
rustc,
551+
RustcDecodable,
552+
RustcEncodable,
535553
rustc_allocator,
536554
rustc_allocator_nounwind,
537555
rustc_allow_const_fn_ptr,
@@ -591,7 +609,6 @@ symbols! {
591609
_Self,
592610
self_in_typedefs,
593611
self_struct_ctor,
594-
Send,
595612
should_panic,
596613
simd,
597614
simd_ffi,
@@ -613,6 +630,7 @@ symbols! {
613630
static_recursion,
614631
std,
615632
str,
633+
stringify,
616634
stmt,
617635
stmt_expr_attributes,
618636
stop_after_dataflow,

0 commit comments

Comments
 (0)