about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorCorey Richardson <corey@octayn.net>2014-07-03 00:45:59 -0700
committerCorey Richardson <corey@octayn.net>2014-07-09 00:06:29 -0700
commitbf04a7ccb1c1d23478885ea4f67fad374ffe0a72 (patch)
treea4fca8ae295651c729a3dd4556db632a527d74d7 /src/libsyntax
parentc8a02527ae6364175c31a5447dd4e21bb6ac3488 (diff)
downloadrust-bf04a7ccb1c1d23478885ea4f67fad374ffe0a72.tar.gz
rust-bf04a7ccb1c1d23478885ea4f67fad374ffe0a72.zip
ast: add an `as_str` method to Ident
This is technically unsafe but interned strings are considered immortal.
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/ast.rs7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs
index d96f1393bc9..b9bb05d1950 100644
--- a/src/libsyntax/ast.rs
+++ b/src/libsyntax/ast.rs
@@ -50,6 +50,13 @@ pub struct Ident {
 impl Ident {
     /// Construct an identifier with the given name and an empty context:
     pub fn new(name: Name) -> Ident { Ident {name: name, ctxt: EMPTY_CTXT}}
+
+    pub fn as_str<'a>(&'a self) -> &'a str {
+        unsafe {
+            // FIXME #12938: can't use copy_lifetime since &str isn't a &T
+            ::std::mem::transmute(token::get_ident(*self).get())
+        }
+    }
 }
 
 impl Show for Ident {