1 //! Attributes injected into the crate root from command line using `-Z crate-attr`.
3 use syntax::ast::{self, AttrItem, AttrStyle};
4 use syntax::attr::mk_attr;
6 use syntax::sess::ParseSess;
7 use syntax_expand::panictry;
8 use syntax_pos::FileName;
10 pub fn inject(mut krate: ast::Crate, parse_sess: &ParseSess, attrs: &[String]) -> ast::Crate {
11 for raw_attr in attrs {
12 let mut parser = rustc_parse::new_parser_from_source_str(
14 FileName::cli_crate_attr_source_code(&raw_attr),
18 let start_span = parser.token.span;
19 let AttrItem { path, tokens } = panictry!(parser.parse_attr_item());
20 let end_span = parser.token.span;
21 if parser.token != token::Eof {
22 parse_sess.span_diagnostic
23 .span_err(start_span.to(end_span), "invalid crate attribute");
27 krate.attrs.push(mk_attr(AttrStyle::Inner, path, tokens, start_span.to(end_span)));