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