mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 04:53:34 +00:00
Merge #5607
5607: Finaize item grammar r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
commit
af8132e610
3 changed files with 90 additions and 82 deletions
|
@ -557,6 +557,7 @@ impl Ctx {
|
|||
let statik = self.lower_static(&ast)?;
|
||||
statik.into()
|
||||
}
|
||||
ast::ExternItem::MacroCall(_) => return None,
|
||||
};
|
||||
self.add_attrs(id.into(), attrs);
|
||||
Some(id)
|
||||
|
|
|
@ -453,12 +453,23 @@ impl Variant {
|
|||
pub struct AssocItemList {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
impl ast::AttrsOwner for AssocItemList {}
|
||||
impl AssocItemList {
|
||||
pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) }
|
||||
pub fn assoc_items(&self) -> AstChildren<AssocItem> { support::children(&self.syntax) }
|
||||
pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) }
|
||||
}
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct ExternItemList {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
impl ast::AttrsOwner for ExternItemList {}
|
||||
impl ExternItemList {
|
||||
pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) }
|
||||
pub fn extern_items(&self) -> AstChildren<ExternItem> { support::children(&self.syntax) }
|
||||
pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) }
|
||||
}
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct ParenType {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
@ -1254,15 +1265,6 @@ impl ConstArg {
|
|||
pub fn block_expr(&self) -> Option<BlockExpr> { support::child(&self.syntax) }
|
||||
}
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct ExternItemList {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
impl ExternItemList {
|
||||
pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) }
|
||||
pub fn extern_items(&self) -> AstChildren<ExternItem> { support::children(&self.syntax) }
|
||||
pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) }
|
||||
}
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct MetaItem {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
@ -1373,6 +1375,14 @@ pub enum AssocItem {
|
|||
impl ast::AttrsOwner for AssocItem {}
|
||||
impl ast::NameOwner for AssocItem {}
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub enum ExternItem {
|
||||
Fn(Fn),
|
||||
Static(Static),
|
||||
MacroCall(MacroCall),
|
||||
}
|
||||
impl ast::AttrsOwner for ExternItem {}
|
||||
impl ast::NameOwner for ExternItem {}
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub enum Stmt {
|
||||
LetStmt(LetStmt),
|
||||
ExprStmt(ExprStmt),
|
||||
|
@ -1384,14 +1394,6 @@ pub enum AttrInput {
|
|||
TokenTree(TokenTree),
|
||||
}
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub enum ExternItem {
|
||||
Fn(Fn),
|
||||
Static(Static),
|
||||
}
|
||||
impl ast::AttrsOwner for ExternItem {}
|
||||
impl ast::NameOwner for ExternItem {}
|
||||
impl ast::VisibilityOwner for ExternItem {}
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub enum AdtDef {
|
||||
Struct(Struct),
|
||||
Enum(Enum),
|
||||
|
@ -1841,6 +1843,17 @@ impl AstNode for AssocItemList {
|
|||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
impl AstNode for ExternItemList {
|
||||
fn can_cast(kind: SyntaxKind) -> bool { kind == EXTERN_ITEM_LIST }
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
impl AstNode for ParenType {
|
||||
fn can_cast(kind: SyntaxKind) -> bool { kind == PAREN_TYPE }
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
|
@ -2754,17 +2767,6 @@ impl AstNode for ConstArg {
|
|||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
impl AstNode for ExternItemList {
|
||||
fn can_cast(kind: SyntaxKind) -> bool { kind == EXTERN_ITEM_LIST }
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
impl AstNode for MetaItem {
|
||||
fn can_cast(kind: SyntaxKind) -> bool { kind == META_ITEM }
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
|
@ -3290,6 +3292,39 @@ impl AstNode for AssocItem {
|
|||
}
|
||||
}
|
||||
}
|
||||
impl From<Fn> for ExternItem {
|
||||
fn from(node: Fn) -> ExternItem { ExternItem::Fn(node) }
|
||||
}
|
||||
impl From<Static> for ExternItem {
|
||||
fn from(node: Static) -> ExternItem { ExternItem::Static(node) }
|
||||
}
|
||||
impl From<MacroCall> for ExternItem {
|
||||
fn from(node: MacroCall) -> ExternItem { ExternItem::MacroCall(node) }
|
||||
}
|
||||
impl AstNode for ExternItem {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
FN | STATIC | MACRO_CALL => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
let res = match syntax.kind() {
|
||||
FN => ExternItem::Fn(Fn { syntax }),
|
||||
STATIC => ExternItem::Static(Static { syntax }),
|
||||
MACRO_CALL => ExternItem::MacroCall(MacroCall { syntax }),
|
||||
_ => return None,
|
||||
};
|
||||
Some(res)
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
match self {
|
||||
ExternItem::Fn(it) => &it.syntax,
|
||||
ExternItem::Static(it) => &it.syntax,
|
||||
ExternItem::MacroCall(it) => &it.syntax,
|
||||
}
|
||||
}
|
||||
}
|
||||
impl From<LetStmt> for Stmt {
|
||||
fn from(node: LetStmt) -> Stmt { Stmt::LetStmt(node) }
|
||||
}
|
||||
|
@ -3346,34 +3381,6 @@ impl AstNode for AttrInput {
|
|||
}
|
||||
}
|
||||
}
|
||||
impl From<Fn> for ExternItem {
|
||||
fn from(node: Fn) -> ExternItem { ExternItem::Fn(node) }
|
||||
}
|
||||
impl From<Static> for ExternItem {
|
||||
fn from(node: Static) -> ExternItem { ExternItem::Static(node) }
|
||||
}
|
||||
impl AstNode for ExternItem {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
FN | STATIC => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
let res = match syntax.kind() {
|
||||
FN => ExternItem::Fn(Fn { syntax }),
|
||||
STATIC => ExternItem::Static(Static { syntax }),
|
||||
_ => return None,
|
||||
};
|
||||
Some(res)
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
match self {
|
||||
ExternItem::Fn(it) => &it.syntax,
|
||||
ExternItem::Static(it) => &it.syntax,
|
||||
}
|
||||
}
|
||||
}
|
||||
impl From<Struct> for AdtDef {
|
||||
fn from(node: Struct) -> AdtDef { AdtDef::Struct(node) }
|
||||
}
|
||||
|
@ -3437,6 +3444,11 @@ impl std::fmt::Display for AssocItem {
|
|||
std::fmt::Display::fmt(self.syntax(), f)
|
||||
}
|
||||
}
|
||||
impl std::fmt::Display for ExternItem {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
std::fmt::Display::fmt(self.syntax(), f)
|
||||
}
|
||||
}
|
||||
impl std::fmt::Display for Stmt {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
std::fmt::Display::fmt(self.syntax(), f)
|
||||
|
@ -3447,11 +3459,6 @@ impl std::fmt::Display for AttrInput {
|
|||
std::fmt::Display::fmt(self.syntax(), f)
|
||||
}
|
||||
}
|
||||
impl std::fmt::Display for ExternItem {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
std::fmt::Display::fmt(self.syntax(), f)
|
||||
}
|
||||
}
|
||||
impl std::fmt::Display for AdtDef {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
std::fmt::Display::fmt(self.syntax(), f)
|
||||
|
@ -3657,6 +3664,11 @@ impl std::fmt::Display for AssocItemList {
|
|||
std::fmt::Display::fmt(self.syntax(), f)
|
||||
}
|
||||
}
|
||||
impl std::fmt::Display for ExternItemList {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
std::fmt::Display::fmt(self.syntax(), f)
|
||||
}
|
||||
}
|
||||
impl std::fmt::Display for ParenType {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
std::fmt::Display::fmt(self.syntax(), f)
|
||||
|
@ -4072,11 +4084,6 @@ impl std::fmt::Display for ConstArg {
|
|||
std::fmt::Display::fmt(self.syntax(), f)
|
||||
}
|
||||
}
|
||||
impl std::fmt::Display for ExternItemList {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
std::fmt::Display::fmt(self.syntax(), f)
|
||||
}
|
||||
}
|
||||
impl std::fmt::Display for MetaItem {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
std::fmt::Display::fmt(self.syntax(), f)
|
||||
|
|
|
@ -129,7 +129,13 @@ Trait =
|
|||
AssocItemList
|
||||
|
||||
AssocItemList =
|
||||
'{' AssocItem* '}'
|
||||
'{' Attr* AssocItem* '}'
|
||||
|
||||
AssocItem =
|
||||
Fn
|
||||
| TypeAlias
|
||||
| Const
|
||||
| MacroCall
|
||||
|
||||
Impl =
|
||||
Attr* Visibility?
|
||||
|
@ -139,6 +145,15 @@ Impl =
|
|||
) WhereClause?
|
||||
AssocItemList
|
||||
|
||||
ExternBlock =
|
||||
Attr* Abi ExternItemList
|
||||
|
||||
ExternItemList =
|
||||
'{' Attr* ExternItem* '}'
|
||||
|
||||
ExternItem =
|
||||
Fn | Static | MacroCall
|
||||
|
||||
ParenType =
|
||||
'(' TypeRef ')'
|
||||
|
||||
|
@ -449,12 +464,6 @@ LifetimeArg =
|
|||
ConstArg =
|
||||
Literal | BlockExpr BlockExpr
|
||||
|
||||
ExternBlock =
|
||||
Attr* Abi ExternItemList
|
||||
|
||||
ExternItemList =
|
||||
'{' extern_items:ExternItem* '}'
|
||||
|
||||
MetaItem =
|
||||
Path '=' AttrInput nested_meta_items:MetaItem*
|
||||
|
||||
|
@ -478,15 +487,6 @@ TypeRef =
|
|||
| ImplTraitType
|
||||
| DynTraitType
|
||||
|
||||
AssocItem =
|
||||
Fn
|
||||
| TypeAlias
|
||||
| Const
|
||||
| MacroCall
|
||||
|
||||
ExternItem =
|
||||
Fn | Static
|
||||
|
||||
AttrInput =
|
||||
Literal
|
||||
| TokenTree
|
||||
|
|
Loading…
Reference in a new issue