diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 034be6a6864ce48de8baae31f305f726f86f5b52..ed28d5f33b92134e19ffa7d0ee0965cc4f768b09 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -22,6 +22,7 @@ use symbol::keywords; use syntax::parse::parse_stream_from_source_str; use syntax_pos::{self, Span, FileName}; +use syntax_pos::symbol::{self, Symbol}; use tokenstream::{TokenStream, TokenTree}; use tokenstream; @@ -478,7 +479,13 @@ pub fn glue(self, joint: Token) -> Option { _ => return None, }, SingleQuote => match joint { - Ident(ident, false) => Lifetime(ident), + Ident(ident, false) => { + let name = Symbol::intern(&format!("'{}", ident)); + Lifetime(symbol::Ident { + name, + span: ident.span, + }) + } _ => return None, }, diff --git a/src/test/run-pass-fulldeps/proc-macro/auxiliary/gen-lifetime-token.rs b/src/test/run-pass-fulldeps/proc-macro/auxiliary/gen-lifetime-token.rs new file mode 100644 index 0000000000000000000000000000000000000000..e288050a928b0ad1ddab1119d55e2cf3355e1fd9 --- /dev/null +++ b/src/test/run-pass-fulldeps/proc-macro/auxiliary/gen-lifetime-token.rs @@ -0,0 +1,35 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// no-prefer-dynamic + +#![crate_type = "proc-macro"] +#![feature(proc_macro)] + +extern crate proc_macro; + +use proc_macro::*; + +#[proc_macro] +pub fn bar(_input: TokenStream) -> TokenStream { + let mut ret = Vec::::new(); + ret.push(Ident::new("static", Span::call_site()).into()); + ret.push(Ident::new("FOO", Span::call_site()).into()); + ret.push(Punct::new(':', Spacing::Alone).into()); + ret.push(Punct::new('&', Spacing::Alone).into()); + ret.push(Punct::new('\'', Spacing::Joint).into()); + ret.push(Ident::new("static", Span::call_site()).into()); + ret.push(Ident::new("i32", Span::call_site()).into()); + ret.push(Punct::new('=', Spacing::Alone).into()); + ret.push(Punct::new('&', Spacing::Alone).into()); + ret.push(Literal::i32_unsuffixed(1).into()); + ret.push(Punct::new(';', Spacing::Alone).into()); + ret.into_iter().collect() +} diff --git a/src/test/run-pass-fulldeps/proc-macro/gen-lifetime-token.rs b/src/test/run-pass-fulldeps/proc-macro/gen-lifetime-token.rs new file mode 100644 index 0000000000000000000000000000000000000000..539e3aa8ecbb20e6a2e618fa71d5da417690f2e5 --- /dev/null +++ b/src/test/run-pass-fulldeps/proc-macro/gen-lifetime-token.rs @@ -0,0 +1,22 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// aux-build:gen-lifetime-token.rs + +#![feature(proc_macro)] + +extern crate gen_lifetime_token as bar; + +bar::bar!(); + +fn main() { + let x: &'static i32 = FOO; + assert_eq!(*x, 1); +}