From 6ce5ab6a7e566932ad1e3987ae7645eb0125dfe5 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Wed, 26 Feb 2020 21:24:22 +0300 Subject: [PATCH] rustc_span: Add `Symbol::to_ident_string` for use in diagnostic messages --- src/librustc_span/symbol.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/librustc_span/symbol.rs b/src/librustc_span/symbol.rs index b8e5ea97f4e..d6232f32f4c 100644 --- a/src/librustc_span/symbol.rs +++ b/src/librustc_span/symbol.rs @@ -1023,6 +1023,14 @@ pub fn as_str(self) -> SymbolStr { pub fn as_u32(self) -> u32 { self.0.as_u32() } + + /// This method is supposed to be used in error messages, so it's expected to be + /// identical to printing the original identifier token written in source code + /// (`token_to_string`, `Ident::to_string`), except that symbols don't keep the rawness flag + /// or edition, so we have to guess the rawness using the global edition. + pub fn to_ident_string(self) -> String { + Ident::with_dummy_span(self).to_string() + } } impl fmt::Debug for Symbol {