@@ -2510,12 +2510,24 @@ impl Ident {
2510
2510
Ident :: new ( self . name , span. with_ctxt ( self . span . ctxt ( ) ) )
2511
2511
}
2512
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.
2513
+ /// Creates a new ident with the same span and name with leading quotes removed, if any.
2514
+ /// If called on an empty ident, or with name just single quotes, returns an empty ident which is invalid.
2515
+ /// Creating empty ident will trigger debug assertions.
2516
+ /// Use `without_first_quote_checked` instead if not certain this will return valid ident.
2515
2517
pub fn without_first_quote ( self ) -> Ident {
2516
2518
Ident :: new ( Symbol :: intern ( self . as_str ( ) . trim_start_matches ( '\'' ) ) , self . span )
2517
2519
}
2518
2520
2521
+ /// Creates a new ident with the same span and name with leading quotes removed, if any.
2522
+ /// If called on an empty ident, or with name just single quotes, returns `None`.
2523
+ /// If you are certain this will return valid ident, use `without_first_quote` instead.
2524
+ pub fn without_first_quote_checked ( self ) -> Option < Ident > {
2525
+ match Symbol :: intern ( self . as_str ( ) . trim_start_matches ( '\'' ) ) {
2526
+ sym:: empty => None ,
2527
+ name => Some ( Ident :: new ( name, self . span ) ) ,
2528
+ }
2529
+ }
2530
+
2519
2531
/// "Normalize" ident for use in comparisons using "item hygiene".
2520
2532
/// Identifiers with same string value become same if they came from the same macro 2.0 macro
2521
2533
/// (e.g., `macro` item, but not `macro_rules` item) and stay different if they came from
@@ -3099,15 +3111,16 @@ impl Ident {
3099
3111
}
3100
3112
3101
3113
pub fn is_raw_lifetime_guess ( self ) -> bool {
3102
- // Check that the name isn't just a single quote .
3114
+ // Ident name might be an empty string or just single quotes, so call checked function .
3103
3115
// `self.without_first_quote()` would return empty ident, which triggers debug assert.
3104
- if self . name . as_str ( ) == "'" {
3105
- return false ;
3116
+ match self . without_first_quote_checked ( ) {
3117
+ None => false ,
3118
+ Some ( ident_without_apostrophe) => {
3119
+ ident_without_apostrophe. name != self . name
3120
+ && ident_without_apostrophe. name . can_be_raw ( )
3121
+ && ident_without_apostrophe. is_reserved_lifetime ( )
3122
+ }
3106
3123
}
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 ( )
3111
3124
}
3112
3125
3113
3126
pub fn guess_print_mode ( self ) -> IdentPrintMode {
0 commit comments