aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax/src')
-rw-r--r--crates/ra_syntax/src/ast/edit.rs4
-rw-r--r--crates/ra_syntax/src/ast/generated/nodes.rs92
-rw-r--r--crates/ra_syntax/src/ast/node_ext.rs2
-rw-r--r--crates/ra_syntax/src/parsing/text_tree_sink.rs2
-rw-r--r--crates/ra_syntax/src/validation.rs4
5 files changed, 51 insertions, 53 deletions
diff --git a/crates/ra_syntax/src/ast/edit.rs b/crates/ra_syntax/src/ast/edit.rs
index 4a67fd44a..0110300af 100644
--- a/crates/ra_syntax/src/ast/edit.rs
+++ b/crates/ra_syntax/src/ast/edit.rs
@@ -192,9 +192,9 @@ impl ast::RecordFieldList {
192 } 192 }
193} 193}
194 194
195impl ast::TypeAliasDef { 195impl ast::TypeAlias {
196 #[must_use] 196 #[must_use]
197 pub fn remove_bounds(&self) -> ast::TypeAliasDef { 197 pub fn remove_bounds(&self) -> ast::TypeAlias {
198 let colon = match self.colon_token() { 198 let colon = match self.colon_token() {
199 Some(it) => it, 199 Some(it) => it,
200 None => return self.clone(), 200 None => return self.clone(),
diff --git a/crates/ra_syntax/src/ast/generated/nodes.rs b/crates/ra_syntax/src/ast/generated/nodes.rs
index 4fc35585d..ad8ccf1ce 100644
--- a/crates/ra_syntax/src/ast/generated/nodes.rs
+++ b/crates/ra_syntax/src/ast/generated/nodes.rs
@@ -183,15 +183,15 @@ impl TraitDef {
183 pub fn assoc_item_list(&self) -> Option<AssocItemList> { support::child(&self.syntax) } 183 pub fn assoc_item_list(&self) -> Option<AssocItemList> { support::child(&self.syntax) }
184} 184}
185#[derive(Debug, Clone, PartialEq, Eq, Hash)] 185#[derive(Debug, Clone, PartialEq, Eq, Hash)]
186pub struct TypeAliasDef { 186pub struct TypeAlias {
187 pub(crate) syntax: SyntaxNode, 187 pub(crate) syntax: SyntaxNode,
188} 188}
189impl ast::AttrsOwner for TypeAliasDef {} 189impl ast::AttrsOwner for TypeAlias {}
190impl ast::NameOwner for TypeAliasDef {} 190impl ast::NameOwner for TypeAlias {}
191impl ast::VisibilityOwner for TypeAliasDef {} 191impl ast::VisibilityOwner for TypeAlias {}
192impl ast::TypeParamsOwner for TypeAliasDef {} 192impl ast::TypeParamsOwner for TypeAlias {}
193impl ast::TypeBoundsOwner for TypeAliasDef {} 193impl ast::TypeBoundsOwner for TypeAlias {}
194impl TypeAliasDef { 194impl TypeAlias {
195 pub fn default_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![default]) } 195 pub fn default_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![default]) }
196 pub fn type_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![type]) } 196 pub fn type_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![type]) }
197 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } 197 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) }
@@ -384,6 +384,13 @@ impl SelfParam {
384 pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) } 384 pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) }
385} 385}
386#[derive(Debug, Clone, PartialEq, Eq, Hash)] 386#[derive(Debug, Clone, PartialEq, Eq, Hash)]
387pub struct TypeBoundList {
388 pub(crate) syntax: SyntaxNode,
389}
390impl TypeBoundList {
391 pub fn bounds(&self) -> AstChildren<TypeBound> { support::children(&self.syntax) }
392}
393#[derive(Debug, Clone, PartialEq, Eq, Hash)]
387pub struct RecordFieldDefList { 394pub struct RecordFieldDefList {
388 pub(crate) syntax: SyntaxNode, 395 pub(crate) syntax: SyntaxNode,
389} 396}
@@ -444,13 +451,6 @@ impl EnumVariant {
444 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 451 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
445} 452}
446#[derive(Debug, Clone, PartialEq, Eq, Hash)] 453#[derive(Debug, Clone, PartialEq, Eq, Hash)]
447pub struct TypeBoundList {
448 pub(crate) syntax: SyntaxNode,
449}
450impl TypeBoundList {
451 pub fn bounds(&self) -> AstChildren<TypeBound> { support::children(&self.syntax) }
452}
453#[derive(Debug, Clone, PartialEq, Eq, Hash)]
454pub struct AssocItemList { 454pub struct AssocItemList {
455 pub(crate) syntax: SyntaxNode, 455 pub(crate) syntax: SyntaxNode,
456} 456}
@@ -1284,7 +1284,7 @@ pub enum Item {
1284 StaticDef(StaticDef), 1284 StaticDef(StaticDef),
1285 StructDef(StructDef), 1285 StructDef(StructDef),
1286 TraitDef(TraitDef), 1286 TraitDef(TraitDef),
1287 TypeAliasDef(TypeAliasDef), 1287 TypeAlias(TypeAlias),
1288 UnionDef(UnionDef), 1288 UnionDef(UnionDef),
1289 Use(Use), 1289 Use(Use),
1290} 1290}
@@ -1365,7 +1365,7 @@ pub enum Expr {
1365#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1365#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1366pub enum AssocItem { 1366pub enum AssocItem {
1367 Fn(Fn), 1367 Fn(Fn),
1368 TypeAliasDef(TypeAliasDef), 1368 TypeAlias(TypeAlias),
1369 ConstDef(ConstDef), 1369 ConstDef(ConstDef),
1370 MacroCall(MacroCall), 1370 MacroCall(MacroCall),
1371} 1371}
@@ -1543,8 +1543,8 @@ impl AstNode for TraitDef {
1543 } 1543 }
1544 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1544 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1545} 1545}
1546impl AstNode for TypeAliasDef { 1546impl AstNode for TypeAlias {
1547 fn can_cast(kind: SyntaxKind) -> bool { kind == TYPE_ALIAS_DEF } 1547 fn can_cast(kind: SyntaxKind) -> bool { kind == TYPE_ALIAS }
1548 fn cast(syntax: SyntaxNode) -> Option<Self> { 1548 fn cast(syntax: SyntaxNode) -> Option<Self> {
1549 if Self::can_cast(syntax.kind()) { 1549 if Self::can_cast(syntax.kind()) {
1550 Some(Self { syntax }) 1550 Some(Self { syntax })
@@ -1752,6 +1752,17 @@ impl AstNode for SelfParam {
1752 } 1752 }
1753 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1753 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1754} 1754}
1755impl AstNode for TypeBoundList {
1756 fn can_cast(kind: SyntaxKind) -> bool { kind == TYPE_BOUND_LIST }
1757 fn cast(syntax: SyntaxNode) -> Option<Self> {
1758 if Self::can_cast(syntax.kind()) {
1759 Some(Self { syntax })
1760 } else {
1761 None
1762 }
1763 }
1764 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1765}
1755impl AstNode for RecordFieldDefList { 1766impl AstNode for RecordFieldDefList {
1756 fn can_cast(kind: SyntaxKind) -> bool { kind == RECORD_FIELD_DEF_LIST } 1767 fn can_cast(kind: SyntaxKind) -> bool { kind == RECORD_FIELD_DEF_LIST }
1757 fn cast(syntax: SyntaxNode) -> Option<Self> { 1768 fn cast(syntax: SyntaxNode) -> Option<Self> {
@@ -1818,17 +1829,6 @@ impl AstNode for EnumVariant {
1818 } 1829 }
1819 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1830 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1820} 1831}
1821impl AstNode for TypeBoundList {
1822 fn can_cast(kind: SyntaxKind) -> bool { kind == TYPE_BOUND_LIST }
1823 fn cast(syntax: SyntaxNode) -> Option<Self> {
1824 if Self::can_cast(syntax.kind()) {
1825 Some(Self { syntax })
1826 } else {
1827 None
1828 }
1829 }
1830 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1831}
1832impl AstNode for AssocItemList { 1832impl AstNode for AssocItemList {
1833 fn can_cast(kind: SyntaxKind) -> bool { kind == ASSOC_ITEM_LIST } 1833 fn can_cast(kind: SyntaxKind) -> bool { kind == ASSOC_ITEM_LIST }
1834 fn cast(syntax: SyntaxNode) -> Option<Self> { 1834 fn cast(syntax: SyntaxNode) -> Option<Self> {
@@ -2808,8 +2808,8 @@ impl From<StructDef> for Item {
2808impl From<TraitDef> for Item { 2808impl From<TraitDef> for Item {
2809 fn from(node: TraitDef) -> Item { Item::TraitDef(node) } 2809 fn from(node: TraitDef) -> Item { Item::TraitDef(node) }
2810} 2810}
2811impl From<TypeAliasDef> for Item { 2811impl From<TypeAlias> for Item {
2812 fn from(node: TypeAliasDef) -> Item { Item::TypeAliasDef(node) } 2812 fn from(node: TypeAlias) -> Item { Item::TypeAlias(node) }
2813} 2813}
2814impl From<UnionDef> for Item { 2814impl From<UnionDef> for Item {
2815 fn from(node: UnionDef) -> Item { Item::UnionDef(node) } 2815 fn from(node: UnionDef) -> Item { Item::UnionDef(node) }
@@ -2821,9 +2821,7 @@ impl AstNode for Item {
2821 fn can_cast(kind: SyntaxKind) -> bool { 2821 fn can_cast(kind: SyntaxKind) -> bool {
2822 match kind { 2822 match kind {
2823 CONST_DEF | ENUM_DEF | EXTERN_BLOCK | EXTERN_CRATE | FN | IMPL_DEF | MACRO_CALL 2823 CONST_DEF | ENUM_DEF | EXTERN_BLOCK | EXTERN_CRATE | FN | IMPL_DEF | MACRO_CALL
2824 | MODULE | STATIC_DEF | STRUCT_DEF | TRAIT_DEF | TYPE_ALIAS_DEF | UNION_DEF | USE => { 2824 | MODULE | STATIC_DEF | STRUCT_DEF | TRAIT_DEF | TYPE_ALIAS | UNION_DEF | USE => true,
2825 true
2826 }
2827 _ => false, 2825 _ => false,
2828 } 2826 }
2829 } 2827 }
@@ -2840,7 +2838,7 @@ impl AstNode for Item {
2840 STATIC_DEF => Item::StaticDef(StaticDef { syntax }), 2838 STATIC_DEF => Item::StaticDef(StaticDef { syntax }),
2841 STRUCT_DEF => Item::StructDef(StructDef { syntax }), 2839 STRUCT_DEF => Item::StructDef(StructDef { syntax }),
2842 TRAIT_DEF => Item::TraitDef(TraitDef { syntax }), 2840 TRAIT_DEF => Item::TraitDef(TraitDef { syntax }),
2843 TYPE_ALIAS_DEF => Item::TypeAliasDef(TypeAliasDef { syntax }), 2841 TYPE_ALIAS => Item::TypeAlias(TypeAlias { syntax }),
2844 UNION_DEF => Item::UnionDef(UnionDef { syntax }), 2842 UNION_DEF => Item::UnionDef(UnionDef { syntax }),
2845 USE => Item::Use(Use { syntax }), 2843 USE => Item::Use(Use { syntax }),
2846 _ => return None, 2844 _ => return None,
@@ -2860,7 +2858,7 @@ impl AstNode for Item {
2860 Item::StaticDef(it) => &it.syntax, 2858 Item::StaticDef(it) => &it.syntax,
2861 Item::StructDef(it) => &it.syntax, 2859 Item::StructDef(it) => &it.syntax,
2862 Item::TraitDef(it) => &it.syntax, 2860 Item::TraitDef(it) => &it.syntax,
2863 Item::TypeAliasDef(it) => &it.syntax, 2861 Item::TypeAlias(it) => &it.syntax,
2864 Item::UnionDef(it) => &it.syntax, 2862 Item::UnionDef(it) => &it.syntax,
2865 Item::Use(it) => &it.syntax, 2863 Item::Use(it) => &it.syntax,
2866 } 2864 }
@@ -3258,8 +3256,8 @@ impl AstNode for Expr {
3258impl From<Fn> for AssocItem { 3256impl From<Fn> for AssocItem {
3259 fn from(node: Fn) -> AssocItem { AssocItem::Fn(node) } 3257 fn from(node: Fn) -> AssocItem { AssocItem::Fn(node) }
3260} 3258}
3261impl From<TypeAliasDef> for AssocItem { 3259impl From<TypeAlias> for AssocItem {
3262 fn from(node: TypeAliasDef) -> AssocItem { AssocItem::TypeAliasDef(node) } 3260 fn from(node: TypeAlias) -> AssocItem { AssocItem::TypeAlias(node) }
3263} 3261}
3264impl From<ConstDef> for AssocItem { 3262impl From<ConstDef> for AssocItem {
3265 fn from(node: ConstDef) -> AssocItem { AssocItem::ConstDef(node) } 3263 fn from(node: ConstDef) -> AssocItem { AssocItem::ConstDef(node) }
@@ -3270,14 +3268,14 @@ impl From<MacroCall> for AssocItem {
3270impl AstNode for AssocItem { 3268impl AstNode for AssocItem {
3271 fn can_cast(kind: SyntaxKind) -> bool { 3269 fn can_cast(kind: SyntaxKind) -> bool {
3272 match kind { 3270 match kind {
3273 FN | TYPE_ALIAS_DEF | CONST_DEF | MACRO_CALL => true, 3271 FN | TYPE_ALIAS | CONST_DEF | MACRO_CALL => true,
3274 _ => false, 3272 _ => false,
3275 } 3273 }
3276 } 3274 }
3277 fn cast(syntax: SyntaxNode) -> Option<Self> { 3275 fn cast(syntax: SyntaxNode) -> Option<Self> {
3278 let res = match syntax.kind() { 3276 let res = match syntax.kind() {
3279 FN => AssocItem::Fn(Fn { syntax }), 3277 FN => AssocItem::Fn(Fn { syntax }),
3280 TYPE_ALIAS_DEF => AssocItem::TypeAliasDef(TypeAliasDef { syntax }), 3278 TYPE_ALIAS => AssocItem::TypeAlias(TypeAlias { syntax }),
3281 CONST_DEF => AssocItem::ConstDef(ConstDef { syntax }), 3279 CONST_DEF => AssocItem::ConstDef(ConstDef { syntax }),
3282 MACRO_CALL => AssocItem::MacroCall(MacroCall { syntax }), 3280 MACRO_CALL => AssocItem::MacroCall(MacroCall { syntax }),
3283 _ => return None, 3281 _ => return None,
@@ -3287,7 +3285,7 @@ impl AstNode for AssocItem {
3287 fn syntax(&self) -> &SyntaxNode { 3285 fn syntax(&self) -> &SyntaxNode {
3288 match self { 3286 match self {
3289 AssocItem::Fn(it) => &it.syntax, 3287 AssocItem::Fn(it) => &it.syntax,
3290 AssocItem::TypeAliasDef(it) => &it.syntax, 3288 AssocItem::TypeAlias(it) => &it.syntax,
3291 AssocItem::ConstDef(it) => &it.syntax, 3289 AssocItem::ConstDef(it) => &it.syntax,
3292 AssocItem::MacroCall(it) => &it.syntax, 3290 AssocItem::MacroCall(it) => &it.syntax,
3293 } 3291 }
@@ -3525,7 +3523,7 @@ impl std::fmt::Display for TraitDef {
3525 std::fmt::Display::fmt(self.syntax(), f) 3523 std::fmt::Display::fmt(self.syntax(), f)
3526 } 3524 }
3527} 3525}
3528impl std::fmt::Display for TypeAliasDef { 3526impl std::fmt::Display for TypeAlias {
3529 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3527 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3530 std::fmt::Display::fmt(self.syntax(), f) 3528 std::fmt::Display::fmt(self.syntax(), f)
3531 } 3529 }
@@ -3620,6 +3618,11 @@ impl std::fmt::Display for SelfParam {
3620 std::fmt::Display::fmt(self.syntax(), f) 3618 std::fmt::Display::fmt(self.syntax(), f)
3621 } 3619 }
3622} 3620}
3621impl std::fmt::Display for TypeBoundList {
3622 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3623 std::fmt::Display::fmt(self.syntax(), f)
3624 }
3625}
3623impl std::fmt::Display for RecordFieldDefList { 3626impl std::fmt::Display for RecordFieldDefList {
3624 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3627 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3625 std::fmt::Display::fmt(self.syntax(), f) 3628 std::fmt::Display::fmt(self.syntax(), f)
@@ -3650,11 +3653,6 @@ impl std::fmt::Display for EnumVariant {
3650 std::fmt::Display::fmt(self.syntax(), f) 3653 std::fmt::Display::fmt(self.syntax(), f)
3651 } 3654 }
3652} 3655}
3653impl std::fmt::Display for TypeBoundList {
3654 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3655 std::fmt::Display::fmt(self.syntax(), f)
3656 }
3657}
3658impl std::fmt::Display for AssocItemList { 3656impl std::fmt::Display for AssocItemList {
3659 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3657 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3660 std::fmt::Display::fmt(self.syntax(), f) 3658 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 9fb6b7268..a7a301d6b 100644
--- a/crates/ra_syntax/src/ast/node_ext.rs
+++ b/crates/ra_syntax/src/ast/node_ext.rs
@@ -485,6 +485,6 @@ impl ast::DocCommentsOwner for ast::TraitDef {}
485impl ast::DocCommentsOwner for ast::Module {} 485impl ast::DocCommentsOwner for ast::Module {}
486impl ast::DocCommentsOwner for ast::StaticDef {} 486impl ast::DocCommentsOwner for ast::StaticDef {}
487impl ast::DocCommentsOwner for ast::ConstDef {} 487impl ast::DocCommentsOwner for ast::ConstDef {}
488impl ast::DocCommentsOwner for ast::TypeAliasDef {} 488impl ast::DocCommentsOwner for ast::TypeAlias {}
489impl ast::DocCommentsOwner for ast::ImplDef {} 489impl ast::DocCommentsOwner for ast::ImplDef {}
490impl ast::DocCommentsOwner for ast::MacroCall {} 490impl ast::DocCommentsOwner for ast::MacroCall {}
diff --git a/crates/ra_syntax/src/parsing/text_tree_sink.rs b/crates/ra_syntax/src/parsing/text_tree_sink.rs
index 2a0f95d15..87a7acd09 100644
--- a/crates/ra_syntax/src/parsing/text_tree_sink.rs
+++ b/crates/ra_syntax/src/parsing/text_tree_sink.rs
@@ -146,7 +146,7 @@ fn n_attached_trivias<'a>(
146 trivias: impl Iterator<Item = (SyntaxKind, &'a str)>, 146 trivias: impl Iterator<Item = (SyntaxKind, &'a str)>,
147) -> usize { 147) -> usize {
148 match kind { 148 match kind {
149 MACRO_CALL | CONST_DEF | TYPE_ALIAS_DEF | STRUCT_DEF | ENUM_DEF | ENUM_VARIANT | FN 149 MACRO_CALL | CONST_DEF | TYPE_ALIAS | STRUCT_DEF | ENUM_DEF | ENUM_VARIANT | FN
150 | TRAIT_DEF | MODULE | RECORD_FIELD_DEF | STATIC_DEF => { 150 | TRAIT_DEF | MODULE | RECORD_FIELD_DEF | STATIC_DEF => {
151 let mut res = 0; 151 let mut res = 0;
152 let mut trivias = trivias.enumerate().peekable(); 152 let mut trivias = trivias.enumerate().peekable();
diff --git a/crates/ra_syntax/src/validation.rs b/crates/ra_syntax/src/validation.rs
index 2714d102a..6a2749381 100644
--- a/crates/ra_syntax/src/validation.rs
+++ b/crates/ra_syntax/src/validation.rs
@@ -4,7 +4,7 @@ mod block;
4 4
5use crate::{ 5use crate::{
6 ast, match_ast, AstNode, SyntaxError, 6 ast, match_ast, AstNode, SyntaxError,
7 SyntaxKind::{BYTE, BYTE_STRING, CHAR, CONST_DEF, FN, INT_NUMBER, STRING, TYPE_ALIAS_DEF}, 7 SyntaxKind::{BYTE, BYTE_STRING, CHAR, CONST_DEF, FN, INT_NUMBER, STRING, TYPE_ALIAS},
8 SyntaxNode, SyntaxToken, TextSize, T, 8 SyntaxNode, SyntaxToken, TextSize, T,
9}; 9};
10use rustc_lexer::unescape::{ 10use rustc_lexer::unescape::{
@@ -200,7 +200,7 @@ fn validate_visibility(vis: ast::Visibility, errors: &mut Vec<SyntaxError>) {
200 None => return, 200 None => return,
201 }; 201 };
202 match parent.kind() { 202 match parent.kind() {
203 FN | CONST_DEF | TYPE_ALIAS_DEF => (), 203 FN | CONST_DEF | TYPE_ALIAS => (),
204 _ => return, 204 _ => return,
205 } 205 }
206 206