Use maybe_whole!
to streamline parse_item_common
.
This requires changing `maybe_whole!` so it allows the value to be modified.
This commit is contained in:
parent
8ac16c6193
commit
d4ad322b5d
2 changed files with 11 additions and 16 deletions
|
@ -6,6 +6,7 @@ use super::{
|
||||||
};
|
};
|
||||||
use crate::errors::{self, MacroExpandsToAdtField};
|
use crate::errors::{self, MacroExpandsToAdtField};
|
||||||
use crate::fluent_generated as fluent;
|
use crate::fluent_generated as fluent;
|
||||||
|
use crate::maybe_whole;
|
||||||
use ast::token::IdentIsRaw;
|
use ast::token::IdentIsRaw;
|
||||||
use rustc_ast::ast::*;
|
use rustc_ast::ast::*;
|
||||||
use rustc_ast::ptr::P;
|
use rustc_ast::ptr::P;
|
||||||
|
@ -115,17 +116,10 @@ impl<'a> Parser<'a> {
|
||||||
fn_parse_mode: FnParseMode,
|
fn_parse_mode: FnParseMode,
|
||||||
force_collect: ForceCollect,
|
force_collect: ForceCollect,
|
||||||
) -> PResult<'a, Option<Item>> {
|
) -> PResult<'a, Option<Item>> {
|
||||||
// Don't use `maybe_whole` so that we have precise control
|
maybe_whole!(self, NtItem, |item| {
|
||||||
// over when we bump the parser
|
|
||||||
if let token::Interpolated(nt) = &self.token.kind
|
|
||||||
&& let token::NtItem(item) = &nt.0
|
|
||||||
{
|
|
||||||
let mut item = item.clone();
|
|
||||||
self.bump();
|
|
||||||
|
|
||||||
attrs.prepend_to_nt_inner(&mut item.attrs);
|
attrs.prepend_to_nt_inner(&mut item.attrs);
|
||||||
return Ok(Some(item.into_inner()));
|
Some(item.into_inner())
|
||||||
};
|
});
|
||||||
|
|
||||||
let item =
|
let item =
|
||||||
self.collect_tokens_trailing_token(attrs, force_collect, |this: &mut Self, attrs| {
|
self.collect_tokens_trailing_token(attrs, force_collect, |this: &mut Self, attrs| {
|
||||||
|
|
|
@ -93,13 +93,14 @@ pub enum TrailingToken {
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! maybe_whole {
|
macro_rules! maybe_whole {
|
||||||
($p:expr, $constructor:ident, |$x:ident| $e:expr) => {
|
($p:expr, $constructor:ident, |$x:ident| $e:expr) => {
|
||||||
if let token::Interpolated(nt) = &$p.token.kind {
|
if let token::Interpolated(nt) = &$p.token.kind
|
||||||
if let token::$constructor(x) = &nt.0 {
|
&& let token::$constructor(x) = &nt.0
|
||||||
let $x = x.clone();
|
{
|
||||||
|
#[allow(unused_mut)]
|
||||||
|
let mut $x = x.clone();
|
||||||
$p.bump();
|
$p.bump();
|
||||||
return Ok($e);
|
return Ok($e);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue