@@ -2342,35 +2342,31 @@ pub const STDLIB_STABLE_CRATES: &[Symbol] = &[sym::std, sym::core, sym::alloc, s
23422342
23432343#[ derive( Copy , Clone , Eq , HashStable_Generic , Encodable , Decodable ) ]
23442344pub struct Ident {
2345+ // `name` should never be the empty symbol. If you are considering that,
2346+ // you are probably conflating "empty identifer with "no identifier" and
2347+ // you should use `Option<Ident>` instead.
23452348 pub name : Symbol ,
23462349 pub span : Span ,
23472350}
23482351
23492352impl Ident {
23502353 #[ inline]
23512354 /// Constructs a new identifier from a symbol and a span.
2352- pub const fn new ( name : Symbol , span : Span ) -> Ident {
2355+ pub fn new ( name : Symbol , span : Span ) -> Ident {
2356+ assert_ne ! ( name, kw:: Empty ) ;
23532357 Ident { name, span }
23542358 }
23552359
23562360 /// Constructs a new identifier with a dummy span.
23572361 #[ inline]
2358- pub const fn with_dummy_span ( name : Symbol ) -> Ident {
2362+ pub fn with_dummy_span ( name : Symbol ) -> Ident {
23592363 Ident :: new ( name, DUMMY_SP )
23602364 }
23612365
2362- /// This is best avoided, because it blurs the lines between "empty
2363- /// identifier" and "no identifier". Using `Option<Ident>` is preferable,
2364- /// where possible, because that is unambiguous.
2365- #[ inline]
2366- pub fn empty ( ) -> Ident {
2367- Ident :: with_dummy_span ( kw:: Empty )
2368- }
2369-
23702366 // For dummy identifiers that are never used and absolutely must be
2371- // present, it's better to use `Ident::dummy` than `Ident::Empty`, because
2372- // it's clearer that it's intended as a dummy value, and more likely to be
2373- // detected if it accidentally does get used.
2367+ // present. Note that this does *not* use the empty symbol; `sym::dummy`
2368+ // makes it clear that it's intended as a dummy value, and is more likely
2369+ // to be detected if it accidentally does get used.
23742370 #[ inline]
23752371 pub fn dummy ( ) -> Ident {
23762372 Ident :: with_dummy_span ( sym:: dummy)
0 commit comments