Skip to content

Commit a8245f5

Browse files
committedMay 12, 2019
Add lots of static Symbols.
These will be used in the subsequent commits. Many of them are attributes. The commit also adds the ability to handle symbols that aren't identifiers (e.g. "proc-macro").
1 parent 1764b29 commit a8245f5

File tree

2 files changed

+415
-16
lines changed

2 files changed

+415
-16
lines changed
 

‎src/librustc_macros/src/symbols.rs

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use quote::quote;
1111
#[allow(non_camel_case_types)]
1212
mod kw {
1313
syn::custom_keyword!(Keywords);
14-
syn::custom_keyword!(Other);
14+
syn::custom_keyword!(Symbols);
1515
}
1616

1717
struct Keyword {
@@ -33,14 +33,24 @@ impl Parse for Keyword {
3333
}
3434
}
3535

36-
struct Symbol(Ident);
36+
struct Symbol {
37+
name: Ident,
38+
value: Option<LitStr>,
39+
}
3740

3841
impl Parse for Symbol {
3942
fn parse(input: ParseStream<'_>) -> Result<Self> {
40-
let ident: Ident = input.parse()?;
43+
let name = input.parse()?;
44+
let value = match input.parse::<Token![:]>() {
45+
Ok(_) => Some(input.parse()?),
46+
Err(_) => None,
47+
};
4148
input.parse::<Token![,]>()?;
4249

43-
Ok(Symbol(ident))
50+
Ok(Symbol {
51+
name,
52+
value,
53+
})
4454
}
4555
}
4656

@@ -69,7 +79,7 @@ impl Parse for Input {
6979
braced!(content in input);
7080
let keywords = content.parse()?;
7181

72-
input.parse::<kw::Other>()?;
82+
input.parse::<kw::Symbols>()?;
7383
let content;
7484
braced!(content in input);
7585
let symbols = content.parse()?;
@@ -116,19 +126,22 @@ pub fn symbols(input: TokenStream) -> TokenStream {
116126
}
117127

118128
for symbol in &input.symbols.0 {
119-
let value = &symbol.0;
120-
let value_str = value.to_string();
121-
check_dup(&value_str);
129+
let name = &symbol.name;
130+
let value = match &symbol.value {
131+
Some(value) => value.value(),
132+
None => name.to_string(),
133+
};
134+
check_dup(&value);
122135
prefill_stream.extend(quote! {
123-
#value_str,
136+
#value,
124137
});
125138
symbols_stream.extend(quote! {
126-
pub const #value: Symbol = Symbol::new(#counter);
139+
pub const #name: Symbol = Symbol::new(#counter);
127140
});
128141
counter += 1;
129142
}
130143

131-
TokenStream::from(quote! {
144+
let tt = TokenStream::from(quote! {
132145
macro_rules! keywords {
133146
() => {
134147
#keyword_stream
@@ -159,5 +172,11 @@ pub fn symbols(input: TokenStream) -> TokenStream {
159172
])
160173
}
161174
}
162-
})
175+
});
176+
177+
// To see the generated code generated, uncomment this line, recompile, and
178+
// run the resulting output through `rustfmt`.
179+
//eprintln!("{}", tt);
180+
181+
tt
163182
}

‎src/libsyntax_pos/symbol.rs

Lines changed: 384 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,88 +99,375 @@ symbols! {
9999
Union: "union",
100100
}
101101

