Skip to content

Commit 842027f

Browse files
committed
parse: NtItem -> parse_item_common.
1 parent b01c1e2 commit 842027f

File tree

2 files changed

+43
-8
lines changed

2 files changed

+43
-8
lines changed

src/librustc_parse/parser/item.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,10 @@ impl<'a> Parser<'a> {
3131

3232
pub(super) fn parse_item_(
3333
&mut self,
34-
mut attrs: Vec<Attribute>,
34+
attrs: Vec<Attribute>,
3535
macros_allowed: bool,
3636
attributes_allowed: bool,
3737
) -> PResult<'a, Option<P<Item>>> {
38-
maybe_whole!(self, NtItem, |item| {
39-
let mut item = item;
40-
mem::swap(&mut item.attrs, &mut attrs);
41-
item.attrs.extend(attrs);
42-
Some(item)
43-
});
4438
let item = self.parse_item_common(attrs, macros_allowed, attributes_allowed, |_| true)?;
4539
if let Some(ref item) = item {
4640
self.error_on_illegal_default(item.defaultness);
@@ -50,11 +44,18 @@ impl<'a> Parser<'a> {
5044

5145
fn parse_item_common(
5246
&mut self,
53-
attrs: Vec<Attribute>,
47+
mut attrs: Vec<Attribute>,
5448
mac_allowed: bool,
5549
attrs_allowed: bool,
5650
req_name: ReqName,
5751
) -> PResult<'a, Option<Item>> {
52+
maybe_whole!(self, NtItem, |item| {
53+
let mut item = item;
54+
mem::swap(&mut item.attrs, &mut attrs);
55+
item.attrs.extend(attrs);
56+
Some(item.into_inner())
57+
});
58+
5859
let mut unclosed_delims = vec![];
5960
let (mut item, tokens) = self.collect_tokens(|this| {
6061
let item = this.parse_item_common_(attrs, mac_allowed, attrs_allowed, req_name);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// check-pass
2+
3+
fn main() {}
4+
5+
macro_rules! mac_impl {
6+
($i:item) => {
7+
struct S;
8+
impl S { $i }
9+
}
10+
}
11+
12+
mac_impl! {
13+
fn foo() {}
14+
}
15+
16+
macro_rules! mac_trait {
17+
($i:item) => {
18+
trait T { $i }
19+
}
20+
}
21+
22+
mac_trait! {
23+
fn foo() {}
24+
}
25+
26+
macro_rules! mac_extern {
27+
($i:item) => {
28+
extern "C" { $i }
29+
}
30+
}
31+
32+
mac_extern! {
33+
fn foo();
34+
}

0 commit comments

Comments
 (0)