From 23fdc562bf06bd001ec728d63a8f5b945bd96700 Mon Sep 17 00:00:00 2001 From: Ville Penttinen Date: Sat, 30 Mar 2019 17:11:21 +0200 Subject: Add new TYPE_BOUND_LIST and TYPE_BOUND syntax kinds These are now used when parsing type bounds. In addition parsing paths inside a bound now does not recursively parse paths, rather they are treated as separate bounds, separated by +. --- crates/ra_syntax/src/ast/generated.rs | 68 +++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) (limited to 'crates/ra_syntax/src/ast/generated.rs') diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs index 47a37e4d1..faf80bc32 100644 --- a/crates/ra_syntax/src/ast/generated.rs +++ b/crates/ra_syntax/src/ast/generated.rs @@ -4369,6 +4369,74 @@ impl TypeArgList { } } +// TypeBound +#[derive(Debug, PartialEq, Eq, Hash)] +#[repr(transparent)] +pub struct TypeBound { + pub(crate) syntax: SyntaxNode, +} +unsafe impl TransparentNewType for TypeBound { + type Repr = rowan::SyntaxNode; +} + +impl AstNode for TypeBound { + fn cast(syntax: &SyntaxNode) -> Option<&Self> { + match syntax.kind() { + TYPE_BOUND => Some(TypeBound::from_repr(syntax.into_repr())), + _ => None, + } + } + fn syntax(&self) -> &SyntaxNode { &self.syntax } +} + +impl ToOwned for TypeBound { + type Owned = TreeArc; + fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } +} + + +impl TypeBound { + pub fn type_ref(&self) -> Option<&TypeRef> { + super::child_opt(self) + } + + pub fn lifetime(&self) -> Option<&Lifetime> { + super::child_opt(self) + } +} + +// TypeBoundList +#[derive(Debug, PartialEq, Eq, Hash)] +#[repr(transparent)] +pub struct TypeBoundList { + pub(crate) syntax: SyntaxNode, +} +unsafe impl TransparentNewType for TypeBoundList { + type Repr = rowan::SyntaxNode; +} + +impl AstNode for TypeBoundList { + fn cast(syntax: &SyntaxNode) -> Option<&Self> { + match syntax.kind() { + TYPE_BOUND_LIST => Some(TypeBoundList::from_repr(syntax.into_repr())), + _ => None, + } + } + fn syntax(&self) -> &SyntaxNode { &self.syntax } +} + +impl ToOwned for TypeBoundList { + type Owned = TreeArc; + fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } +} + + +impl TypeBoundList { + pub fn bounds(&self) -> impl Iterator { + super::children(self) + } +} + // TypeParam #[derive(Debug, PartialEq, Eq, Hash)] #[repr(transparent)] -- cgit v1.2.3 From 55dcdb7d094f473c73f87ecf997b24f8e35f2a5e Mon Sep 17 00:00:00 2001 From: Ville Penttinen Date: Sun, 31 Mar 2019 10:56:48 +0300 Subject: Add trait ast::TypeBoundsOwner --- crates/ra_syntax/src/ast/generated.rs | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'crates/ra_syntax/src/ast/generated.rs') diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs index faf80bc32..9ea423b40 100644 --- a/crates/ra_syntax/src/ast/generated.rs +++ b/crates/ra_syntax/src/ast/generated.rs @@ -685,6 +685,7 @@ impl ToOwned for DynTraitType { } +impl ast::TypeBoundsOwner for DynTraitType {} impl DynTraitType {} // EnumDef @@ -1581,6 +1582,7 @@ impl ToOwned for ImplTraitType { } +impl ast::TypeBoundsOwner for ImplTraitType {} impl ImplTraitType {} // IndexExpr @@ -4061,6 +4063,7 @@ impl ast::NameOwner for TraitDef {} impl ast::AttrsOwner for TraitDef {} impl ast::DocCommentsOwner for TraitDef {} impl ast::TypeParamsOwner for TraitDef {} +impl ast::TypeBoundsOwner for TraitDef {} impl TraitDef { pub fn item_list(&self) -> Option<&ItemList> { super::child_opt(self) @@ -4291,6 +4294,7 @@ impl ast::NameOwner for TypeAliasDef {} impl ast::TypeParamsOwner for TypeAliasDef {} impl ast::AttrsOwner for TypeAliasDef {} impl ast::DocCommentsOwner for TypeAliasDef {} +impl ast::TypeBoundsOwner for TypeAliasDef {} impl TypeAliasDef { pub fn type_ref(&self) -> Option<&TypeRef> { super::child_opt(self) @@ -4465,6 +4469,7 @@ impl ToOwned for TypeParam { impl ast::NameOwner for TypeParam {} impl ast::AttrsOwner for TypeParam {} +impl ast::TypeBoundsOwner for TypeParam {} impl TypeParam {} // TypeParamList -- cgit v1.2.3