From bf04a7ccb1c1d23478885ea4f67fad374ffe0a72 Mon Sep 17 00:00:00 2001 From: Corey Richardson Date: Thu, 3 Jul 2014 00:45:59 -0700 Subject: [PATCH] ast: add an `as_str` method to Ident This is technically unsafe but interned strings are considered immortal. --- src/libsyntax/ast.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index d96f1393bc91..b9bb05d1950c 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 {