cfg_attr: avoid .outer_tokens
This commit is contained in:
parent
9630dbbc3c
commit
bbcda98d41
7 changed files with 178 additions and 76 deletions
|
@ -270,21 +270,13 @@ pub fn stream_to_parser_with_base_dir<'a>(
|
|||
}
|
||||
|
||||
/// Runs the given subparser `f` on the tokens of the given `attr`'s item.
|
||||
pub fn parse_in_attr<'a, T>(
|
||||
pub fn parse_in<'a, T>(
|
||||
sess: &'a ParseSess,
|
||||
attr: &ast::Attribute,
|
||||
tts: TokenStream,
|
||||
name: &'static str,
|
||||
mut f: impl FnMut(&mut Parser<'a>) -> PResult<'a, T>,
|
||||
) -> PResult<'a, T> {
|
||||
let mut parser = Parser::new(
|
||||
sess,
|
||||
// FIXME(#66940, Centril | petrochenkov): refactor this function so it doesn't
|
||||
// require reconstructing and immediately re-parsing delimiters.
|
||||
attr.get_normal_item().args.outer_tokens(),
|
||||
None,
|
||||
false,
|
||||
false,
|
||||
Some("attribute"),
|
||||
);
|
||||
let mut parser = Parser::new(sess, tts, None, false, false, Some(name));
|
||||
let result = f(&mut parser)?;
|
||||
if parser.token != token::Eof {
|
||||
parser.unexpected()?;
|
||||
|
@ -292,6 +284,17 @@ pub fn parse_in_attr<'a, T>(
|
|||
Ok(result)
|
||||
}
|
||||
|
||||
/// Runs the given subparser `f` on the tokens of the given `attr`'s item.
|
||||
pub fn parse_in_attr<'a, T>(
|
||||
sess: &'a ParseSess,
|
||||
attr: &ast::Attribute,
|
||||
f: impl FnMut(&mut Parser<'a>) -> PResult<'a, T>,
|
||||
) -> PResult<'a, T> {
|
||||
// FIXME(#66940, Centril | petrochenkov): refactor this function so it doesn't
|
||||
// require reconstructing and immediately re-parsing delimiters.
|
||||
parse_in(sess, attr.get_normal_item().args.outer_tokens(), "attribute", f)
|
||||
}
|
||||
|
||||
// NOTE(Centril): The following probably shouldn't be here but it acknowledges the
|
||||
// fact that architecturally, we are using parsing (read on below to understand why).
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue