@@ -33,6 +33,15 @@ symbols! {
33
33
// Special reserved identifiers used internally for elided lifetimes,
34
34
// unnamed method parameters, crate root module, error recovery etc.
35
35
// Matching predicates: `is_any_keyword`, `is_special`/`is_reserved`
36
+ //
37
+ // Notes about `kw::Empty`:
38
+ // - Its use can blur the lines between "empty symbol" and "no symbol".
39
+ // Using `Option<Symbol>` is preferable, where possible, because that
40
+ // is unambiguous.
41
+ // - For dummy symbols that are never used and absolutely must be
42
+ // present, it's better to use `sym::dummy` than `kw::Empty`, because
43
+ // it's clearer that it's intended as a dummy value, and more likely
44
+ // to be detected if it accidentally does get used.
36
45
Empty : "" ,
37
46
PathRoot : "{{root}}" ,
38
47
DollarCrate : "$crate" ,
@@ -834,6 +843,7 @@ symbols! {
834
843
drop_types_in_const,
835
844
dropck_eyepatch,
836
845
dropck_parametricity,
846
+ dummy: "<!dummy!>" , // use this instead of `kw::Empty` for symbols that won't be used
837
847
dummy_cgu_name,
838
848
dylib,
839
849
dyn_compatible_for_dispatch,
@@ -2305,11 +2315,23 @@ impl Ident {
2305
2315
Ident :: new ( name, DUMMY_SP )
2306
2316
}
2307
2317
2318
+ /// This is best avoided, because it blurs the lines between "empty
2319
+ /// identifier" and "no identifier". Using `Option<Ident>` is preferable,
2320
+ /// where possible, because that is unambiguous.
2308
2321
#[ inline]
2309
2322
pub fn empty ( ) -> Ident {
2310
2323
Ident :: with_dummy_span ( kw:: Empty )
2311
2324
}
2312
2325
2326
+ // For dummy identifiers that are never used and absolutely must be
2327
+ // present, it's better to use `Ident::dummy` than `Ident::Empty`, because
2328
+ // it's clearer that it's intended as a dummy value, and more likely to be
2329
+ // detected if it accidentally does get used.
2330
+ #[ inline]
2331
+ pub fn dummy ( ) -> Ident {
2332
+ Ident :: with_dummy_span ( sym:: dummy)
2333
+ }
2334
+
2313
2335
/// Maps a string to an identifier with a dummy span.
2314
2336
pub fn from_str ( string : & str ) -> Ident {
2315
2337
Ident :: with_dummy_span ( Symbol :: intern ( string) )
0 commit comments