1
Fork 0

expand: Turn ast::Crate into a first class expansion target

And stop creating a fake `mod` item for the crate root when expanding a crate.
This commit is contained in:
Vadim Petrochenkov 2021-10-17 19:32:34 +03:00
parent 4919988fe1
commit 141c6cc78e
20 changed files with 203 additions and 159 deletions

View file

@ -326,6 +326,12 @@ pub fn fake_token_stream(sess: &ParseSess, nt: &Nonterminal) -> TokenStream {
parse_stream_from_source_str(filename, source, sess, Some(nt.span()))
}
pub fn fake_token_stream_for_crate(sess: &ParseSess, krate: &ast::Crate) -> TokenStream {
let source = pprust::crate_to_string_for_macros(krate);
let filename = FileName::macro_expansion_source_code(&source);
parse_stream_from_source_str(filename, source, sess, Some(krate.span))
}
pub fn parse_cfg_attr(
attr: &Attribute,
parse_sess: &ParseSess,