mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-03 04:04:06 +00:00
ast: add an as_str
method to Ident
This is technically unsafe but interned strings are considered immortal.
This commit is contained in:
parent
c8a02527ae
commit
bf04a7ccb1
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user