@@ -33,6 +33,15 @@ symbols! {
3333 // Special reserved identifiers used internally for elided lifetimes,
3434 // unnamed method parameters, crate root module, error recovery etc.
3535 // 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.
3645 Empty : "" ,
3746 PathRoot : "{{root}}" ,
3847 DollarCrate : "$crate" ,
@@ -833,6 +842,7 @@ symbols! {
833842 drop_types_in_const,
834843 dropck_eyepatch,
835844 dropck_parametricity,
845+ dummy: "<!dummy!>" , // use this instead of `kw::Empty` for symbols that won't be used
836846 dummy_cgu_name,
837847 dylib,
838848 dyn_compatible_for_dispatch,
@@ -2303,11 +2313,23 @@ impl Ident {
23032313 Ident :: new ( name, DUMMY_SP )
23042314 }
23052315
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.
23062319 #[ inline]
23072320 pub fn empty ( ) -> Ident {
23082321 Ident :: with_dummy_span ( kw:: Empty )
23092322 }
23102323
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+
23112333 /// Maps a string to an identifier with a dummy span.
23122334 pub fn from_str ( string : & str ) -> Ident {
23132335 Ident :: with_dummy_span ( Symbol :: intern ( string) )
0 commit comments