@@ -187,8 +187,9 @@ pub fn literal_to_string(lit: token::Lit) -> String {
187
187
out
188
188
}
189
189
190
- fn ident_to_string ( ident : ast:: Ident , is_raw : bool ) -> String {
191
- ident_to_string_ext ( ident. name , is_raw, Some ( ident. span ) )
190
+ /// Print an ident from AST, `$crate` is converted into its respective crate name.
191
+ fn ast_ident_to_string ( ident : ast:: Ident , is_raw : bool ) -> String {
192
+ ident_to_string ( ident. name , is_raw, Some ( ident. span ) )
192
193
}
193
194
194
195
// AST pretty-printer is used as a fallback for turning AST structures into token streams for
@@ -202,9 +203,7 @@ fn ident_to_string(ident: ast::Ident, is_raw: bool) -> String {
202
203
// but not otherwise. Pretty-printing is the only way for proc macros to discover token contents,
203
204
// so we should not perform this lossy conversion if the top level call to the pretty-printer was
204
205
// done for a token stream or a single token.
205
- fn ident_to_string_ext (
206
- name : ast:: Name , is_raw : bool , convert_dollar_crate : Option < Span >
207
- ) -> String {
206
+ fn ident_to_string ( name : ast:: Name , is_raw : bool , convert_dollar_crate : Option < Span > ) -> String {
208
207
if is_raw {
209
208
format ! ( "r#{}" , name)
210
209
} else {
@@ -222,6 +221,7 @@ fn ident_to_string_ext(
222
221
}
223
222
}
224
223
224
+ /// Print the token kind precisely, without converting `$crate` into its respective crate name.
225
225
pub fn token_kind_to_string ( tok : & TokenKind ) -> String {
226
226
token_kind_to_string_ext ( tok, None )
227
227
}
@@ -272,7 +272,7 @@ fn token_kind_to_string_ext(tok: &TokenKind, convert_dollar_crate: Option<Span>)
272
272
token:: Literal ( lit) => literal_to_string ( lit) ,
273
273
274
274
/* Name components */
275
- token:: Ident ( s, is_raw) => ident_to_string_ext ( s, is_raw, convert_dollar_crate) ,
275
+ token:: Ident ( s, is_raw) => ident_to_string ( s, is_raw, convert_dollar_crate) ,
276
276
token:: Lifetime ( s) => s. to_string ( ) ,
277
277
278
278
/* Other */
@@ -286,6 +286,7 @@ fn token_kind_to_string_ext(tok: &TokenKind, convert_dollar_crate: Option<Span>)
286
286
}
287
287
}
288
288
289
+ /// Print the token precisely, without converting `$crate` into its respective crate name.
289
290
pub fn token_to_string ( token : & Token ) -> String {
290
291
token_to_string_ext ( token, false )
291
292
}
@@ -305,7 +306,7 @@ crate fn nonterminal_to_string(nt: &Nonterminal) -> String {
305
306
token:: NtBlock ( ref e) => block_to_string ( e) ,
306
307
token:: NtStmt ( ref e) => stmt_to_string ( e) ,
307
308
token:: NtPat ( ref e) => pat_to_string ( e) ,
308
- token:: NtIdent ( e, is_raw) => ident_to_string ( e, is_raw) ,
309
+ token:: NtIdent ( e, is_raw) => ast_ident_to_string ( e, is_raw) ,
309
310
token:: NtLifetime ( e) => e. to_string ( ) ,
310
311
token:: NtLiteral ( ref e) => expr_to_string ( e) ,
311
312
token:: NtTT ( ref tree) => tt_to_string ( tree. clone ( ) ) ,
@@ -601,7 +602,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target=pp::Printer> + std::ops::DerefM
601
602
self . word ( "::" ) ;
602
603
}
603
604
if segment. ident . name != kw:: PathRoot {
604
- self . word ( ident_to_string ( segment. ident , segment. ident . is_raw_guess ( ) ) ) ;
605
+ self . word ( ast_ident_to_string ( segment. ident , segment. ident . is_raw_guess ( ) ) ) ;
605
606
}
606
607
}
607
608
}
@@ -2205,7 +2206,7 @@ impl<'a> State<'a> {
2205
2206
}
2206
2207
2207
2208
crate fn print_ident ( & mut self , ident : ast:: Ident ) {
2208
- self . s . word ( ident_to_string ( ident, ident. is_raw_guess ( ) ) ) ;
2209
+ self . s . word ( ast_ident_to_string ( ident, ident. is_raw_guess ( ) ) ) ;
2209
2210
self . ann . post ( self , AnnNode :: Ident ( & ident) )
2210
2211
}
2211
2212
0 commit comments