102-
// Other symbols that can be referred to with syntax_pos::symbols::*
103-
Other {
102+
// Symbols that can be referred to with syntax_pos::symbols::*. The symbol
103+
// is the stringified identifier unless otherwise specified (e.g.
104+
// `proc_dash_macro` represents "proc-macro").
105+
Symbols {
106+
aarch64_target_feature,
107+
abi,
108+
abi_amdgpu_kernel,
109+
abi_msp430_interrupt,
110+
abi_ptx,
111+
abi_sysv64,
112+
abi_thiscall,
113+
abi_unadjusted,
114+
abi_vectorcall,
115+
abi_x86_interrupt,
116+
aborts,
117+
advanced_slice_patterns,
118+
adx_target_feature,
104119
alias,
105120
align,
121+
alignstack,
122+
all,
123+
allocator,
124+
allocator_internals,
106125
alloc_error_handler,
107126
allow,
127+
allowed,
108128
allow_fail,
109129
allow_internal_unsafe,
110130
allow_internal_unstable,
131+
allow_internal_unstable_backcompat_hack,
132+
always,
133+
any,
134+
arbitrary_self_types,
135+
arm_target_feature,
136+
asm,
137+
associated_consts,
138+
associated_type_defaults,
139+
associated_types,
140+
async_await,
141+
attr,
142+
attributes,
143+
attr_literals,
144+
augmented_assignments,
111145
automatically_derived,
146+
avx512_target_feature,
147+
await_macro,
148+
bin,
149+
bind_by_move_pattern_guards,
150+
block,
151+
borrowck_graphviz_postflow,
152+
borrowck_graphviz_preflow,
153+
box_patterns,
154+
box_syntax,
155+
braced_empty_structs,
156+
C,
157+
cdylib,
112158
cfg,
113159
cfg_attr,
160+
cfg_attr_multi,
161+
cfg_target_feature,
162+
cfg_target_has_atomic,
163+
cfg_target_thread_local,
164+
cfg_target_vendor,
165+
clone,
166+
clone_closures,
167+
clone_from,
168+
closure_to_fn_coercion,
169+
cmpxchg16b_target_feature,
114170
cold,
171+
compile_error,
115172
compiler_builtins,
173+
concat_idents,
174+
conservative_impl_trait,
175+
console,
176+
const_compare_raw_pointers,
177+
const_fn,
178+
const_fn_union,
179+
const_generics,
180+
const_indexing,
181+
const_let,
182+
const_panic,
183+
const_raw_ptr_deref,
184+
const_raw_ptr_to_usize_cast,
185+
const_transmute,
186+
contents,
187+
convert,
188+
copy_closures,
189+
core,
190+
core_intrinsics,
116191
crate_id,
192+
crate_in_paths,
117193
crate_name,
118194
crate_type,
195+
crate_visibility_modifier,
196+
custom_attribute,
197+
custom_derive,
198+
custom_inner_attributes,
199+
custom_test_frameworks,
200+
c_variadic,
201+
decl_macro,
119202
default_lib_allocator,
203+
default_type_parameter_fallback,
204+
default_type_params,
120205
deny,
121206
deprecated,
122207
derive,
123208
doc,
209+
doc_alias,
210+
doc_cfg,
211+
doc_keyword,
212+
doc_masked,
213+
doc_spotlight,
214+
document_private_items,
215+
dotdoteq_in_patterns,
216+
dotdot_in_tuple_patterns,
217+
dropck_eyepatch,
218+
dropck_parametricity,
219+
drop_types_in_const,
220+
dylib,
221+
dyn_trait,
222+
eh_personality,
223+
eh_unwind_resume,
224+
enable,
225+
Err,
226+
except,
227+
exclusive_range_pattern,
228+
exhaustive_integer_patterns,
229+
exhaustive_patterns,
230+
existential_type,
231+
expected,
124232
export_name,
233+
extern_absolute_paths,
234+
external_doc,
235+
extern_crate_item_prelude,
236+
extern_crate_self,
237+
extern_in_paths,
238+
extern_prelude,
239+
extern_types,
240+
f16c_target_feature,
125241
feature,
126242
ffi_returns_twice,
243+
field_init_shorthand,
244+
file,
245+
fn_must_use,
127246
forbid,
247+
format_args_nl,
248+
from,
249+
From,
250+
from_error,
251+
from_generator,
252+
from_ok,
128253
fundamental,
254+
future,
255+
Future,
256+
generators,
257+
generic_associated_types,
258+
generic_param_attrs,
129259
global_allocator,
260+
global_asm,
261+
globs,
262+
hexagon_target_feature,
263+
hidden,
264+
homogeneous_aggregate,
265+
html_favicon_url,
266+
html_logo_url,
267+
html_no_source,
268+
html_playground_url,
269+
html_root_url,
270+
i128,
271+
i128_type,
272+
i16,
273+
i32,
274+
i64,
275+
i8,
276+
ident,
277+
if_let,
278+
if_while_or_patterns,
130279
ignore,
280+
impl_header_lifetime_elision,
281+
impl_trait_in_bindings,
282+
import_shadowing,
283+
in_band_lifetimes,
131284
include,
285+
inclusive_range_syntax,
286+
infer_outlives_requirements,
287+
infer_static_outlives_requirements,
132288
inline,
289+
intel,
290+
into_iter,
291+
IntoIterator,
292+
into_result,
293+
intrinsics,
294+
irrefutable_let_patterns,
295+
isize,
296+
issue,
297+
issue_5723_bootstrap,
298+
issue_tracker_base_url,
299+
item_like_imports,
300+
iter,
301+
Iterator,
133302
keyword,
303+
kind,
304+
label,
305+
label_break_value,
134306
lang,
307+
lang_items,
308+
lib,
135309
link,
310+
linkage,
136311
link_args,
312+
link_cfg,
313+
link_llvm_intrinsics,
137314
link_name,
138315
link_section,
139-
linkage,
316+
lint_reasons,
317+
local_inner_macros,
318+
log_syntax,
319+
loop_break_value,
320+
macro_at_most_once_rep,
140321
macro_escape,
141322
macro_export,
323+
macro_lifetime_matcher,
324+
macro_literal_matcher,
325+
macro_reexport,
326+
macro_rules,
327+
macros_in_extern,
142328
macro_use,
329+
macro_vis_matcher,
143330
main,
331+
managed_boxes,
144332
marker,
333+
marker_trait_attr,
145334
masked,
335+
match_beginning_vert,
336+
match_default_bindings,
146337
may_dangle,
338+
message,
339+
min_const_fn,
340+
min_const_unsafe_fn,
341+
mips_target_feature,
342+
mmx_target_feature,
343+
module,
344+
more_struct_aliases,
345+
movbe_target_feature,
147346
must_use,
148347
naked,
348+
naked_functions,
349+
name,
149350
needs_allocator,
150351
needs_panic_runtime,
352+
negate_unsigned,
353+
never,
354+
never_type,
355+
next,
356+
nll,
151357
no_builtins,
152358
no_core,
359+
no_crate_inject,
153360
no_debug,
361+
no_default_passes,
154362
no_implicit_prelude,
363+
no_inline,
155364
no_link,
156365
no_main,
157366
no_mangle,
367+
non_ascii_idents,
368+
None,
369+
non_exhaustive,
370+
non_modrs_mods,
371+
no_stack_check,
158372
no_start,
159373
no_std,
160-
non_exhaustive,
374+
not,
375+
note,
376+
Ok,
161377
omit_gdb_pretty_printer_section,
378+
on,
379+
on_unimplemented,
380+
oom,
381+
ops,
162382
optimize,
383+
optimize_attribute,
384+
optin_builtin_traits,
385+
option,
386+
Option,
387+
opt_out_copy,
388+
overlapping_marker_traits,
389+
packed,
163390
panic_handler,
391+
panic_impl,
392+
panic_implementation,
164393
panic_runtime,
394+
passes,
165395
path,
396+
pattern_parentheses,
397+
Pending,
398+
pin,
399+
Pin,
400+
platform_intrinsics,
166401
plugin,
167402
plugin_registrar,
403+
plugins,
404+
Poll,
405+
poll_with_tls_context,
406+
powerpc_target_feature,
407+
precise_pointer_size_matching,
408+
prelude,
168409
prelude_import,
410+
primitive,
411+
proc_dash_macro: "proc-macro",
169412
proc_macro,
170413
proc_macro_attribute,
171414
proc_macro_derive,
415+
proc_macro_expr,
416+
proc_macro_gen,
417+
proc_macro_hygiene,
418+
proc_macro_mod,
419+
proc_macro_non_items,
420+
proc_macro_path_invoc,
172421
profiler_runtime,
422+
pub_restricted,
423+
pushpop_unsafe,
424+
quad_precision_float,
425+
question_mark,
426+
quote,
427+
Range,
428+
RangeFrom,
429+
RangeFull,
430+
RangeInclusive,
431+
RangeTo,
432+
RangeToInclusive,
433+
raw_identifiers,
434+
Ready,
435+
reason,
173436
recursion_limit,
174437
reexport_test_harness_main,
438+
reflect,
439+
relaxed_adts,
175440
repr,
441+
repr128,
442+
repr_align,
443+
repr_align_enum,
444+
repr_packed,
445+
repr_simd,
446+
repr_transparent,
447+
re_rebalance_coherence,
448+
result,
449+
Result,
450+
Return,
451+
rlib,
452+
rtm_target_feature,
453+
rust,
454+
rust_2015_preview,
455+
rust_2018_preview,
456+
rust_begin_unwind,
457+
rustc_allocator_nounwind,
458+
rustc_allow_const_fn_ptr,
176459
rustc_args_required_const,
460+
rustc_attrs,
177461
rustc_clean,
178462
rustc_const_unstable,
179463
rustc_conversion_suggestion,
180464
rustc_copy_clone_marker,
181465
rustc_def_path,
182466
rustc_deprecated,
467+
rustc_diagnostic_macros,
183468
rustc_dirty,
469+
rustc_doc_only_macro,
470+
rustc_dump_env_program_clauses,
184471
rustc_dump_program_clauses,
185472
rustc_dump_user_substs,
186473
rustc_error,
@@ -191,37 +478,130 @@ symbols! {
191478
rustc_layout_scalar_valid_range_end,
192479
rustc_layout_scalar_valid_range_start,
193480
rustc_mir,
481+
rustc_object_lifetime_default,
194482
rustc_on_unimplemented,
195483
rustc_outlives,
196484
rustc_paren_sugar,
197485
rustc_partition_codegened,
198486
rustc_partition_reused,
487+
rustc_peek,
488+
rustc_peek_definite_init,
489+
rustc_peek_maybe_init,
490+
rustc_peek_maybe_uninit,
491+
rustc_private,
199492
rustc_proc_macro_decls,
493+
rustc_promotable,
200494
rustc_regions,
495+
rustc_stable,
201496
rustc_std_internal_symbol,
202497
rustc_symbol_name,
203498
rustc_synthetic,
204499
rustc_test_marker,
205500
rustc_then_this_would_need,
206501
rustc_transparent_macro,
207502
rustc_variance,
503+
rustdoc,
504+
rust_eh_personality,
505+
rust_eh_unwind_resume,
506+
rust_oom,
507+
__rust_unstable_column,
508+
rvalue_static_promotion,
208509
sanitizer_runtime,
510+
self_in_typedefs,
511+
self_struct_ctor,
512+
Send,
209513
should_panic,
210514
simd,
515+
simd_ffi,
516+
since,
517+
size,
518+
slice_patterns,
519+
slicing_syntax,
520+
Some,
521+
specialization,
522+
speed,
211523
spotlight,
524+
sse4a_target_feature,
212525
stable,
526+
staged_api,
213527
start,
528+
static_in_const,
529+
staticlib,
530+
static_nobundle,
531+
static_recursion,
532+
std,
533+
stmt_expr_attributes,
534+
stop_after_dataflow,
535+
struct_field_attributes,
536+
struct_inherit,
214537
structural_match,
538+
struct_variant,
539+
suggestion,
215540
target_feature,
541+
target_has_atomic,
542+
target_thread_local,
543+
task,
544+
tbm_target_feature,
545+
termination_trait,
546+
termination_trait_test,
547+
test,
548+
test_2018_feature,
549+
test_accepted_feature,
550+
test_removed_feature,
216551
test_runner,
217552
thread_local,
553+
tool_attributes,
554+
tool_lints,
555+
trace_macros,
556+
trait_alias,
557+
transmute,
558+
transparent,
559+
trivial_bounds,
560+
Try,
561+
try_blocks,
562+
tuple_indexing,
563+
ty,
564+
type_alias_enum_variants,
565+
type_ascription,
218566
type_length_limit,
567+
type_macros,
568+
u128,
569+
u16,
570+
u32,
571+
u64,
572+
u8,
573+
unboxed_closures,
574+
underscore_const_names,
575+
underscore_imports,
576+
underscore_lifetimes,
577+
uniform_paths,
578+
universal_impl_trait,
579+
unmarked_api,
580+
unrestricted_attribute_tokens,
219581
unsafe_destructor_blind_to_params,
582+
unsafe_no_drop_flag,
583+
unsized_locals,
584+
unsized_tuple_coercion,
220585
unstable,
586+
untagged_unions,
221587
unwind,
588+
unwind_attributes,
222589
used,
590+
use_extern_macros,
591+
use_nested_groups,
592+
usize,
593+
v1,
594+
vis,
595+
visible_private_types,
596+
volatile,
223597
warn,
598+
warn_directory_ownership,
599+
wasm_import_module,
600+
wasm_target_feature,
601+
while_let,
602+
windows,
224603
windows_subsystem,
604+
Yield,
225605
}
226606
}
227607

0 commit comments

Comments
 (0)
Please sign in to comment.