aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/ast
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax/src/ast')
-rw-r--r--crates/ra_syntax/src/ast/edit.rs4
-rw-r--r--crates/ra_syntax/src/ast/expr_ext.rs2
-rw-r--r--crates/ra_syntax/src/ast/generated/nodes.rs415
-rw-r--r--crates/ra_syntax/src/ast/make.rs2
-rw-r--r--crates/ra_syntax/src/ast/node_ext.rs2
5 files changed, 214 insertions, 211 deletions
diff --git a/crates/ra_syntax/src/ast/edit.rs b/crates/ra_syntax/src/ast/edit.rs
index 6ebe10ff6..4a67fd44a 100644
--- a/crates/ra_syntax/src/ast/edit.rs
+++ b/crates/ra_syntax/src/ast/edit.rs
@@ -29,9 +29,9 @@ impl ast::BinExpr {
29 } 29 }
30} 30}
31 31
32impl ast::FnDef { 32impl ast::Fn {
33 #[must_use] 33 #[must_use]
34 pub fn with_body(&self, body: ast::BlockExpr) -> ast::FnDef { 34 pub fn with_body(&self, body: ast::BlockExpr) -> ast::Fn {
35 let mut to_insert: ArrayVec<[SyntaxElement; 2]> = ArrayVec::new(); 35 let mut to_insert: ArrayVec<[SyntaxElement; 2]> = ArrayVec::new();
36 let old_body_or_semi: SyntaxElement = if let Some(old_body) = self.body() { 36 let old_body_or_semi: SyntaxElement = if let Some(old_body) = self.body() {
37 old_body.syntax().clone().into() 37 old_body.syntax().clone().into()
diff --git a/crates/ra_syntax/src/ast/expr_ext.rs b/crates/ra_syntax/src/ast/expr_ext.rs
index 69c85c809..8692b9bb5 100644
--- a/crates/ra_syntax/src/ast/expr_ext.rs
+++ b/crates/ra_syntax/src/ast/expr_ext.rs
@@ -401,7 +401,7 @@ impl ast::BlockExpr {
401 Some(it) => it, 401 Some(it) => it,
402 None => return true, 402 None => return true,
403 }; 403 };
404 !matches!(parent.kind(), FN_DEF | IF_EXPR | WHILE_EXPR | LOOP_EXPR | EFFECT_EXPR) 404 !matches!(parent.kind(), FN | IF_EXPR | WHILE_EXPR | LOOP_EXPR | EFFECT_EXPR)
405 } 405 }
406} 406}
407 407
diff --git a/crates/ra_syntax/src/ast/generated/nodes.rs b/crates/ra_syntax/src/ast/generated/nodes.rs
index be657699f..4fc35585d 100644
--- a/crates/ra_syntax/src/ast/generated/nodes.rs
+++ b/crates/ra_syntax/src/ast/generated/nodes.rs
@@ -79,19 +79,19 @@ impl ExternCrate {
79 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } 79 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
80} 80}
81#[derive(Debug, Clone, PartialEq, Eq, Hash)] 81#[derive(Debug, Clone, PartialEq, Eq, Hash)]
82pub struct FnDef { 82pub struct Fn {
83 pub(crate) syntax: SyntaxNode, 83 pub(crate) syntax: SyntaxNode,
84} 84}
85impl ast::AttrsOwner for FnDef {} 85impl ast::AttrsOwner for Fn {}
86impl ast::NameOwner for FnDef {} 86impl ast::NameOwner for Fn {}
87impl ast::VisibilityOwner for FnDef {} 87impl ast::VisibilityOwner for Fn {}
88impl ast::TypeParamsOwner for FnDef {} 88impl ast::TypeParamsOwner for Fn {}
89impl FnDef { 89impl Fn {
90 pub fn abi(&self) -> Option<Abi> { support::child(&self.syntax) }
91 pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) }
92 pub fn default_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![default]) } 90 pub fn default_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![default]) }
93 pub fn async_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![async]) } 91 pub fn async_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![async]) }
92 pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) }
94 pub fn unsafe_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![unsafe]) } 93 pub fn unsafe_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![unsafe]) }
94 pub fn abi(&self) -> Option<Abi> { support::child(&self.syntax) }
95 pub fn fn_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![fn]) } 95 pub fn fn_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![fn]) }
96 pub fn param_list(&self) -> Option<ParamList> { support::child(&self.syntax) } 96 pub fn param_list(&self) -> Option<ParamList> { support::child(&self.syntax) }
97 pub fn ret_type(&self) -> Option<RetType> { support::child(&self.syntax) } 97 pub fn ret_type(&self) -> Option<RetType> { support::child(&self.syntax) }
@@ -303,7 +303,9 @@ impl UseTreeList {
303pub struct Abi { 303pub struct Abi {
304 pub(crate) syntax: SyntaxNode, 304 pub(crate) syntax: SyntaxNode,
305} 305}
306impl Abi {} 306impl Abi {
307 pub fn extern_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![extern]) }
308}
307#[derive(Debug, Clone, PartialEq, Eq, Hash)] 309#[derive(Debug, Clone, PartialEq, Eq, Hash)]
308pub struct TypeParamList { 310pub struct TypeParamList {
309 pub(crate) syntax: SyntaxNode, 311 pub(crate) syntax: SyntaxNode,
@@ -321,8 +323,9 @@ pub struct ParamList {
321} 323}
322impl ParamList { 324impl ParamList {
323 pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) } 325 pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) }
324 pub fn self_param(&self) -> Option<SelfParam> { support::child(&self.syntax) }
325 pub fn params(&self) -> AstChildren<Param> { support::children(&self.syntax) } 326 pub fn params(&self) -> AstChildren<Param> { support::children(&self.syntax) }
327 pub fn self_param(&self) -> Option<SelfParam> { support::child(&self.syntax) }
328 pub fn comma_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![,]) }
326 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } 329 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
327} 330}
328#[derive(Debug, Clone, PartialEq, Eq, Hash)] 331#[derive(Debug, Clone, PartialEq, Eq, Hash)]
@@ -355,6 +358,32 @@ impl BlockExpr {
355 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } 358 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) }
356} 359}
357#[derive(Debug, Clone, PartialEq, Eq, Hash)] 360#[derive(Debug, Clone, PartialEq, Eq, Hash)]
361pub struct Param {
362 pub(crate) syntax: SyntaxNode,
363}
364impl ast::AttrsOwner for Param {}
365impl ast::TypeAscriptionOwner for Param {}
366impl Param {
367 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) }
368 pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) }
369 pub fn dotdotdot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![...]) }
370}
371#[derive(Debug, Clone, PartialEq, Eq, Hash)]
372pub struct SelfParam {
373 pub(crate) syntax: SyntaxNode,
374}
375impl ast::AttrsOwner for SelfParam {}
376impl ast::TypeAscriptionOwner for SelfParam {}
377impl SelfParam {
378 pub fn amp_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![&]) }
379 pub fn lifetime_token(&self) -> Option<SyntaxToken> {
380 support::token(&self.syntax, T![lifetime])
381 }
382 pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) }
383 pub fn self_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![self]) }
384 pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) }
385}
386#[derive(Debug, Clone, PartialEq, Eq, Hash)]
358pub struct RecordFieldDefList { 387pub struct RecordFieldDefList {
359 pub(crate) syntax: SyntaxNode, 388 pub(crate) syntax: SyntaxNode,
360} 389}
@@ -1173,32 +1202,6 @@ impl LetStmt {
1173 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } 1202 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
1174} 1203}
1175#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1204#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1176pub struct SelfParam {
1177 pub(crate) syntax: SyntaxNode,
1178}
1179impl ast::AttrsOwner for SelfParam {}
1180impl ast::TypeAscriptionOwner for SelfParam {}
1181impl SelfParam {
1182 pub fn amp_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![&]) }
1183 pub fn lifetime_token(&self) -> Option<SyntaxToken> {
1184 support::token(&self.syntax, T![lifetime])
1185 }
1186 pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) }
1187 pub fn self_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![self]) }
1188 pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) }
1189}
1190#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1191pub struct Param {
1192 pub(crate) syntax: SyntaxNode,
1193}
1194impl ast::AttrsOwner for Param {}
1195impl ast::TypeAscriptionOwner for Param {}
1196impl Param {
1197 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) }
1198 pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) }
1199 pub fn dotdotdot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![...]) }
1200}
1201#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1202pub struct PathSegment { 1205pub struct PathSegment {
1203 pub(crate) syntax: SyntaxNode, 1206 pub(crate) syntax: SyntaxNode,
1204} 1207}
@@ -1274,7 +1277,7 @@ pub enum Item {
1274 EnumDef(EnumDef), 1277 EnumDef(EnumDef),
1275 ExternBlock(ExternBlock), 1278 ExternBlock(ExternBlock),
1276 ExternCrate(ExternCrate), 1279 ExternCrate(ExternCrate),
1277 FnDef(FnDef), 1280 Fn(Fn),
1278 ImplDef(ImplDef), 1281 ImplDef(ImplDef),
1279 MacroCall(MacroCall), 1282 MacroCall(MacroCall),
1280 Module(Module), 1283 Module(Module),
@@ -1303,6 +1306,24 @@ pub enum TypeRef {
1303 DynTraitType(DynTraitType), 1306 DynTraitType(DynTraitType),
1304} 1307}
1305#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1308#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1309pub enum Pat {
1310 OrPat(OrPat),
1311 ParenPat(ParenPat),
1312 RefPat(RefPat),
1313 BoxPat(BoxPat),
1314 BindPat(BindPat),
1315 PlaceholderPat(PlaceholderPat),
1316 DotDotPat(DotDotPat),
1317 PathPat(PathPat),
1318 RecordPat(RecordPat),
1319 TupleStructPat(TupleStructPat),
1320 TuplePat(TuplePat),
1321 SlicePat(SlicePat),
1322 RangePat(RangePat),
1323 LiteralPat(LiteralPat),
1324 MacroPat(MacroPat),
1325}
1326#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1306pub enum FieldDefList { 1327pub enum FieldDefList {
1307 RecordFieldDefList(RecordFieldDefList), 1328 RecordFieldDefList(RecordFieldDefList),
1308 TupleFieldDefList(TupleFieldDefList), 1329 TupleFieldDefList(TupleFieldDefList),
@@ -1343,7 +1364,7 @@ pub enum Expr {
1343} 1364}
1344#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1365#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1345pub enum AssocItem { 1366pub enum AssocItem {
1346 FnDef(FnDef), 1367 Fn(Fn),
1347 TypeAliasDef(TypeAliasDef), 1368 TypeAliasDef(TypeAliasDef),
1348 ConstDef(ConstDef), 1369 ConstDef(ConstDef),
1349 MacroCall(MacroCall), 1370 MacroCall(MacroCall),
@@ -1351,24 +1372,6 @@ pub enum AssocItem {
1351impl ast::AttrsOwner for AssocItem {} 1372impl ast::AttrsOwner for AssocItem {}
1352impl ast::NameOwner for AssocItem {} 1373impl ast::NameOwner for AssocItem {}
1353#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1374#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1354pub enum Pat {
1355 OrPat(OrPat),
1356 ParenPat(ParenPat),
1357 RefPat(RefPat),
1358 BoxPat(BoxPat),
1359 BindPat(BindPat),
1360 PlaceholderPat(PlaceholderPat),
1361 DotDotPat(DotDotPat),
1362 PathPat(PathPat),
1363 RecordPat(RecordPat),
1364 TupleStructPat(TupleStructPat),
1365 TuplePat(TuplePat),
1366 SlicePat(SlicePat),
1367 RangePat(RangePat),
1368 LiteralPat(LiteralPat),
1369 MacroPat(MacroPat),
1370}
1371#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1372pub enum Stmt { 1375pub enum Stmt {
1373 LetStmt(LetStmt), 1376 LetStmt(LetStmt),
1374 ExprStmt(ExprStmt), 1377 ExprStmt(ExprStmt),
@@ -1381,7 +1384,7 @@ pub enum AttrInput {
1381} 1384}
1382#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1385#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1383pub enum ExternItem { 1386pub enum ExternItem {
1384 FnDef(FnDef), 1387 Fn(Fn),
1385 StaticDef(StaticDef), 1388 StaticDef(StaticDef),
1386} 1389}
1387impl ast::AttrsOwner for ExternItem {} 1390impl ast::AttrsOwner for ExternItem {}
@@ -1463,8 +1466,8 @@ impl AstNode for ExternCrate {
1463 } 1466 }
1464 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1467 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1465} 1468}
1466impl AstNode for FnDef { 1469impl AstNode for Fn {
1467 fn can_cast(kind: SyntaxKind) -> bool { kind == FN_DEF } 1470 fn can_cast(kind: SyntaxKind) -> bool { kind == FN }
1468 fn cast(syntax: SyntaxNode) -> Option<Self> { 1471 fn cast(syntax: SyntaxNode) -> Option<Self> {
1469 if Self::can_cast(syntax.kind()) { 1472 if Self::can_cast(syntax.kind()) {
1470 Some(Self { syntax }) 1473 Some(Self { syntax })
@@ -1727,6 +1730,28 @@ impl AstNode for BlockExpr {
1727 } 1730 }
1728 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1731 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1729} 1732}
1733impl AstNode for Param {
1734 fn can_cast(kind: SyntaxKind) -> bool { kind == PARAM }
1735 fn cast(syntax: SyntaxNode) -> Option<Self> {
1736 if Self::can_cast(syntax.kind()) {
1737 Some(Self { syntax })
1738 } else {
1739 None
1740 }
1741 }
1742 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1743}
1744impl AstNode for SelfParam {
1745 fn can_cast(kind: SyntaxKind) -> bool { kind == SELF_PARAM }
1746 fn cast(syntax: SyntaxNode) -> Option<Self> {
1747 if Self::can_cast(syntax.kind()) {
1748 Some(Self { syntax })
1749 } else {
1750 None
1751 }
1752 }
1753 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1754}
1730impl AstNode for RecordFieldDefList { 1755impl AstNode for RecordFieldDefList {
1731 fn can_cast(kind: SyntaxKind) -> bool { kind == RECORD_FIELD_DEF_LIST } 1756 fn can_cast(kind: SyntaxKind) -> bool { kind == RECORD_FIELD_DEF_LIST }
1732 fn cast(syntax: SyntaxNode) -> Option<Self> { 1757 fn cast(syntax: SyntaxNode) -> Option<Self> {
@@ -2673,28 +2698,6 @@ impl AstNode for LetStmt {
2673 } 2698 }
2674 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2699 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2675} 2700}
2676impl AstNode for SelfParam {
2677 fn can_cast(kind: SyntaxKind) -> bool { kind == SELF_PARAM }
2678 fn cast(syntax: SyntaxNode) -> Option<Self> {
2679 if Self::can_cast(syntax.kind()) {
2680 Some(Self { syntax })
2681 } else {
2682 None
2683 }
2684 }
2685 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2686}
2687impl AstNode for Param {
2688 fn can_cast(kind: SyntaxKind) -> bool { kind == PARAM }
2689 fn cast(syntax: SyntaxNode) -> Option<Self> {
2690 if Self::can_cast(syntax.kind()) {
2691 Some(Self { syntax })
2692 } else {
2693 None
2694 }
2695 }
2696 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2697}
2698impl AstNode for PathSegment { 2701impl AstNode for PathSegment {
2699 fn can_cast(kind: SyntaxKind) -> bool { kind == PATH_SEGMENT } 2702 fn can_cast(kind: SyntaxKind) -> bool { kind == PATH_SEGMENT }
2700 fn cast(syntax: SyntaxNode) -> Option<Self> { 2703 fn cast(syntax: SyntaxNode) -> Option<Self> {
@@ -2784,8 +2787,8 @@ impl From<ExternBlock> for Item {
2784impl From<ExternCrate> for Item { 2787impl From<ExternCrate> for Item {
2785 fn from(node: ExternCrate) -> Item { Item::ExternCrate(node) } 2788 fn from(node: ExternCrate) -> Item { Item::ExternCrate(node) }
2786} 2789}
2787impl From<FnDef> for Item { 2790impl From<Fn> for Item {
2788 fn from(node: FnDef) -> Item { Item::FnDef(node) } 2791 fn from(node: Fn) -> Item { Item::Fn(node) }
2789} 2792}
2790impl From<ImplDef> for Item { 2793impl From<ImplDef> for Item {
2791 fn from(node: ImplDef) -> Item { Item::ImplDef(node) } 2794 fn from(node: ImplDef) -> Item { Item::ImplDef(node) }
@@ -2817,7 +2820,7 @@ impl From<Use> for Item {
2817impl AstNode for Item { 2820impl AstNode for Item {
2818 fn can_cast(kind: SyntaxKind) -> bool { 2821 fn can_cast(kind: SyntaxKind) -> bool {
2819 match kind { 2822 match kind {
2820 CONST_DEF | ENUM_DEF | EXTERN_BLOCK | EXTERN_CRATE | FN_DEF | IMPL_DEF | MACRO_CALL 2823 CONST_DEF | ENUM_DEF | EXTERN_BLOCK | EXTERN_CRATE | FN | IMPL_DEF | MACRO_CALL
2821 | MODULE | STATIC_DEF | STRUCT_DEF | TRAIT_DEF | TYPE_ALIAS_DEF | UNION_DEF | USE => { 2824 | MODULE | STATIC_DEF | STRUCT_DEF | TRAIT_DEF | TYPE_ALIAS_DEF | UNION_DEF | USE => {
2822 true 2825 true
2823 } 2826 }
@@ -2830,7 +2833,7 @@ impl AstNode for Item {
2830 ENUM_DEF => Item::EnumDef(EnumDef { syntax }), 2833 ENUM_DEF => Item::EnumDef(EnumDef { syntax }),
2831 EXTERN_BLOCK => Item::ExternBlock(ExternBlock { syntax }), 2834 EXTERN_BLOCK => Item::ExternBlock(ExternBlock { syntax }),
2832 EXTERN_CRATE => Item::ExternCrate(ExternCrate { syntax }), 2835 EXTERN_CRATE => Item::ExternCrate(ExternCrate { syntax }),
2833 FN_DEF => Item::FnDef(FnDef { syntax }), 2836 FN => Item::Fn(Fn { syntax }),
2834 IMPL_DEF => Item::ImplDef(ImplDef { syntax }), 2837 IMPL_DEF => Item::ImplDef(ImplDef { syntax }),
2835 MACRO_CALL => Item::MacroCall(MacroCall { syntax }), 2838 MACRO_CALL => Item::MacroCall(MacroCall { syntax }),
2836 MODULE => Item::Module(Module { syntax }), 2839 MODULE => Item::Module(Module { syntax }),
@@ -2850,7 +2853,7 @@ impl AstNode for Item {
2850 Item::EnumDef(it) => &it.syntax, 2853 Item::EnumDef(it) => &it.syntax,
2851 Item::ExternBlock(it) => &it.syntax, 2854 Item::ExternBlock(it) => &it.syntax,
2852 Item::ExternCrate(it) => &it.syntax, 2855 Item::ExternCrate(it) => &it.syntax,
2853 Item::FnDef(it) => &it.syntax, 2856 Item::Fn(it) => &it.syntax,
2854 Item::ImplDef(it) => &it.syntax, 2857 Item::ImplDef(it) => &it.syntax,
2855 Item::MacroCall(it) => &it.syntax, 2858 Item::MacroCall(it) => &it.syntax,
2856 Item::Module(it) => &it.syntax, 2859 Item::Module(it) => &it.syntax,
@@ -2948,6 +2951,101 @@ impl AstNode for TypeRef {
2948 } 2951 }
2949 } 2952 }
2950} 2953}
2954impl From<OrPat> for Pat {
2955 fn from(node: OrPat) -> Pat { Pat::OrPat(node) }
2956}
2957impl From<ParenPat> for Pat {
2958 fn from(node: ParenPat) -> Pat { Pat::ParenPat(node) }
2959}
2960impl From<RefPat> for Pat {
2961 fn from(node: RefPat) -> Pat { Pat::RefPat(node) }
2962}
2963impl From<BoxPat> for Pat {
2964 fn from(node: BoxPat) -> Pat { Pat::BoxPat(node) }
2965}
2966impl From<BindPat> for Pat {
2967 fn from(node: BindPat) -> Pat { Pat::BindPat(node) }
2968}
2969impl From<PlaceholderPat> for Pat {
2970 fn from(node: PlaceholderPat) -> Pat { Pat::PlaceholderPat(node) }
2971}
2972impl From<DotDotPat> for Pat {
2973 fn from(node: DotDotPat) -> Pat { Pat::DotDotPat(node) }
2974}
2975impl From<PathPat> for Pat {
2976 fn from(node: PathPat) -> Pat { Pat::PathPat(node) }
2977}
2978impl From<RecordPat> for Pat {
2979 fn from(node: RecordPat) -> Pat { Pat::RecordPat(node) }
2980}
2981impl From<TupleStructPat> for Pat {
2982 fn from(node: TupleStructPat) -> Pat { Pat::TupleStructPat(node) }
2983}
2984impl From<TuplePat> for Pat {
2985 fn from(node: TuplePat) -> Pat { Pat::TuplePat(node) }
2986}
2987impl From<SlicePat> for Pat {
2988 fn from(node: SlicePat) -> Pat { Pat::SlicePat(node) }
2989}
2990impl From<RangePat> for Pat {
2991 fn from(node: RangePat) -> Pat { Pat::RangePat(node) }
2992}
2993impl From<LiteralPat> for Pat {
2994 fn from(node: LiteralPat) -> Pat { Pat::LiteralPat(node) }
2995}
2996impl From<MacroPat> for Pat {
2997 fn from(node: MacroPat) -> Pat { Pat::MacroPat(node) }
2998}
2999impl AstNode for Pat {
3000 fn can_cast(kind: SyntaxKind) -> bool {
3001 match kind {
3002 OR_PAT | PAREN_PAT | REF_PAT | BOX_PAT | BIND_PAT | PLACEHOLDER_PAT | DOT_DOT_PAT
3003 | PATH_PAT | RECORD_PAT | TUPLE_STRUCT_PAT | TUPLE_PAT | SLICE_PAT | RANGE_PAT
3004 | LITERAL_PAT | MACRO_PAT => true,
3005 _ => false,
3006 }
3007 }
3008 fn cast(syntax: SyntaxNode) -> Option<Self> {
3009 let res = match syntax.kind() {
3010 OR_PAT => Pat::OrPat(OrPat { syntax }),
3011 PAREN_PAT => Pat::ParenPat(ParenPat { syntax }),
3012 REF_PAT => Pat::RefPat(RefPat { syntax }),
3013 BOX_PAT => Pat::BoxPat(BoxPat { syntax }),
3014 BIND_PAT => Pat::BindPat(BindPat { syntax }),
3015 PLACEHOLDER_PAT => Pat::PlaceholderPat(PlaceholderPat { syntax }),
3016 DOT_DOT_PAT => Pat::DotDotPat(DotDotPat { syntax }),
3017 PATH_PAT => Pat::PathPat(PathPat { syntax }),
3018 RECORD_PAT => Pat::RecordPat(RecordPat { syntax }),
3019 TUPLE_STRUCT_PAT => Pat::TupleStructPat(TupleStructPat { syntax }),
3020 TUPLE_PAT => Pat::TuplePat(TuplePat { syntax }),
3021 SLICE_PAT => Pat::SlicePat(SlicePat { syntax }),
3022 RANGE_PAT => Pat::RangePat(RangePat { syntax }),
3023 LITERAL_PAT => Pat::LiteralPat(LiteralPat { syntax }),
3024 MACRO_PAT => Pat::MacroPat(MacroPat { syntax }),
3025 _ => return None,
3026 };
3027 Some(res)
3028 }
3029 fn syntax(&self) -> &SyntaxNode {
3030 match self {
3031 Pat::OrPat(it) => &it.syntax,
3032 Pat::ParenPat(it) => &it.syntax,
3033 Pat::RefPat(it) => &it.syntax,
3034 Pat::BoxPat(it) => &it.syntax,
3035 Pat::BindPat(it) => &it.syntax,
3036 Pat::PlaceholderPat(it) => &it.syntax,
3037 Pat::DotDotPat(it) => &it.syntax,
3038 Pat::PathPat(it) => &it.syntax,
3039 Pat::RecordPat(it) => &it.syntax,
3040 Pat::TupleStructPat(it) => &it.syntax,
3041 Pat::TuplePat(it) => &it.syntax,
3042 Pat::SlicePat(it) => &it.syntax,
3043 Pat::RangePat(it) => &it.syntax,
3044 Pat::LiteralPat(it) => &it.syntax,
3045 Pat::MacroPat(it) => &it.syntax,
3046 }
3047 }
3048}
2951impl From<RecordFieldDefList> for FieldDefList { 3049impl From<RecordFieldDefList> for FieldDefList {
2952 fn from(node: RecordFieldDefList) -> FieldDefList { FieldDefList::RecordFieldDefList(node) } 3050 fn from(node: RecordFieldDefList) -> FieldDefList { FieldDefList::RecordFieldDefList(node) }
2953} 3051}
@@ -3157,8 +3255,8 @@ impl AstNode for Expr {
3157 } 3255 }
3158 } 3256 }
3159} 3257}
3160impl From<FnDef> for AssocItem { 3258impl From<Fn> for AssocItem {
3161 fn from(node: FnDef) -> AssocItem { AssocItem::FnDef(node) } 3259 fn from(node: Fn) -> AssocItem { AssocItem::Fn(node) }
3162} 3260}
3163impl From<TypeAliasDef> for AssocItem { 3261impl From<TypeAliasDef> for AssocItem {
3164 fn from(node: TypeAliasDef) -> AssocItem { AssocItem::TypeAliasDef(node) } 3262 fn from(node: TypeAliasDef) -> AssocItem { AssocItem::TypeAliasDef(node) }
@@ -3172,13 +3270,13 @@ impl From<MacroCall> for AssocItem {
3172impl AstNode for AssocItem { 3270impl AstNode for AssocItem {
3173 fn can_cast(kind: SyntaxKind) -> bool { 3271 fn can_cast(kind: SyntaxKind) -> bool {
3174 match kind { 3272 match kind {
3175 FN_DEF | TYPE_ALIAS_DEF | CONST_DEF | MACRO_CALL => true, 3273 FN | TYPE_ALIAS_DEF | CONST_DEF | MACRO_CALL => true,
3176 _ => false, 3274 _ => false,
3177 } 3275 }
3178 } 3276 }
3179 fn cast(syntax: SyntaxNode) -> Option<Self> { 3277 fn cast(syntax: SyntaxNode) -> Option<Self> {
3180 let res = match syntax.kind() { 3278 let res = match syntax.kind() {
3181 FN_DEF => AssocItem::FnDef(FnDef { syntax }), 3279 FN => AssocItem::Fn(Fn { syntax }),
3182 TYPE_ALIAS_DEF => AssocItem::TypeAliasDef(TypeAliasDef { syntax }), 3280 TYPE_ALIAS_DEF => AssocItem::TypeAliasDef(TypeAliasDef { syntax }),
3183 CONST_DEF => AssocItem::ConstDef(ConstDef { syntax }), 3281 CONST_DEF => AssocItem::ConstDef(ConstDef { syntax }),
3184 MACRO_CALL => AssocItem::MacroCall(MacroCall { syntax }), 3282 MACRO_CALL => AssocItem::MacroCall(MacroCall { syntax }),
@@ -3188,108 +3286,13 @@ impl AstNode for AssocItem {
3188 } 3286 }
3189 fn syntax(&self) -> &SyntaxNode { 3287 fn syntax(&self) -> &SyntaxNode {
3190 match self { 3288 match self {
3191 AssocItem::FnDef(it) => &it.syntax, 3289 AssocItem::Fn(it) => &it.syntax,
3192 AssocItem::TypeAliasDef(it) => &it.syntax, 3290 AssocItem::TypeAliasDef(it) => &it.syntax,
3193 AssocItem::ConstDef(it) => &it.syntax, 3291 AssocItem::ConstDef(it) => &it.syntax,
3194 AssocItem::MacroCall(it) => &it.syntax, 3292 AssocItem::MacroCall(it) => &it.syntax,
3195 } 3293 }
3196 } 3294 }
3197} 3295}
3198impl From<OrPat> for Pat {
3199 fn from(node: OrPat) -> Pat { Pat::OrPat(node) }
3200}
3201impl From<ParenPat> for Pat {
3202 fn from(node: ParenPat) -> Pat { Pat::ParenPat(node) }
3203}
3204impl From<RefPat> for Pat {
3205 fn from(node: RefPat) -> Pat { Pat::RefPat(node) }
3206}
3207impl From<BoxPat> for Pat {
3208 fn from(node: BoxPat) -> Pat { Pat::BoxPat(node) }
3209}
3210impl From<BindPat> for Pat {
3211 fn from(node: BindPat) -> Pat { Pat::BindPat(node) }
3212}
3213impl From<PlaceholderPat> for Pat {
3214 fn from(node: PlaceholderPat) -> Pat { Pat::PlaceholderPat(node) }
3215}
3216impl From<DotDotPat> for Pat {
3217 fn from(node: DotDotPat) -> Pat { Pat::DotDotPat(node) }
3218}
3219impl From<PathPat> for Pat {
3220 fn from(node: PathPat) -> Pat { Pat::PathPat(node) }
3221}
3222impl From<RecordPat> for Pat {
3223 fn from(node: RecordPat) -> Pat { Pat::RecordPat(node) }
3224}
3225impl From<TupleStructPat> for Pat {
3226 fn from(node: TupleStructPat) -> Pat { Pat::TupleStructPat(node) }
3227}
3228impl From<TuplePat> for Pat {
3229 fn from(node: TuplePat) -> Pat { Pat::TuplePat(node) }
3230}
3231impl From<SlicePat> for Pat {
3232 fn from(node: SlicePat) -> Pat { Pat::SlicePat(node) }
3233}
3234impl From<RangePat> for Pat {
3235 fn from(node: RangePat) -> Pat { Pat::RangePat(node) }
3236}
3237impl From<LiteralPat> for Pat {
3238 fn from(node: LiteralPat) -> Pat { Pat::LiteralPat(node) }
3239}
3240impl From<MacroPat> for Pat {
3241 fn from(node: MacroPat) -> Pat { Pat::MacroPat(node) }
3242}
3243impl AstNode for Pat {
3244 fn can_cast(kind: SyntaxKind) -> bool {
3245 match kind {
3246 OR_PAT | PAREN_PAT | REF_PAT | BOX_PAT | BIND_PAT | PLACEHOLDER_PAT | DOT_DOT_PAT
3247 | PATH_PAT | RECORD_PAT | TUPLE_STRUCT_PAT | TUPLE_PAT | SLICE_PAT | RANGE_PAT
3248 | LITERAL_PAT | MACRO_PAT => true,
3249 _ => false,
3250 }
3251 }
3252 fn cast(syntax: SyntaxNode) -> Option<Self> {
3253 let res = match syntax.kind() {
3254 OR_PAT => Pat::OrPat(OrPat { syntax }),
3255 PAREN_PAT => Pat::ParenPat(ParenPat { syntax }),
3256 REF_PAT => Pat::RefPat(RefPat { syntax }),
3257 BOX_PAT => Pat::BoxPat(BoxPat { syntax }),
3258 BIND_PAT => Pat::BindPat(BindPat { syntax }),
3259 PLACEHOLDER_PAT => Pat::PlaceholderPat(PlaceholderPat { syntax }),
3260 DOT_DOT_PAT => Pat::DotDotPat(DotDotPat { syntax }),
3261 PATH_PAT => Pat::PathPat(PathPat { syntax }),
3262 RECORD_PAT => Pat::RecordPat(RecordPat { syntax }),
3263 TUPLE_STRUCT_PAT => Pat::TupleStructPat(TupleStructPat { syntax }),
3264 TUPLE_PAT => Pat::TuplePat(TuplePat { syntax }),
3265 SLICE_PAT => Pat::SlicePat(SlicePat { syntax }),
3266 RANGE_PAT => Pat::RangePat(RangePat { syntax }),
3267 LITERAL_PAT => Pat::LiteralPat(LiteralPat { syntax }),
3268 MACRO_PAT => Pat::MacroPat(MacroPat { syntax }),
3269 _ => return None,
3270 };
3271 Some(res)
3272 }
3273 fn syntax(&self) -> &SyntaxNode {
3274 match self {
3275 Pat::OrPat(it) => &it.syntax,
3276 Pat::ParenPat(it) => &it.syntax,
3277 Pat::RefPat(it) => &it.syntax,
3278 Pat::BoxPat(it) => &it.syntax,
3279 Pat::BindPat(it) => &it.syntax,
3280 Pat::PlaceholderPat(it) => &it.syntax,
3281 Pat::DotDotPat(it) => &it.syntax,
3282 Pat::PathPat(it) => &it.syntax,
3283 Pat::RecordPat(it) => &it.syntax,
3284 Pat::TupleStructPat(it) => &it.syntax,
3285 Pat::TuplePat(it) => &it.syntax,
3286 Pat::SlicePat(it) => &it.syntax,
3287 Pat::RangePat(it) => &it.syntax,
3288 Pat::LiteralPat(it) => &it.syntax,
3289 Pat::MacroPat(it) => &it.syntax,
3290 }
3291 }
3292}
3293impl From<LetStmt> for Stmt { 3296impl From<LetStmt> for Stmt {
3294 fn from(node: LetStmt) -> Stmt { Stmt::LetStmt(node) } 3297 fn from(node: LetStmt) -> Stmt { Stmt::LetStmt(node) }
3295} 3298}
@@ -3346,8 +3349,8 @@ impl AstNode for AttrInput {
3346 } 3349 }
3347 } 3350 }
3348} 3351}
3349impl From<FnDef> for ExternItem { 3352impl From<Fn> for ExternItem {
3350 fn from(node: FnDef) -> ExternItem { ExternItem::FnDef(node) } 3353 fn from(node: Fn) -> ExternItem { ExternItem::Fn(node) }
3351} 3354}
3352impl From<StaticDef> for ExternItem { 3355impl From<StaticDef> for ExternItem {
3353 fn from(node: StaticDef) -> ExternItem { ExternItem::StaticDef(node) } 3356 fn from(node: StaticDef) -> ExternItem { ExternItem::StaticDef(node) }
@@ -3355,13 +3358,13 @@ impl From<StaticDef> for ExternItem {
3355impl AstNode for ExternItem { 3358impl AstNode for ExternItem {
3356 fn can_cast(kind: SyntaxKind) -> bool { 3359 fn can_cast(kind: SyntaxKind) -> bool {
3357 match kind { 3360 match kind {
3358 FN_DEF | STATIC_DEF => true, 3361 FN | STATIC_DEF => true,
3359 _ => false, 3362 _ => false,
3360 } 3363 }
3361 } 3364 }
3362 fn cast(syntax: SyntaxNode) -> Option<Self> { 3365 fn cast(syntax: SyntaxNode) -> Option<Self> {
3363 let res = match syntax.kind() { 3366 let res = match syntax.kind() {
3364 FN_DEF => ExternItem::FnDef(FnDef { syntax }), 3367 FN => ExternItem::Fn(Fn { syntax }),
3365 STATIC_DEF => ExternItem::StaticDef(StaticDef { syntax }), 3368 STATIC_DEF => ExternItem::StaticDef(StaticDef { syntax }),
3366 _ => return None, 3369 _ => return None,
3367 }; 3370 };
@@ -3369,7 +3372,7 @@ impl AstNode for ExternItem {
3369 } 3372 }
3370 fn syntax(&self) -> &SyntaxNode { 3373 fn syntax(&self) -> &SyntaxNode {
3371 match self { 3374 match self {
3372 ExternItem::FnDef(it) => &it.syntax, 3375 ExternItem::Fn(it) => &it.syntax,
3373 ExternItem::StaticDef(it) => &it.syntax, 3376 ExternItem::StaticDef(it) => &it.syntax,
3374 } 3377 }
3375 } 3378 }
@@ -3417,22 +3420,22 @@ impl std::fmt::Display for TypeRef {
3417 std::fmt::Display::fmt(self.syntax(), f) 3420 std::fmt::Display::fmt(self.syntax(), f)
3418 } 3421 }
3419} 3422}
3420impl std::fmt::Display for FieldDefList { 3423impl std::fmt::Display for Pat {
3421 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3424 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3422 std::fmt::Display::fmt(self.syntax(), f) 3425 std::fmt::Display::fmt(self.syntax(), f)
3423 } 3426 }
3424} 3427}
3425impl std::fmt::Display for Expr { 3428impl std::fmt::Display for FieldDefList {
3426 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3429 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3427 std::fmt::Display::fmt(self.syntax(), f) 3430 std::fmt::Display::fmt(self.syntax(), f)
3428 } 3431 }
3429} 3432}
3430impl std::fmt::Display for AssocItem { 3433impl std::fmt::Display for Expr {
3431 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3434 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3432 std::fmt::Display::fmt(self.syntax(), f) 3435 std::fmt::Display::fmt(self.syntax(), f)
3433 } 3436 }
3434} 3437}
3435impl std::fmt::Display for Pat { 3438impl std::fmt::Display for AssocItem {
3436 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3439 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3437 std::fmt::Display::fmt(self.syntax(), f) 3440 std::fmt::Display::fmt(self.syntax(), f)
3438 } 3441 }
@@ -3487,7 +3490,7 @@ impl std::fmt::Display for ExternCrate {
3487 std::fmt::Display::fmt(self.syntax(), f) 3490 std::fmt::Display::fmt(self.syntax(), f)
3488 } 3491 }
3489} 3492}
3490impl std::fmt::Display for FnDef { 3493impl std::fmt::Display for Fn {
3491 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3494 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3492 std::fmt::Display::fmt(self.syntax(), f) 3495 std::fmt::Display::fmt(self.syntax(), f)
3493 } 3496 }
@@ -3607,6 +3610,16 @@ impl std::fmt::Display for BlockExpr {
3607 std::fmt::Display::fmt(self.syntax(), f) 3610 std::fmt::Display::fmt(self.syntax(), f)
3608 } 3611 }
3609} 3612}
3613impl std::fmt::Display for Param {
3614 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3615 std::fmt::Display::fmt(self.syntax(), f)
3616 }
3617}
3618impl std::fmt::Display for SelfParam {
3619 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3620 std::fmt::Display::fmt(self.syntax(), f)
3621 }
3622}
3610impl std::fmt::Display for RecordFieldDefList { 3623impl std::fmt::Display for RecordFieldDefList {
3611 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3624 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3612 std::fmt::Display::fmt(self.syntax(), f) 3625 std::fmt::Display::fmt(self.syntax(), f)
@@ -4037,16 +4050,6 @@ impl std::fmt::Display for LetStmt {
4037 std::fmt::Display::fmt(self.syntax(), f) 4050 std::fmt::Display::fmt(self.syntax(), f)
4038 } 4051 }
4039} 4052}
4040impl std::fmt::Display for SelfParam {
4041 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4042 std::fmt::Display::fmt(self.syntax(), f)
4043 }
4044}
4045impl std::fmt::Display for Param {
4046 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4047 std::fmt::Display::fmt(self.syntax(), f)
4048 }
4049}
4050impl std::fmt::Display for PathSegment { 4053impl std::fmt::Display for PathSegment {
4051 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 4054 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4052 std::fmt::Display::fmt(self.syntax(), f) 4055 std::fmt::Display::fmt(self.syntax(), f)
diff --git a/crates/ra_syntax/src/ast/make.rs b/crates/ra_syntax/src/ast/make.rs
index 0ff69bc2d..ef235680f 100644
--- a/crates/ra_syntax/src/ast/make.rs
+++ b/crates/ra_syntax/src/ast/make.rs
@@ -294,7 +294,7 @@ pub fn fn_def(
294 type_params: Option<ast::TypeParamList>, 294 type_params: Option<ast::TypeParamList>,
295 params: ast::ParamList, 295 params: ast::ParamList,
296 body: ast::BlockExpr, 296 body: ast::BlockExpr,
297) -> ast::FnDef { 297) -> ast::Fn {
298 let type_params = 298 let type_params =
299 if let Some(type_params) = type_params { format!("<{}>", type_params) } else { "".into() }; 299 if let Some(type_params) = type_params { format!("<{}>", type_params) } else { "".into() };
300 let visibility = match visibility { 300 let visibility = match visibility {
diff --git a/crates/ra_syntax/src/ast/node_ext.rs b/crates/ra_syntax/src/ast/node_ext.rs
index 242900643..9fb6b7268 100644
--- a/crates/ra_syntax/src/ast/node_ext.rs
+++ b/crates/ra_syntax/src/ast/node_ext.rs
@@ -474,7 +474,7 @@ impl ast::TokenTree {
474} 474}
475 475
476impl ast::DocCommentsOwner for ast::SourceFile {} 476impl ast::DocCommentsOwner for ast::SourceFile {}
477impl ast::DocCommentsOwner for ast::FnDef {} 477impl ast::DocCommentsOwner for ast::Fn {}
478impl ast::DocCommentsOwner for ast::StructDef {} 478impl ast::DocCommentsOwner for ast::StructDef {}
479impl ast::DocCommentsOwner for ast::UnionDef {} 479impl ast::DocCommentsOwner for ast::UnionDef {}
480impl ast::DocCommentsOwner for ast::RecordFieldDef {} 480impl ast::DocCommentsOwner for ast::RecordFieldDef {}