Finalize TypeBound grammar

This commit is contained in:
Aleksey Kladov 2020-07-31 15:01:18 +02:00
parent a6527ed92c
commit b250ae6c55
4 changed files with 35 additions and 54 deletions

View file

@ -639,6 +639,17 @@ impl DynTraitType {
pub fn type_bound_list(&self) -> Option<TypeBoundList> { 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<SyntaxToken> {
support::token(&self.syntax, T![lifetime])
}
pub fn question_mark_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![?]) }
pub fn ty(&self) -> Option<Type> { 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<Expr> { 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<SyntaxToken> {
support::token(&self.syntax, T![lifetime])
}
pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) }
pub fn ty(&self) -> Option<Type> { 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<Self> {
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<Self> {
@ -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<Self> {
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<Self> {
@ -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)