about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorDylan DPC <dylan.dpc@gmail.com>2020-02-28 01:55:42 +0100
committerGitHub <noreply@github.com>2020-02-28 01:55:42 +0100
commitffe4af57118bfb5063fc8015a1feddc76a607dbf (patch)
tree38503f991333264cbfe347ee7767a04f53c69d46 /src
parentab45408a4c0a3ce065c3c11369e3d97220c97de6 (diff)
parent6ce5ab6a7e566932ad1e3987ae7645eb0125dfe5 (diff)
downloadrust-ffe4af57118bfb5063fc8015a1feddc76a607dbf.tar.gz
rust-ffe4af57118bfb5063fc8015a1feddc76a607dbf.zip
Rollup merge of #69491 - petrochenkov:symprint, r=Mark-Simulacrum
rustc_span: Add `Symbol::to_ident_string` for use in diagnostic messages

Covers the same error reporting use case (https://github.com/rust-lang/rust/pull/69387#discussion_r382999205) as the `Display` impl for `Ident`.
cc https://github.com/rust-lang/rust/issues/69053

Follow-up to https://github.com/rust-lang/rust/pull/69387.
r? @Mark-Simulacrum
Diffstat (limited to 'src')
-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 {