]> git.lizzy.rs Git - rust.git/commitdiff
ast: add an `as_str` method to Ident
authorCorey Richardson <corey@octayn.net>
Thu, 3 Jul 2014 07:45:59 +0000 (00:45 -0700)
committerCorey Richardson <corey@octayn.net>
Wed, 9 Jul 2014 07:06:29 +0000 (00:06 -0700)
This is technically unsafe but interned strings are considered immortal.

src/libsyntax/ast.rs

index d96f1393bc9174dba73b662d0c29e37a93171bdc..b9bb05d1950cc6147e372d21dc478bb0f5af3240 100644 (file)
@@ -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 {