From ddf08daddf7e86d67e8d2e5596f8013b376dd522 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 31 Jul 2020 18:46:07 +0200 Subject: [PATCH] Fix const arguments grammar --- crates/ra_parser/src/grammar/type_args.rs | 2 +- crates/ra_syntax/src/ast/generated/nodes.rs | 521 +++++++++--------- .../parser/inline/ok/0039_type_arg.rast | 3 +- xtask/src/codegen/rust.ungram | 2 +- 4 files changed, 264 insertions(+), 264 deletions(-) diff --git a/crates/ra_parser/src/grammar/type_args.rs b/crates/ra_parser/src/grammar/type_args.rs index 8f88d51db3..aef7cd6fbb 100644 --- a/crates/ra_parser/src/grammar/type_args.rs +++ b/crates/ra_parser/src/grammar/type_args.rs @@ -52,7 +52,7 @@ fn type_arg(p: &mut Parser) { m.complete(p, CONST_ARG); } k if k.is_literal() => { - p.bump(k); + expressions::literal(p); m.complete(p, CONST_ARG); } _ => { diff --git a/crates/ra_syntax/src/ast/generated/nodes.rs b/crates/ra_syntax/src/ast/generated/nodes.rs index 132c2ae8c3..97a882bf0a 100644 --- a/crates/ra_syntax/src/ast/generated/nodes.rs +++ b/crates/ra_syntax/src/ast/generated/nodes.rs @@ -106,8 +106,7 @@ pub struct ConstArg { pub(crate) syntax: SyntaxNode, } impl ConstArg { - pub fn literal(&self) -> Option { support::child(&self.syntax) } - pub fn block_expr(&self) -> Option { support::child(&self.syntax) } + pub fn expr(&self) -> Option { support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TypeBoundList { @@ -117,23 +116,6 @@ impl TypeBoundList { pub fn bounds(&self) -> AstChildren { support::children(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct Literal { - pub(crate) syntax: SyntaxNode, -} -impl ast::AttrsOwner for Literal {} -impl Literal {} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct BlockExpr { - pub(crate) syntax: SyntaxNode, -} -impl ast::AttrsOwner for BlockExpr {} -impl BlockExpr { - pub fn l_curly_token(&self) -> Option { support::token(&self.syntax, T!['{']) } - pub fn statements(&self) -> AstChildren { support::children(&self.syntax) } - pub fn expr(&self) -> Option { support::child(&self.syntax) } - pub fn r_curly_token(&self) -> Option { support::token(&self.syntax, T!['}']) } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct SourceFile { pub(crate) syntax: SyntaxNode, } @@ -437,6 +419,17 @@ impl WhereClause { pub fn predicates(&self) -> AstChildren { support::children(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct BlockExpr { + pub(crate) syntax: SyntaxNode, +} +impl ast::AttrsOwner for BlockExpr {} +impl BlockExpr { + pub fn l_curly_token(&self) -> Option { support::token(&self.syntax, T!['{']) } + pub fn statements(&self) -> AstChildren { support::children(&self.syntax) } + pub fn expr(&self) -> Option { support::child(&self.syntax) } + pub fn r_curly_token(&self) -> Option { support::token(&self.syntax, T!['}']) } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct SelfParam { pub(crate) syntax: SyntaxNode, } @@ -590,6 +583,12 @@ impl WherePred { pub fn ty(&self) -> Option { support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct Literal { + pub(crate) syntax: SyntaxNode, +} +impl ast::AttrsOwner for Literal {} +impl Literal {} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TokenTree { pub(crate) syntax: SyntaxNode, } @@ -1292,6 +1291,39 @@ pub enum Type { TupleType(TupleType), } #[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub enum Expr { + ArrayExpr(ArrayExpr), + AwaitExpr(AwaitExpr), + BinExpr(BinExpr), + BlockExpr(BlockExpr), + BoxExpr(BoxExpr), + BreakExpr(BreakExpr), + CallExpr(CallExpr), + CastExpr(CastExpr), + ClosureExpr(ClosureExpr), + ContinueExpr(ContinueExpr), + EffectExpr(EffectExpr), + FieldExpr(FieldExpr), + ForExpr(ForExpr), + IfExpr(IfExpr), + IndexExpr(IndexExpr), + Literal(Literal), + LoopExpr(LoopExpr), + MacroCall(MacroCall), + MatchExpr(MatchExpr), + MethodCallExpr(MethodCallExpr), + ParenExpr(ParenExpr), + PathExpr(PathExpr), + PrefixExpr(PrefixExpr), + RangeExpr(RangeExpr), + RecordExpr(RecordExpr), + RefExpr(RefExpr), + ReturnExpr(ReturnExpr), + TryExpr(TryExpr), + TupleExpr(TupleExpr), + WhileExpr(WhileExpr), +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum Item { Const(Const), Enum(Enum), @@ -1333,39 +1365,6 @@ pub enum FieldList { TupleFieldList(TupleFieldList), } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub enum Expr { - ArrayExpr(ArrayExpr), - AwaitExpr(AwaitExpr), - BinExpr(BinExpr), - BlockExpr(BlockExpr), - BoxExpr(BoxExpr), - BreakExpr(BreakExpr), - CallExpr(CallExpr), - CastExpr(CastExpr), - ClosureExpr(ClosureExpr), - ContinueExpr(ContinueExpr), - EffectExpr(EffectExpr), - FieldExpr(FieldExpr), - ForExpr(ForExpr), - IfExpr(IfExpr), - IndexExpr(IndexExpr), - Literal(Literal), - LoopExpr(LoopExpr), - MacroCall(MacroCall), - MatchExpr(MatchExpr), - MethodCallExpr(MethodCallExpr), - ParenExpr(ParenExpr), - PathExpr(PathExpr), - PrefixExpr(PrefixExpr), - RangeExpr(RangeExpr), - RecordExpr(RecordExpr), - RefExpr(RefExpr), - ReturnExpr(ReturnExpr), - TryExpr(TryExpr), - TupleExpr(TupleExpr), - WhileExpr(WhileExpr), -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum AdtDef { Enum(Enum), Struct(Struct), @@ -1537,28 +1536,6 @@ impl AstNode for TypeBoundList { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for Literal { - fn can_cast(kind: SyntaxKind) -> bool { kind == LITERAL } - fn cast(syntax: SyntaxNode) -> Option { - if Self::can_cast(syntax.kind()) { - Some(Self { syntax }) - } else { - None - } - } - fn syntax(&self) -> &SyntaxNode { &self.syntax } -} -impl AstNode for BlockExpr { - fn can_cast(kind: SyntaxKind) -> bool { kind == BLOCK_EXPR } - fn cast(syntax: SyntaxNode) -> Option { - if Self::can_cast(syntax.kind()) { - Some(Self { syntax }) - } else { - None - } - } - fn syntax(&self) -> &SyntaxNode { &self.syntax } -} impl AstNode for SourceFile { fn can_cast(kind: SyntaxKind) -> bool { kind == SOURCE_FILE } fn cast(syntax: SyntaxNode) -> Option { @@ -1834,6 +1811,17 @@ impl AstNode for WhereClause { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } +impl AstNode for BlockExpr { + fn can_cast(kind: SyntaxKind) -> bool { kind == BLOCK_EXPR } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { &self.syntax } +} impl AstNode for SelfParam { fn can_cast(kind: SyntaxKind) -> bool { kind == SELF_PARAM } fn cast(syntax: SyntaxNode) -> Option { @@ -1988,6 +1976,17 @@ impl AstNode for WherePred { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } +impl AstNode for Literal { + fn can_cast(kind: SyntaxKind) -> bool { kind == LITERAL } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { &self.syntax } +} impl AstNode for TokenTree { fn can_cast(kind: SyntaxKind) -> bool { kind == TOKEN_TREE } fn cast(syntax: SyntaxNode) -> Option { @@ -2892,6 +2891,178 @@ impl AstNode for Type { } } } +impl From for Expr { + fn from(node: ArrayExpr) -> Expr { Expr::ArrayExpr(node) } +} +impl From for Expr { + fn from(node: AwaitExpr) -> Expr { Expr::AwaitExpr(node) } +} +impl From for Expr { + fn from(node: BinExpr) -> Expr { Expr::BinExpr(node) } +} +impl From for Expr { + fn from(node: BlockExpr) -> Expr { Expr::BlockExpr(node) } +} +impl From for Expr { + fn from(node: BoxExpr) -> Expr { Expr::BoxExpr(node) } +} +impl From for Expr { + fn from(node: BreakExpr) -> Expr { Expr::BreakExpr(node) } +} +impl From for Expr { + fn from(node: CallExpr) -> Expr { Expr::CallExpr(node) } +} +impl From for Expr { + fn from(node: CastExpr) -> Expr { Expr::CastExpr(node) } +} +impl From for Expr { + fn from(node: ClosureExpr) -> Expr { Expr::ClosureExpr(node) } +} +impl From for Expr { + fn from(node: ContinueExpr) -> Expr { Expr::ContinueExpr(node) } +} +impl From for Expr { + fn from(node: EffectExpr) -> Expr { Expr::EffectExpr(node) } +} +impl From for Expr { + fn from(node: FieldExpr) -> Expr { Expr::FieldExpr(node) } +} +impl From for Expr { + fn from(node: ForExpr) -> Expr { Expr::ForExpr(node) } +} +impl From for Expr { + fn from(node: IfExpr) -> Expr { Expr::IfExpr(node) } +} +impl From for Expr { + fn from(node: IndexExpr) -> Expr { Expr::IndexExpr(node) } +} +impl From for Expr { + fn from(node: Literal) -> Expr { Expr::Literal(node) } +} +impl From for Expr { + fn from(node: LoopExpr) -> Expr { Expr::LoopExpr(node) } +} +impl From for Expr { + fn from(node: MacroCall) -> Expr { Expr::MacroCall(node) } +} +impl From for Expr { + fn from(node: MatchExpr) -> Expr { Expr::MatchExpr(node) } +} +impl From for Expr { + fn from(node: MethodCallExpr) -> Expr { Expr::MethodCallExpr(node) } +} +impl From for Expr { + fn from(node: ParenExpr) -> Expr { Expr::ParenExpr(node) } +} +impl From for Expr { + fn from(node: PathExpr) -> Expr { Expr::PathExpr(node) } +} +impl From for Expr { + fn from(node: PrefixExpr) -> Expr { Expr::PrefixExpr(node) } +} +impl From for Expr { + fn from(node: RangeExpr) -> Expr { Expr::RangeExpr(node) } +} +impl From for Expr { + fn from(node: RecordExpr) -> Expr { Expr::RecordExpr(node) } +} +impl From for Expr { + fn from(node: RefExpr) -> Expr { Expr::RefExpr(node) } +} +impl From for Expr { + fn from(node: ReturnExpr) -> Expr { Expr::ReturnExpr(node) } +} +impl From for Expr { + fn from(node: TryExpr) -> Expr { Expr::TryExpr(node) } +} +impl From for Expr { + fn from(node: TupleExpr) -> Expr { Expr::TupleExpr(node) } +} +impl From for Expr { + fn from(node: WhileExpr) -> Expr { Expr::WhileExpr(node) } +} +impl AstNode for Expr { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + ARRAY_EXPR | AWAIT_EXPR | BIN_EXPR | BLOCK_EXPR | BOX_EXPR | BREAK_EXPR | CALL_EXPR + | CAST_EXPR | CLOSURE_EXPR | CONTINUE_EXPR | EFFECT_EXPR | FIELD_EXPR | FOR_EXPR + | IF_EXPR | INDEX_EXPR | LITERAL | LOOP_EXPR | MACRO_CALL | MATCH_EXPR + | METHOD_CALL_EXPR | PAREN_EXPR | PATH_EXPR | PREFIX_EXPR | RANGE_EXPR + | RECORD_EXPR | REF_EXPR | RETURN_EXPR | TRY_EXPR | TUPLE_EXPR | WHILE_EXPR => true, + _ => false, + } + } + fn cast(syntax: SyntaxNode) -> Option { + let res = match syntax.kind() { + ARRAY_EXPR => Expr::ArrayExpr(ArrayExpr { syntax }), + AWAIT_EXPR => Expr::AwaitExpr(AwaitExpr { syntax }), + BIN_EXPR => Expr::BinExpr(BinExpr { syntax }), + BLOCK_EXPR => Expr::BlockExpr(BlockExpr { syntax }), + BOX_EXPR => Expr::BoxExpr(BoxExpr { syntax }), + BREAK_EXPR => Expr::BreakExpr(BreakExpr { syntax }), + CALL_EXPR => Expr::CallExpr(CallExpr { syntax }), + CAST_EXPR => Expr::CastExpr(CastExpr { syntax }), + CLOSURE_EXPR => Expr::ClosureExpr(ClosureExpr { syntax }), + CONTINUE_EXPR => Expr::ContinueExpr(ContinueExpr { syntax }), + EFFECT_EXPR => Expr::EffectExpr(EffectExpr { syntax }), + FIELD_EXPR => Expr::FieldExpr(FieldExpr { syntax }), + FOR_EXPR => Expr::ForExpr(ForExpr { syntax }), + IF_EXPR => Expr::IfExpr(IfExpr { syntax }), + INDEX_EXPR => Expr::IndexExpr(IndexExpr { syntax }), + LITERAL => Expr::Literal(Literal { syntax }), + LOOP_EXPR => Expr::LoopExpr(LoopExpr { syntax }), + MACRO_CALL => Expr::MacroCall(MacroCall { syntax }), + MATCH_EXPR => Expr::MatchExpr(MatchExpr { syntax }), + METHOD_CALL_EXPR => Expr::MethodCallExpr(MethodCallExpr { syntax }), + PAREN_EXPR => Expr::ParenExpr(ParenExpr { syntax }), + PATH_EXPR => Expr::PathExpr(PathExpr { syntax }), + PREFIX_EXPR => Expr::PrefixExpr(PrefixExpr { syntax }), + RANGE_EXPR => Expr::RangeExpr(RangeExpr { syntax }), + RECORD_EXPR => Expr::RecordExpr(RecordExpr { syntax }), + REF_EXPR => Expr::RefExpr(RefExpr { syntax }), + RETURN_EXPR => Expr::ReturnExpr(ReturnExpr { syntax }), + TRY_EXPR => Expr::TryExpr(TryExpr { syntax }), + TUPLE_EXPR => Expr::TupleExpr(TupleExpr { syntax }), + WHILE_EXPR => Expr::WhileExpr(WhileExpr { syntax }), + _ => return None, + }; + Some(res) + } + fn syntax(&self) -> &SyntaxNode { + match self { + Expr::ArrayExpr(it) => &it.syntax, + Expr::AwaitExpr(it) => &it.syntax, + Expr::BinExpr(it) => &it.syntax, + Expr::BlockExpr(it) => &it.syntax, + Expr::BoxExpr(it) => &it.syntax, + Expr::BreakExpr(it) => &it.syntax, + Expr::CallExpr(it) => &it.syntax, + Expr::CastExpr(it) => &it.syntax, + Expr::ClosureExpr(it) => &it.syntax, + Expr::ContinueExpr(it) => &it.syntax, + Expr::EffectExpr(it) => &it.syntax, + Expr::FieldExpr(it) => &it.syntax, + Expr::ForExpr(it) => &it.syntax, + Expr::IfExpr(it) => &it.syntax, + Expr::IndexExpr(it) => &it.syntax, + Expr::Literal(it) => &it.syntax, + Expr::LoopExpr(it) => &it.syntax, + Expr::MacroCall(it) => &it.syntax, + Expr::MatchExpr(it) => &it.syntax, + Expr::MethodCallExpr(it) => &it.syntax, + Expr::ParenExpr(it) => &it.syntax, + Expr::PathExpr(it) => &it.syntax, + Expr::PrefixExpr(it) => &it.syntax, + Expr::RangeExpr(it) => &it.syntax, + Expr::RecordExpr(it) => &it.syntax, + Expr::RefExpr(it) => &it.syntax, + Expr::ReturnExpr(it) => &it.syntax, + Expr::TryExpr(it) => &it.syntax, + Expr::TupleExpr(it) => &it.syntax, + Expr::WhileExpr(it) => &it.syntax, + } + } +} impl From for Item { fn from(node: Const) -> Item { Item::Const(node) } } @@ -3104,178 +3275,6 @@ impl AstNode for FieldList { } } } -impl From for Expr { - fn from(node: ArrayExpr) -> Expr { Expr::ArrayExpr(node) } -} -impl From for Expr { - fn from(node: AwaitExpr) -> Expr { Expr::AwaitExpr(node) } -} -impl From for Expr { - fn from(node: BinExpr) -> Expr { Expr::BinExpr(node) } -} -impl From for Expr { - fn from(node: BlockExpr) -> Expr { Expr::BlockExpr(node) } -} -impl From for Expr { - fn from(node: BoxExpr) -> Expr { Expr::BoxExpr(node) } -} -impl From for Expr { - fn from(node: BreakExpr) -> Expr { Expr::BreakExpr(node) } -} -impl From for Expr { - fn from(node: CallExpr) -> Expr { Expr::CallExpr(node) } -} -impl From for Expr { - fn from(node: CastExpr) -> Expr { Expr::CastExpr(node) } -} -impl From for Expr { - fn from(node: ClosureExpr) -> Expr { Expr::ClosureExpr(node) } -} -impl From for Expr { - fn from(node: ContinueExpr) -> Expr { Expr::ContinueExpr(node) } -} -impl From for Expr { - fn from(node: EffectExpr) -> Expr { Expr::EffectExpr(node) } -} -impl From for Expr { - fn from(node: FieldExpr) -> Expr { Expr::FieldExpr(node) } -} -impl From for Expr { - fn from(node: ForExpr) -> Expr { Expr::ForExpr(node) } -} -impl From for Expr { - fn from(node: IfExpr) -> Expr { Expr::IfExpr(node) } -} -impl From for Expr { - fn from(node: IndexExpr) -> Expr { Expr::IndexExpr(node) } -} -impl From for Expr { - fn from(node: Literal) -> Expr { Expr::Literal(node) } -} -impl From for Expr { - fn from(node: LoopExpr) -> Expr { Expr::LoopExpr(node) } -} -impl From for Expr { - fn from(node: MacroCall) -> Expr { Expr::MacroCall(node) } -} -impl From for Expr { - fn from(node: MatchExpr) -> Expr { Expr::MatchExpr(node) } -} -impl From for Expr { - fn from(node: MethodCallExpr) -> Expr { Expr::MethodCallExpr(node) } -} -impl From for Expr { - fn from(node: ParenExpr) -> Expr { Expr::ParenExpr(node) } -} -impl From for Expr { - fn from(node: PathExpr) -> Expr { Expr::PathExpr(node) } -} -impl From for Expr { - fn from(node: PrefixExpr) -> Expr { Expr::PrefixExpr(node) } -} -impl From for Expr { - fn from(node: RangeExpr) -> Expr { Expr::RangeExpr(node) } -} -impl From for Expr { - fn from(node: RecordExpr) -> Expr { Expr::RecordExpr(node) } -} -impl From for Expr { - fn from(node: RefExpr) -> Expr { Expr::RefExpr(node) } -} -impl From for Expr { - fn from(node: ReturnExpr) -> Expr { Expr::ReturnExpr(node) } -} -impl From for Expr { - fn from(node: TryExpr) -> Expr { Expr::TryExpr(node) } -} -impl From for Expr { - fn from(node: TupleExpr) -> Expr { Expr::TupleExpr(node) } -} -impl From for Expr { - fn from(node: WhileExpr) -> Expr { Expr::WhileExpr(node) } -} -impl AstNode for Expr { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - ARRAY_EXPR | AWAIT_EXPR | BIN_EXPR | BLOCK_EXPR | BOX_EXPR | BREAK_EXPR | CALL_EXPR - | CAST_EXPR | CLOSURE_EXPR | CONTINUE_EXPR | EFFECT_EXPR | FIELD_EXPR | FOR_EXPR - | IF_EXPR | INDEX_EXPR | LITERAL | LOOP_EXPR | MACRO_CALL | MATCH_EXPR - | METHOD_CALL_EXPR | PAREN_EXPR | PATH_EXPR | PREFIX_EXPR | RANGE_EXPR - | RECORD_EXPR | REF_EXPR | RETURN_EXPR | TRY_EXPR | TUPLE_EXPR | WHILE_EXPR => true, - _ => false, - } - } - fn cast(syntax: SyntaxNode) -> Option { - let res = match syntax.kind() { - ARRAY_EXPR => Expr::ArrayExpr(ArrayExpr { syntax }), - AWAIT_EXPR => Expr::AwaitExpr(AwaitExpr { syntax }), - BIN_EXPR => Expr::BinExpr(BinExpr { syntax }), - BLOCK_EXPR => Expr::BlockExpr(BlockExpr { syntax }), - BOX_EXPR => Expr::BoxExpr(BoxExpr { syntax }), - BREAK_EXPR => Expr::BreakExpr(BreakExpr { syntax }), - CALL_EXPR => Expr::CallExpr(CallExpr { syntax }), - CAST_EXPR => Expr::CastExpr(CastExpr { syntax }), - CLOSURE_EXPR => Expr::ClosureExpr(ClosureExpr { syntax }), - CONTINUE_EXPR => Expr::ContinueExpr(ContinueExpr { syntax }), - EFFECT_EXPR => Expr::EffectExpr(EffectExpr { syntax }), - FIELD_EXPR => Expr::FieldExpr(FieldExpr { syntax }), - FOR_EXPR => Expr::ForExpr(ForExpr { syntax }), - IF_EXPR => Expr::IfExpr(IfExpr { syntax }), - INDEX_EXPR => Expr::IndexExpr(IndexExpr { syntax }), - LITERAL => Expr::Literal(Literal { syntax }), - LOOP_EXPR => Expr::LoopExpr(LoopExpr { syntax }), - MACRO_CALL => Expr::MacroCall(MacroCall { syntax }), - MATCH_EXPR => Expr::MatchExpr(MatchExpr { syntax }), - METHOD_CALL_EXPR => Expr::MethodCallExpr(MethodCallExpr { syntax }), - PAREN_EXPR => Expr::ParenExpr(ParenExpr { syntax }), - PATH_EXPR => Expr::PathExpr(PathExpr { syntax }), - PREFIX_EXPR => Expr::PrefixExpr(PrefixExpr { syntax }), - RANGE_EXPR => Expr::RangeExpr(RangeExpr { syntax }), - RECORD_EXPR => Expr::RecordExpr(RecordExpr { syntax }), - REF_EXPR => Expr::RefExpr(RefExpr { syntax }), - RETURN_EXPR => Expr::ReturnExpr(ReturnExpr { syntax }), - TRY_EXPR => Expr::TryExpr(TryExpr { syntax }), - TUPLE_EXPR => Expr::TupleExpr(TupleExpr { syntax }), - WHILE_EXPR => Expr::WhileExpr(WhileExpr { syntax }), - _ => return None, - }; - Some(res) - } - fn syntax(&self) -> &SyntaxNode { - match self { - Expr::ArrayExpr(it) => &it.syntax, - Expr::AwaitExpr(it) => &it.syntax, - Expr::BinExpr(it) => &it.syntax, - Expr::BlockExpr(it) => &it.syntax, - Expr::BoxExpr(it) => &it.syntax, - Expr::BreakExpr(it) => &it.syntax, - Expr::CallExpr(it) => &it.syntax, - Expr::CastExpr(it) => &it.syntax, - Expr::ClosureExpr(it) => &it.syntax, - Expr::ContinueExpr(it) => &it.syntax, - Expr::EffectExpr(it) => &it.syntax, - Expr::FieldExpr(it) => &it.syntax, - Expr::ForExpr(it) => &it.syntax, - Expr::IfExpr(it) => &it.syntax, - Expr::IndexExpr(it) => &it.syntax, - Expr::Literal(it) => &it.syntax, - Expr::LoopExpr(it) => &it.syntax, - Expr::MacroCall(it) => &it.syntax, - Expr::MatchExpr(it) => &it.syntax, - Expr::MethodCallExpr(it) => &it.syntax, - Expr::ParenExpr(it) => &it.syntax, - Expr::PathExpr(it) => &it.syntax, - Expr::PrefixExpr(it) => &it.syntax, - Expr::RangeExpr(it) => &it.syntax, - Expr::RecordExpr(it) => &it.syntax, - Expr::RefExpr(it) => &it.syntax, - Expr::ReturnExpr(it) => &it.syntax, - Expr::TryExpr(it) => &it.syntax, - Expr::TupleExpr(it) => &it.syntax, - Expr::WhileExpr(it) => &it.syntax, - } - } -} impl From for AdtDef { fn from(node: Enum) -> AdtDef { AdtDef::Enum(node) } } @@ -3432,6 +3431,11 @@ impl std::fmt::Display for Type { std::fmt::Display::fmt(self.syntax(), f) } } +impl std::fmt::Display for Expr { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} impl std::fmt::Display for Item { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) @@ -3447,11 +3451,6 @@ impl std::fmt::Display for FieldList { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for Expr { - 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) @@ -3537,16 +3536,6 @@ impl std::fmt::Display for TypeBoundList { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for Literal { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - std::fmt::Display::fmt(self.syntax(), f) - } -} -impl std::fmt::Display for BlockExpr { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - std::fmt::Display::fmt(self.syntax(), f) - } -} impl std::fmt::Display for SourceFile { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) @@ -3672,6 +3661,11 @@ impl std::fmt::Display for WhereClause { std::fmt::Display::fmt(self.syntax(), f) } } +impl std::fmt::Display for BlockExpr { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} impl std::fmt::Display for SelfParam { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) @@ -3742,6 +3736,11 @@ impl std::fmt::Display for WherePred { std::fmt::Display::fmt(self.syntax(), f) } } +impl std::fmt::Display for Literal { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} impl std::fmt::Display for TokenTree { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0039_type_arg.rast b/crates/ra_syntax/test_data/parser/inline/ok/0039_type_arg.rast index b9381abdcb..69e98b9d6c 100644 --- a/crates/ra_syntax/test_data/parser/inline/ok/0039_type_arg.rast +++ b/crates/ra_syntax/test_data/parser/inline/ok/0039_type_arg.rast @@ -27,7 +27,8 @@ SOURCE_FILE@0..46 COMMA@23..24 "," WHITESPACE@24..25 " " CONST_ARG@25..26 - INT_NUMBER@25..26 "1" + LITERAL@25..26 + INT_NUMBER@25..26 "1" COMMA@26..27 "," WHITESPACE@27..28 " " CONST_ARG@28..33 diff --git a/xtask/src/codegen/rust.ungram b/xtask/src/codegen/rust.ungram index fa18acbb36..8536b97481 100644 --- a/xtask/src/codegen/rust.ungram +++ b/xtask/src/codegen/rust.ungram @@ -26,7 +26,7 @@ LifetimeArg = 'lifetime' ConstArg = - Literal | BlockExpr BlockExpr + Expr SourceFile = 'shebang'?