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;
7 use syntax::sess::ParseSess;
8 use syntax_expand::panictry;
9 use syntax_pos::FileName;
11 pub fn inject(mut krate: ast::Crate, parse_sess: &ParseSess, attrs: &[String]) -> ast::Crate {
12 for raw_attr in attrs {
13 let mut parser = parse::new_parser_from_source_str(
15 FileName::cli_crate_attr_source_code(&raw_attr),
19 let start_span = parser.token.span;
20 let AttrItem { path, tokens } = panictry!(parser.parse_attr_item());
21 let end_span = parser.token.span;
22 if parser.token != token::Eof {
23 parse_sess.span_diagnostic
24 .span_err(start_span.to(end_span), "invalid crate attribute");
28 krate.attrs.push(mk_attr(AttrStyle::Inner, path, tokens, start_span.to(end_span)));