about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>2020-02-26 21:24:22 +0300
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>2020-02-26 22:02:43 +0300
commit6ce5ab6a7e566932ad1e3987ae7645eb0125dfe5 (patch)
treee638ee90e0a24aa5474f1f21b707b22273c623f3
parent892cb143e5984f220e6b26b48d972bd1f4644298 (diff)
downloadrust-6ce5ab6a7e566932ad1e3987ae7645eb0125dfe5.tar.gz
rust-6ce5ab6a7e566932ad1e3987ae7645eb0125dfe5.zip
rustc_span: Add `Symbol::to_ident_string` for use in diagnostic messages
-rw-r--r--src/librustc_span/symbol.rs8
1 files changed, 8 insertions, 0 deletions
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 @@ impl Symbol {
     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 {