-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 #62771.
- Loading branch information
Showing
5 changed files
with
48 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters