Skip to content

Commit af8132e

Browse files
bors[bot]matklad
andauthored
Merge #5607
5607: Finaize item grammar r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2 parents 0f58055 + 917c89c commit af8132e

File tree

3 files changed

+88
-80
lines changed

3 files changed

+88
-80
lines changed

crates/ra_hir_def/src/item_tree/lower.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,7 @@ impl Ctx {
557557
let statik = self.lower_static(&ast)?;
558558
statik.into()
559559
}
560+
ast::ExternItem::MacroCall(_) => return None,
560561
};
561562
self.add_attrs(id.into(), attrs);
562563
Some(id)

crates/ra_syntax/src/ast/generated/nodes.rs

Lines changed: 71 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -453,12 +453,23 @@ impl Variant {
453453
pub struct AssocItemList {
454454
pub(crate) syntax: SyntaxNode,
455455
}
456+
impl ast::AttrsOwner for AssocItemList {}
456457
impl AssocItemList {
457458
pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) }
458459
pub fn assoc_items(&self) -> AstChildren<AssocItem> { support::children(&self.syntax) }
459460
pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) }
460461
}
461462
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
463+
pub struct ExternItemList {
464+
pub(crate) syntax: SyntaxNode,
465+
}
466+
impl ast::AttrsOwner for ExternItemList {}
467+
impl ExternItemList {
468+
pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) }
469+
pub fn extern_items(&self) -> AstChildren<ExternItem> { support::children(&self.syntax) }
470+
pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) }
471+
}
472+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
462473
pub struct ParenType {
463474
pub(crate) syntax: SyntaxNode,
464475
}
@@ -1254,15 +1265,6 @@ impl ConstArg {
12541265
pub fn block_expr(&self) -> Option<BlockExpr> { support::child(&self.syntax) }
12551266
}
12561267
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1257-
pub struct ExternItemList {
1258-
pub(crate) syntax: SyntaxNode,
1259-
}
1260-
impl ExternItemList {
1261-
pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) }
1262-
pub fn extern_items(&self) -> AstChildren<ExternItem> { support::children(&self.syntax) }
1263-
pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) }
1264-
}
1265-
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
12661268
pub struct MetaItem {
12671269
pub(crate) syntax: SyntaxNode,
12681270
}
@@ -1373,6 +1375,14 @@ pub enum AssocItem {
13731375
impl ast::AttrsOwner for AssocItem {}
13741376
impl ast::NameOwner for AssocItem {}
13751377
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1378+
pub enum ExternItem {
1379+
Fn(Fn),
1380+
Static(Static),
1381+
MacroCall(MacroCall),
1382+
}
1383+
impl ast::AttrsOwner for ExternItem {}
1384+
impl ast::NameOwner for ExternItem {}
1385+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
13761386
pub enum Stmt {
13771387
LetStmt(LetStmt),
13781388
ExprStmt(ExprStmt),
@@ -1384,14 +1394,6 @@ pub enum AttrInput {
13841394
TokenTree(TokenTree),
13851395
}
13861396
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1387-
pub enum ExternItem {
1388-
Fn(Fn),
1389-
Static(Static),
1390-
}
1391-
impl ast::AttrsOwner for ExternItem {}
1392-
impl ast::NameOwner for ExternItem {}
1393-
impl ast::VisibilityOwner for ExternItem {}
1394-
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
13951397
pub enum AdtDef {
13961398
Struct(Struct),
13971399
Enum(Enum),
@@ -1841,6 +1843,17 @@ impl AstNode for AssocItemList {
18411843
}
18421844
fn syntax(&self) -> &SyntaxNode { &self.syntax }
18431845
}
1846+
impl AstNode for ExternItemList {
1847+
fn can_cast(kind: SyntaxKind) -> bool { kind == EXTERN_ITEM_LIST }
1848+
fn cast(syntax: SyntaxNode) -> Option<Self> {
1849+
if Self::can_cast(syntax.kind()) {
1850+
Some(Self { syntax })
1851+
} else {
1852+
None
1853+
}
1854+
}
1855+
fn syntax(&self) -> &SyntaxNode { &self.syntax }
1856+
}
18441857
impl AstNode for ParenType {
18451858
fn can_cast(kind: SyntaxKind) -> bool { kind == PAREN_TYPE }
18461859
fn cast(syntax: SyntaxNode) -> Option<Self> {
@@ -2754,17 +2767,6 @@ impl AstNode for ConstArg {
27542767
}
27552768
fn syntax(&self) -> &SyntaxNode { &self.syntax }
27562769
}
2757-
impl AstNode for ExternItemList {
2758-
fn can_cast(kind: SyntaxKind) -> bool { kind == EXTERN_ITEM_LIST }
2759-
fn cast(syntax: SyntaxNode) -> Option<Self> {
2760-
if Self::can_cast(syntax.kind()) {
2761-
Some(Self { syntax })
2762-
} else {
2763-
None
2764-
}
2765-
}
2766-
fn syntax(&self) -> &SyntaxNode { &self.syntax }
2767-
}
27682770
impl AstNode for MetaItem {
27692771
fn can_cast(kind: SyntaxKind) -> bool { kind == META_ITEM }
27702772
fn cast(syntax: SyntaxNode) -> Option<Self> {
@@ -3290,6 +3292,39 @@ impl AstNode for AssocItem {
32903292
}
32913293
}
32923294
}
3295+
impl From<Fn> for ExternItem {
3296+
fn from(node: Fn) -> ExternItem { ExternItem::Fn(node) }
3297+
}
3298+
impl From<Static> for ExternItem {
3299+
fn from(node: Static) -> ExternItem { ExternItem::Static(node) }
3300+
}
3301+
impl From<MacroCall> for ExternItem {
3302+
fn from(node: MacroCall) -> ExternItem { ExternItem::MacroCall(node) }
3303+
}
3304+
impl AstNode for ExternItem {
3305+
fn can_cast(kind: SyntaxKind) -> bool {
3306+
match kind {
3307+
FN | STATIC | MACRO_CALL => true,
3308+
_ => false,
3309+
}
3310+
}
3311+
fn cast(syntax: SyntaxNode) -> Option<Self> {
3312+
let res = match syntax.kind() {
3313+
FN => ExternItem::Fn(Fn { syntax }),
3314+
STATIC => ExternItem::Static(Static { syntax }),
3315+
MACRO_CALL => ExternItem::MacroCall(MacroCall { syntax }),
3316+
_ => return None,
3317+
};
3318+
Some(res)
3319+
}
3320+
fn syntax(&self) -> &SyntaxNode {
3321+
match self {
3322+
ExternItem::Fn(it) => &it.syntax,
3323+
ExternItem::Static(it) => &it.syntax,
3324+
ExternItem::MacroCall(it) => &it.syntax,
3325+
}
3326+
}
3327+
}
32933328
impl From<LetStmt> for Stmt {
32943329
fn from(node: LetStmt) -> Stmt { Stmt::LetStmt(node) }
32953330
}
@@ -3346,34 +3381,6 @@ impl AstNode for AttrInput {
33463381
}
33473382
}
33483383
}
3349-
impl From<Fn> for ExternItem {
3350-
fn from(node: Fn) -> ExternItem { ExternItem::Fn(node) }
3351-
}
3352-
impl From<Static> for ExternItem {
3353-
fn from(node: Static) -> ExternItem { ExternItem::Static(node) }
3354-
}
3355-
impl AstNode for ExternItem {
3356-
fn can_cast(kind: SyntaxKind) -> bool {
3357-
match kind {
3358-
FN | STATIC => true,
3359-
_ => false,
3360-
}
3361-
}
3362-
fn cast(syntax: SyntaxNode) -> Option<Self> {
3363-
let res = match syntax.kind() {
3364-
FN => ExternItem::Fn(Fn { syntax }),
3365-
STATIC => ExternItem::Static(Static { syntax }),
3366-
_ => return None,
3367-
};
3368-
Some(res)
3369-
}
3370-
fn syntax(&self) -> &SyntaxNode {
3371-
match self {
3372-
ExternItem::Fn(it) => &it.syntax,
3373-
ExternItem::Static(it) => &it.syntax,
3374-
}
3375-
}
3376-
}
33773384
impl From<Struct> for AdtDef {
33783385
fn from(node: Struct) -> AdtDef { AdtDef::Struct(node) }
33793386
}
@@ -3437,17 +3444,17 @@ impl std::fmt::Display for AssocItem {
34373444
std::fmt::Display::fmt(self.syntax(), f)
34383445
}
34393446
}
3440-
impl std::fmt::Display for Stmt {
3447+
impl std::fmt::Display for ExternItem {
34413448
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
34423449
std::fmt::Display::fmt(self.syntax(), f)
34433450
}
34443451
}
3445-
impl std::fmt::Display for AttrInput {
3452+
impl std::fmt::Display for Stmt {
34463453
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
34473454
std::fmt::Display::fmt(self.syntax(), f)
34483455
}
34493456
}
3450-
impl std::fmt::Display for ExternItem {
3457+
impl std::fmt::Display for AttrInput {
34513458
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
34523459
std::fmt::Display::fmt(self.syntax(), f)
34533460
}
@@ -3657,6 +3664,11 @@ impl std::fmt::Display for AssocItemList {
36573664
std::fmt::Display::fmt(self.syntax(), f)
36583665
}
36593666
}
3667+
impl std::fmt::Display for ExternItemList {
3668+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3669+
std::fmt::Display::fmt(self.syntax(), f)
3670+
}
3671+
}
36603672
impl std::fmt::Display for ParenType {
36613673
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
36623674
std::fmt::Display::fmt(self.syntax(), f)
@@ -4072,11 +4084,6 @@ impl std::fmt::Display for ConstArg {
40724084
std::fmt::Display::fmt(self.syntax(), f)
40734085
}
40744086
}
4075-
impl std::fmt::Display for ExternItemList {
4076-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4077-
std::fmt::Display::fmt(self.syntax(), f)
4078-
}
4079-
}
40804087
impl std::fmt::Display for MetaItem {
40814088
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
40824089
std::fmt::Display::fmt(self.syntax(), f)

xtask/src/codegen/rust.ungram

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,13 @@ Trait =
129129
AssocItemList
130130

131131
AssocItemList =
132-
'{' AssocItem* '}'
132+
'{' Attr* AssocItem* '}'
133+
134+
AssocItem =
135+
Fn
136+
| TypeAlias
137+
| Const
138+
| MacroCall
133139

134140
Impl =
135141
Attr* Visibility?
@@ -139,6 +145,15 @@ Impl =
139145
) WhereClause?
140146
AssocItemList
141147

148+
ExternBlock =
149+
Attr* Abi ExternItemList
150+
151+
ExternItemList =
152+
'{' Attr* ExternItem* '}'
153+
154+
ExternItem =
155+
Fn | Static | MacroCall
156+
142157
ParenType =
143158
'(' TypeRef ')'
144159

@@ -449,12 +464,6 @@ LifetimeArg =
449464
ConstArg =
450465
Literal | BlockExpr BlockExpr
451466

452-
ExternBlock =
453-
Attr* Abi ExternItemList
454-
455-
ExternItemList =
456-
'{' extern_items:ExternItem* '}'
457-
458467
MetaItem =
459468
Path '=' AttrInput nested_meta_items:MetaItem*
460469

@@ -478,15 +487,6 @@ TypeRef =
478487
| ImplTraitType
479488
| DynTraitType
480489

481-
AssocItem =
482-
Fn
483-
| TypeAlias
484-
| Const
485-
| MacroCall
486-
487-
ExternItem =
488-
Fn | Static
489-
490490
AttrInput =
491491
Literal
492492
| TokenTree

0 commit comments

Comments
 (0)