Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit d4ad322

Browse files
committed
Use maybe_whole! to streamline parse_item_common.
This requires changing `maybe_whole!` so it allows the value to be modified.
1 parent 8ac16c6 commit d4ad322

File tree

2 files changed

+11
-16
lines changed

2 files changed

+11
-16
lines changed

compiler/rustc_parse/src/parser/item.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use super::{
66
};
77
use crate::errors::{self, MacroExpandsToAdtField};
88
use crate::fluent_generated as fluent;
9+
use crate::maybe_whole;
910
use ast::token::IdentIsRaw;
1011
use rustc_ast::ast::*;
1112
use rustc_ast::ptr::P;
@@ -115,17 +116,10 @@ impl<'a> Parser<'a> {
115116
fn_parse_mode: FnParseMode,
116117
force_collect: ForceCollect,
117118
) -> PResult<'a, Option<Item>> {
118-
// Don't use `maybe_whole` so that we have precise control
119-
// over when we bump the parser
120-
if let token::Interpolated(nt) = &self.token.kind
121-
&& let token::NtItem(item) = &nt.0
122-
{
123-
let mut item = item.clone();
124-
self.bump();
125-
119+
maybe_whole!(self, NtItem, |item| {
126120
attrs.prepend_to_nt_inner(&mut item.attrs);
127-
return Ok(Some(item.into_inner()));
128-
};
121+
Some(item.into_inner())
122+
});
129123

130124
let item =
131125
self.collect_tokens_trailing_token(attrs, force_collect, |this: &mut Self, attrs| {

compiler/rustc_parse/src/parser/mod.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,13 @@ pub enum TrailingToken {
9393
#[macro_export]
9494
macro_rules! maybe_whole {
9595
($p:expr, $constructor:ident, |$x:ident| $e:expr) => {
96-
if let token::Interpolated(nt) = &$p.token.kind {
97-
if let token::$constructor(x) = &nt.0 {
98-
let $x = x.clone();
99-
$p.bump();
100-
return Ok($e);
101-
}
96+
if let token::Interpolated(nt) = &$p.token.kind
97+
&& let token::$constructor(x) = &nt.0
98+
{
99+
#[allow(unused_mut)]
100+
let mut $x = x.clone();
101+
$p.bump();
102+
return Ok($e);
102103
}
103104
};
104105
}

0 commit comments

Comments
 (0)