From b250ae6c55c446f65f85914d98da2cd2c75871f7 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 31 Jul 2020 15:01:18 +0200 Subject: Finalize TypeBound grammar --- crates/ra_hir_def/src/generics.rs | 2 +- crates/ra_syntax/src/ast/generated/nodes.rs | 54 ++++++++++++++--------------- crates/ra_syntax/src/ast/node_ext.rs | 20 ----------- 3 files changed, 28 insertions(+), 48 deletions(-) (limited to 'crates') diff --git a/crates/ra_hir_def/src/generics.rs b/crates/ra_hir_def/src/generics.rs index be0b45af3..699ba9c92 100644 --- a/crates/ra_hir_def/src/generics.rs +++ b/crates/ra_hir_def/src/generics.rs @@ -270,7 +270,7 @@ impl GenericParams { bound: ast::TypeBound, type_ref: TypeRef, ) { - if bound.question_token().is_some() { + if bound.question_mark_token().is_some() { // FIXME: remove this bound return; } diff --git a/crates/ra_syntax/src/ast/generated/nodes.rs b/crates/ra_syntax/src/ast/generated/nodes.rs index afa37f227..9064398a9 100644 --- a/crates/ra_syntax/src/ast/generated/nodes.rs +++ b/crates/ra_syntax/src/ast/generated/nodes.rs @@ -639,6 +639,17 @@ impl DynTraitType { pub fn type_bound_list(&self) -> Option { support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct TypeBound { + pub(crate) syntax: SyntaxNode, +} +impl TypeBound { + pub fn lifetime_token(&self) -> Option { + support::token(&self.syntax, T![lifetime]) + } + pub fn question_mark_token(&self) -> Option { support::token(&self.syntax, T![?]) } + pub fn ty(&self) -> Option { support::child(&self.syntax) } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TupleExpr { pub(crate) syntax: SyntaxNode, } @@ -1168,17 +1179,6 @@ impl MacroStmts { pub fn expr(&self) -> Option { support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct TypeBound { - pub(crate) syntax: SyntaxNode, -} -impl TypeBound { - pub fn lifetime_token(&self) -> Option { - support::token(&self.syntax, T![lifetime]) - } - pub fn const_token(&self) -> Option { support::token(&self.syntax, T![const]) } - pub fn ty(&self) -> Option { support::child(&self.syntax) } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct WherePred { pub(crate) syntax: SyntaxNode, } @@ -2045,6 +2045,17 @@ impl AstNode for DynTraitType { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } +impl AstNode for TypeBound { + fn can_cast(kind: SyntaxKind) -> bool { kind == TYPE_BOUND } + 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 TupleExpr { fn can_cast(kind: SyntaxKind) -> bool { kind == TUPLE_EXPR } fn cast(syntax: SyntaxNode) -> Option { @@ -2661,17 +2672,6 @@ impl AstNode for MacroStmts { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for TypeBound { - fn can_cast(kind: SyntaxKind) -> bool { kind == TYPE_BOUND } - 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 WherePred { fn can_cast(kind: SyntaxKind) -> bool { kind == WHERE_PRED } fn cast(syntax: SyntaxNode) -> Option { @@ -3746,6 +3746,11 @@ impl std::fmt::Display for DynTraitType { std::fmt::Display::fmt(self.syntax(), f) } } +impl std::fmt::Display for TypeBound { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} impl std::fmt::Display for TupleExpr { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) @@ -4026,11 +4031,6 @@ impl std::fmt::Display for MacroStmts { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for TypeBound { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - std::fmt::Display::fmt(self.syntax(), f) - } -} impl std::fmt::Display for WherePred { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) diff --git a/crates/ra_syntax/src/ast/node_ext.rs b/crates/ra_syntax/src/ast/node_ext.rs index 30c2db56b..69726fb93 100644 --- a/crates/ra_syntax/src/ast/node_ext.rs +++ b/crates/ra_syntax/src/ast/node_ext.rs @@ -362,26 +362,6 @@ impl ast::TypeBound { unreachable!() } } - - pub fn const_question_token(&self) -> Option { - self.syntax() - .children_with_tokens() - .filter_map(|it| it.into_token()) - .take_while(|it| it.kind() != T![const]) - .find(|it| it.kind() == T![?]) - } - - pub fn question_token(&self) -> Option { - if self.const_token().is_some() { - self.syntax() - .children_with_tokens() - .filter_map(|it| it.into_token()) - .skip_while(|it| it.kind() != T![const]) - .find(|it| it.kind() == T![?]) - } else { - support::token(&self.syntax, T![?]) - } - } } pub enum VisibilityKind { -- cgit v1.2.3