Rollup merge of #64243 - petrochenkov:cmdattr, r=alexcrichton
Move injection of attributes from command line to `libsyntax_ext` Just a tiny bit of code generation that wasn't moved into `libsyntax_ext` in https://github.com/rust-lang/rust/pull/62771.
This commit is contained in:
30
src/libsyntax_ext/cmdline_attrs.rs
Normal file
30
src/libsyntax_ext/cmdline_attrs.rs
Normal file
@@ -0,0 +1,30 @@
|
||||
//! Attributes injected into the crate root from command line using `-Z crate-attr`.
|
||||
|
||||
use syntax::ast::{self, AttrStyle};
|
||||
use syntax::attr::mk_attr;
|
||||
use syntax::panictry;
|
||||
use syntax::parse::{self, token, ParseSess};
|
||||
use syntax_pos::FileName;
|
||||
|
||||
pub fn inject(mut krate: ast::Crate, parse_sess: &ParseSess, attrs: &[String]) -> ast::Crate {
|
||||
for raw_attr in attrs {
|
||||
let mut parser = parse::new_parser_from_source_str(
|
||||
parse_sess,
|
||||
FileName::cli_crate_attr_source_code(&raw_attr),
|
||||
raw_attr.clone(),
|
||||
);
|
||||
|
||||
let start_span = parser.token.span;
|
||||
let (path, tokens) = panictry!(parser.parse_meta_item_unrestricted());
|
||||
let end_span = parser.token.span;
|
||||
if parser.token != token::Eof {
|
||||
parse_sess.span_diagnostic
|
||||
.span_err(start_span.to(end_span), "invalid crate attribute");
|
||||
continue;
|
||||
}
|
||||
|
||||
krate.attrs.push(mk_attr(AttrStyle::Inner, path, tokens, start_span.to(end_span)));
|
||||
}
|
||||
|
||||
krate
|
||||
}
|
||||
@@ -40,6 +40,7 @@ mod source_util;
|
||||
mod test;
|
||||
mod trace_macros;
|
||||
|
||||
pub mod cmdline_attrs;
|
||||
pub mod plugin_macro_defs;
|
||||
pub mod proc_macro_harness;
|
||||
pub mod standard_library_imports;
|
||||
|
||||
Reference in New Issue
Block a user