@@ -2463,9 +2463,10 @@ pub const STDLIB_STABLE_CRATES: &[Symbol] = &[sym::std, sym::core, sym::alloc, s
2463
2463
2464
2464
#[ derive( Copy , Clone , Eq , HashStable_Generic , Encodable , Decodable ) ]
2465
2465
pub struct Ident {
2466
- // `name` should never be the empty symbol. If you are considering that,
2467
- // you are probably conflating "empty identifier with "no identifier" and
2468
- // you should use `Option<Ident>` instead.
2466
+ /// `name` should never be the empty symbol. If you are considering that,
2467
+ /// you are probably conflating "empty identifier with "no identifier" and
2468
+ /// you should use `Option<Ident>` instead.
2469
+ /// Trying to construct an `Ident` with an empty name will trigger debug assertions.
2469
2470
pub name : Symbol ,
2470
2471
pub span : Span ,
2471
2472
}
@@ -2508,6 +2509,8 @@ impl Ident {
2508
2509
Ident :: new ( self . name , span. with_ctxt ( self . span . ctxt ( ) ) )
2509
2510
}
2510
2511
2512
+ /// Creates a new ident with the same span and name with leading quote removed, if any.
2513
+ /// If called on an empty ident, or with name just a single quote, returns an empty ident which is invalid.
2511
2514
pub fn without_first_quote ( self ) -> Ident {
2512
2515
Ident :: new ( Symbol :: intern ( self . as_str ( ) . trim_start_matches ( '\'' ) ) , self . span )
2513
2516
}
@@ -3095,10 +3098,15 @@ impl Ident {
3095
3098
}
3096
3099
3097
3100
pub fn is_raw_lifetime_guess ( self ) -> bool {
3098
- let name_without_apostrophe = self . without_first_quote ( ) ;
3099
- name_without_apostrophe. name != self . name
3100
- && name_without_apostrophe. name . can_be_raw ( )
3101
- && name_without_apostrophe. is_reserved_lifetime ( )
3101
+ // Check that the name isn't just a single quote.
3102
+ // `self.without_first_quote()` would return empty ident, which triggers debug assert.
3103
+ if self . name . as_str ( ) == "'" {
3104
+ return false ;
3105
+ }
3106
+ let ident_without_apostrophe = self . without_first_quote ( ) ;
3107
+ ident_without_apostrophe. name != self . name
3108
+ && ident_without_apostrophe. name . can_be_raw ( )
3109
+ && ident_without_apostrophe. is_reserved_lifetime ( )
3102
3110
}
3103
3111
3104
3112
pub fn guess_print_mode ( self ) -> IdentPrintMode {
0 commit comments