@@ -2342,35 +2342,31 @@ pub const STDLIB_STABLE_CRATES: &[Symbol] = &[sym::std, sym::core, sym::alloc, s
2342
2342
2343
2343
#[ derive( Copy , Clone , Eq , HashStable_Generic , Encodable , Decodable ) ]
2344
2344
pub 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.
2345
2348
pub name : Symbol ,
2346
2349
pub span : Span ,
2347
2350
}
2348
2351
2349
2352
impl Ident {
2350
2353
#[ inline]
2351
2354
/// 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 ) ;
2353
2357
Ident { name, span }
2354
2358
}
2355
2359
2356
2360
/// Constructs a new identifier with a dummy span.
2357
2361
#[ inline]
2358
- pub const fn with_dummy_span ( name : Symbol ) -> Ident {
2362
+ pub fn with_dummy_span ( name : Symbol ) -> Ident {
2359
2363
Ident :: new ( name, DUMMY_SP )
2360
2364
}
2361
2365
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
-
2370
2366
// 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.
2374
2370
#[ inline]
2375
2371
pub fn dummy ( ) -> Ident {
2376
2372
Ident :: with_dummy_span ( sym:: dummy)
0 commit comments