@@ -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 gets used.
36
45
Empty : "" ,
37
46
PathRoot : "{{root}}" ,
38
47
DollarCrate : "$crate" ,
@@ -833,6 +842,7 @@ symbols! {
833
842
drop_types_in_const,
834
843
dropck_eyepatch,
835
844
dropck_parametricity,
845
+ dummy: "<!dummy!>" , // use this instead of `kw::Empty` for symbols that won't be used
836
846
dummy_cgu_name,
837
847
dylib,
838
848
dyn_compatible_for_dispatch,
@@ -2303,11 +2313,23 @@ impl Ident {
2303
2313
Ident :: new ( name, DUMMY_SP )
2304
2314
}
2305
2315
2316
+ /// This is best avoided, because it blurs the lines between "empty
2317
+ /// identifier" and "no identifier". Using `Option<Ident>` is preferable,
2318
+ /// where possible, because that is unambiguous.
2306
2319
#[ inline]
2307
2320
pub fn empty ( ) -> Ident {
2308
2321
Ident :: with_dummy_span ( kw:: Empty )
2309
2322
}
2310
2323
2324
+ // For dummy identifiers that are never used and absolutely must be
2325
+ // present, it's better to use `Ident::dummy` than `Ident::Empty`, because
2326
+ // it's clearer that it's intended as a dummy value, and more likely to be
2327
+ // detected if it accidentally does gets used.
2328
+ #[ inline]
2329
+ pub fn dummy ( ) -> Ident {
2330
+ Ident :: with_dummy_span ( sym:: dummy)
2331
+ }
2332
+
2311
2333
/// Maps a string to an identifier with a dummy span.
2312
2334
pub fn from_str ( string : & str ) -> Ident {
2313
2335
Ident :: with_dummy_span ( Symbol :: intern ( string) )
0 commit comments