proc_macro_plugin: Wrap nonexistent filename in <>

I'm not sure how big of an issue this can become in practice, but `FileMap`s made from something that's not a file are supposed to wrap the file name in `<>`.

For an example fix, see kevinmehall/rust-peg@332fd4dbae. There, it caused cargo to always recompile a crate using rust-peg, even when nothing was changed, because cargo sees that the dummy file doesn't exist.
This commit is contained in:
Jonas Schievink 2016-10-15 02:56:29 +02:00 committed by Jonas Schievink
parent 966c70085a
commit fb7a8294f8

View File

@ -15,12 +15,12 @@
use syntax::parse::{ParseSess, filemap_to_tts};
use syntax::tokenstream::TokenStream;
/// Map a string to tts, using a made-up filename. For example, `lex(15)` will return a
/// Map a string to tts, using a made-up filename. For example, `lex("15")` will return a
/// TokenStream containing the literal 15.
pub fn lex(source_str: &str) -> TokenStream {
let ps = ParseSess::new();
TokenStream::from_tts(filemap_to_tts(&ps,
ps.codemap().new_filemap("procmacro_lex".to_string(),
ps.codemap().new_filemap("<procmacro_lex>".to_string(),
None,
source_str.to_owned())))
}