@@ -2463,9 +2463,10 @@ pub const STDLIB_STABLE_CRATES: &[Symbol] = &[sym::std, sym::core, sym::alloc, s
24632463
24642464#[ derive( Copy , Clone , Eq , HashStable_Generic , Encodable , Decodable ) ]
24652465pub 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.
24692470 pub name : Symbol ,
24702471 pub span : Span ,
24712472}
@@ -2508,6 +2509,8 @@ impl Ident {
25082509 Ident :: new ( self . name , span. with_ctxt ( self . span . ctxt ( ) ) )
25092510 }
25102511
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.
25112514 pub fn without_first_quote ( self ) -> Ident {
25122515 Ident :: new ( Symbol :: intern ( self . as_str ( ) . trim_start_matches ( '\'' ) ) , self . span )
25132516 }
@@ -3095,10 +3098,15 @@ impl Ident {
30953098 }
30963099
30973100 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 ( )
31023110 }
31033111
31043112 pub fn guess_print_mode ( self ) -> IdentPrintMode {
0 commit comments