aboutsummaryrefslogtreecommitdiff
path: root/crates/syntax/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/syntax/src')
-rw-r--r--crates/syntax/src/ast.rs6
-rw-r--r--crates/syntax/src/ast/generated/nodes.rs98
-rw-r--r--crates/syntax/src/ast/node_ext.rs66
-rw-r--r--crates/syntax/src/display.rs18
-rw-r--r--crates/syntax/src/parsing/lexer.rs4
5 files changed, 153 insertions, 39 deletions
diff --git a/crates/syntax/src/ast.rs b/crates/syntax/src/ast.rs
index 7844f9ed6..83de067d9 100644
--- a/crates/syntax/src/ast.rs
+++ b/crates/syntax/src/ast.rs
@@ -19,8 +19,8 @@ pub use self::{
19 expr_ext::{ArrayExprKind, BinOp, Effect, ElseBranch, LiteralKind, PrefixOp, RangeOp}, 19 expr_ext::{ArrayExprKind, BinOp, Effect, ElseBranch, LiteralKind, PrefixOp, RangeOp},
20 generated::{nodes::*, tokens::*}, 20 generated::{nodes::*, tokens::*},
21 node_ext::{ 21 node_ext::{
22 AttrKind, FieldKind, NameOrNameRef, PathSegmentKind, SelfParamKind, SlicePatComponents, 22 AttrKind, FieldKind, Macro, NameOrNameRef, PathSegmentKind, SelfParamKind,
23 StructKind, TypeBoundKind, VisibilityKind, 23 SlicePatComponents, StructKind, TypeBoundKind, VisibilityKind,
24 }, 24 },
25 token_ext::*, 25 token_ext::*,
26 traits::*, 26 traits::*,
@@ -311,7 +311,7 @@ where
311 let pred = predicates.next().unwrap(); 311 let pred = predicates.next().unwrap();
312 let mut bounds = pred.type_bound_list().unwrap().bounds(); 312 let mut bounds = pred.type_bound_list().unwrap().bounds();
313 313
314 assert_eq!("'a", pred.lifetime_token().unwrap().text()); 314 assert_eq!("'a", pred.lifetime().unwrap().lifetime_ident_token().unwrap().text());
315 315
316 assert_bound("'b", bounds.next()); 316 assert_bound("'b", bounds.next());
317 assert_bound("'c", bounds.next()); 317 assert_bound("'c", bounds.next());
diff --git a/crates/syntax/src/ast/generated/nodes.rs b/crates/syntax/src/ast/generated/nodes.rs
index 0ad75214f..1588ba93e 100644
--- a/crates/syntax/src/ast/generated/nodes.rs
+++ b/crates/syntax/src/ast/generated/nodes.rs
@@ -20,6 +20,15 @@ impl NameRef {
20 pub fn ident_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![ident]) } 20 pub fn ident_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![ident]) }
21} 21}
22#[derive(Debug, Clone, PartialEq, Eq, Hash)] 22#[derive(Debug, Clone, PartialEq, Eq, Hash)]
23pub struct Lifetime {
24 pub(crate) syntax: SyntaxNode,
25}
26impl Lifetime {
27 pub fn lifetime_ident_token(&self) -> Option<SyntaxToken> {
28 support::token(&self.syntax, T![lifetime_ident])
29 }
30}
31#[derive(Debug, Clone, PartialEq, Eq, Hash)]
23pub struct Path { 32pub struct Path {
24 pub(crate) syntax: SyntaxNode, 33 pub(crate) syntax: SyntaxNode,
25} 34}
@@ -105,9 +114,7 @@ pub struct LifetimeArg {
105 pub(crate) syntax: SyntaxNode, 114 pub(crate) syntax: SyntaxNode,
106} 115}
107impl LifetimeArg { 116impl LifetimeArg {
108 pub fn lifetime_token(&self) -> Option<SyntaxToken> { 117 pub fn lifetime(&self) -> Option<Lifetime> { support::child(&self.syntax) }
109 support::token(&self.syntax, T![lifetime])
110 }
111} 118}
112#[derive(Debug, Clone, PartialEq, Eq, Hash)] 119#[derive(Debug, Clone, PartialEq, Eq, Hash)]
113pub struct ConstArg { 120pub struct ConstArg {
@@ -286,6 +293,18 @@ impl MacroRules {
286 pub fn token_tree(&self) -> Option<TokenTree> { support::child(&self.syntax) } 293 pub fn token_tree(&self) -> Option<TokenTree> { support::child(&self.syntax) }
287} 294}
288#[derive(Debug, Clone, PartialEq, Eq, Hash)] 295#[derive(Debug, Clone, PartialEq, Eq, Hash)]
296pub struct MacroDef {
297 pub(crate) syntax: SyntaxNode,
298}
299impl ast::AttrsOwner for MacroDef {}
300impl ast::NameOwner for MacroDef {}
301impl ast::VisibilityOwner for MacroDef {}
302impl MacroDef {
303 pub fn macro_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![macro]) }
304 pub fn args(&self) -> Option<TokenTree> { support::child(&self.syntax) }
305 pub fn body(&self) -> Option<TokenTree> { support::child(&self.syntax) }
306}
307#[derive(Debug, Clone, PartialEq, Eq, Hash)]
289pub struct Module { 308pub struct Module {
290 pub(crate) syntax: SyntaxNode, 309 pub(crate) syntax: SyntaxNode,
291} 310}
@@ -475,9 +494,7 @@ pub struct SelfParam {
475impl ast::AttrsOwner for SelfParam {} 494impl ast::AttrsOwner for SelfParam {}
476impl SelfParam { 495impl SelfParam {
477 pub fn amp_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![&]) } 496 pub fn amp_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![&]) }
478 pub fn lifetime_token(&self) -> Option<SyntaxToken> { 497 pub fn lifetime(&self) -> Option<Lifetime> { support::child(&self.syntax) }
479 support::token(&self.syntax, T![lifetime])
480 }
481 pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) } 498 pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) }
482 pub fn self_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![self]) } 499 pub fn self_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![self]) }
483 pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) } 500 pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) }
@@ -593,9 +610,7 @@ pub struct LifetimeParam {
593impl ast::AttrsOwner for LifetimeParam {} 610impl ast::AttrsOwner for LifetimeParam {}
594impl ast::TypeBoundsOwner for LifetimeParam {} 611impl ast::TypeBoundsOwner for LifetimeParam {}
595impl LifetimeParam { 612impl LifetimeParam {
596 pub fn lifetime_token(&self) -> Option<SyntaxToken> { 613 pub fn lifetime(&self) -> Option<Lifetime> { support::child(&self.syntax) }
597 support::token(&self.syntax, T![lifetime])
598 }
599} 614}
600#[derive(Debug, Clone, PartialEq, Eq, Hash)] 615#[derive(Debug, Clone, PartialEq, Eq, Hash)]
601pub struct TypeParam { 616pub struct TypeParam {
@@ -616,9 +631,7 @@ impl ast::TypeBoundsOwner for WherePred {}
616impl WherePred { 631impl WherePred {
617 pub fn for_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![for]) } 632 pub fn for_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![for]) }
618 pub fn generic_param_list(&self) -> Option<GenericParamList> { support::child(&self.syntax) } 633 pub fn generic_param_list(&self) -> Option<GenericParamList> { support::child(&self.syntax) }
619 pub fn lifetime_token(&self) -> Option<SyntaxToken> { 634 pub fn lifetime(&self) -> Option<Lifetime> { support::child(&self.syntax) }
620 support::token(&self.syntax, T![lifetime])
621 }
622 pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) } 635 pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
623} 636}
624#[derive(Debug, Clone, PartialEq, Eq, Hash)] 637#[derive(Debug, Clone, PartialEq, Eq, Hash)]
@@ -694,9 +707,7 @@ pub struct BreakExpr {
694impl ast::AttrsOwner for BreakExpr {} 707impl ast::AttrsOwner for BreakExpr {}
695impl BreakExpr { 708impl BreakExpr {
696 pub fn break_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![break]) } 709 pub fn break_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![break]) }
697 pub fn lifetime_token(&self) -> Option<SyntaxToken> { 710 pub fn lifetime(&self) -> Option<Lifetime> { support::child(&self.syntax) }
698 support::token(&self.syntax, T![lifetime])
699 }
700 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 711 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
701} 712}
702#[derive(Debug, Clone, PartialEq, Eq, Hash)] 713#[derive(Debug, Clone, PartialEq, Eq, Hash)]
@@ -740,9 +751,7 @@ impl ContinueExpr {
740 pub fn continue_token(&self) -> Option<SyntaxToken> { 751 pub fn continue_token(&self) -> Option<SyntaxToken> {
741 support::token(&self.syntax, T![continue]) 752 support::token(&self.syntax, T![continue])
742 } 753 }
743 pub fn lifetime_token(&self) -> Option<SyntaxToken> { 754 pub fn lifetime(&self) -> Option<Lifetime> { support::child(&self.syntax) }
744 support::token(&self.syntax, T![lifetime])
745 }
746} 755}
747#[derive(Debug, Clone, PartialEq, Eq, Hash)] 756#[derive(Debug, Clone, PartialEq, Eq, Hash)]
748pub struct EffectExpr { 757pub struct EffectExpr {
@@ -925,9 +934,8 @@ pub struct Label {
925 pub(crate) syntax: SyntaxNode, 934 pub(crate) syntax: SyntaxNode,
926} 935}
927impl Label { 936impl Label {
928 pub fn lifetime_token(&self) -> Option<SyntaxToken> { 937 pub fn lifetime(&self) -> Option<Lifetime> { support::child(&self.syntax) }
929 support::token(&self.syntax, T![lifetime]) 938 pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) }
930 }
931} 939}
932#[derive(Debug, Clone, PartialEq, Eq, Hash)] 940#[derive(Debug, Clone, PartialEq, Eq, Hash)]
933pub struct RecordExprFieldList { 941pub struct RecordExprFieldList {
@@ -1088,9 +1096,7 @@ pub struct RefType {
1088} 1096}
1089impl RefType { 1097impl RefType {
1090 pub fn amp_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![&]) } 1098 pub fn amp_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![&]) }
1091 pub fn lifetime_token(&self) -> Option<SyntaxToken> { 1099 pub fn lifetime(&self) -> Option<Lifetime> { support::child(&self.syntax) }
1092 support::token(&self.syntax, T![lifetime])
1093 }
1094 pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) } 1100 pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) }
1095 pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) } 1101 pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
1096} 1102}
@@ -1117,9 +1123,7 @@ pub struct TypeBound {
1117 pub(crate) syntax: SyntaxNode, 1123 pub(crate) syntax: SyntaxNode,
1118} 1124}
1119impl TypeBound { 1125impl TypeBound {
1120 pub fn lifetime_token(&self) -> Option<SyntaxToken> { 1126 pub fn lifetime(&self) -> Option<Lifetime> { support::child(&self.syntax) }
1121 support::token(&self.syntax, T![lifetime])
1122 }
1123 pub fn question_mark_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![?]) } 1127 pub fn question_mark_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![?]) }
1124 pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) } 1128 pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
1125} 1129}
@@ -1332,6 +1336,7 @@ pub enum Item {
1332 Impl(Impl), 1336 Impl(Impl),
1333 MacroCall(MacroCall), 1337 MacroCall(MacroCall),
1334 MacroRules(MacroRules), 1338 MacroRules(MacroRules),
1339 MacroDef(MacroDef),
1335 Module(Module), 1340 Module(Module),
1336 Static(Static), 1341 Static(Static),
1337 Struct(Struct), 1342 Struct(Struct),
@@ -1425,6 +1430,17 @@ impl AstNode for NameRef {
1425 } 1430 }
1426 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1431 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1427} 1432}
1433impl AstNode for Lifetime {
1434 fn can_cast(kind: SyntaxKind) -> bool { kind == LIFETIME }
1435 fn cast(syntax: SyntaxNode) -> Option<Self> {
1436 if Self::can_cast(syntax.kind()) {
1437 Some(Self { syntax })
1438 } else {
1439 None
1440 }
1441 }
1442 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1443}
1428impl AstNode for Path { 1444impl AstNode for Path {
1429 fn can_cast(kind: SyntaxKind) -> bool { kind == PATH } 1445 fn can_cast(kind: SyntaxKind) -> bool { kind == PATH }
1430 fn cast(syntax: SyntaxNode) -> Option<Self> { 1446 fn cast(syntax: SyntaxNode) -> Option<Self> {
@@ -1689,6 +1705,17 @@ impl AstNode for MacroRules {
1689 } 1705 }
1690 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1706 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1691} 1707}
1708impl AstNode for MacroDef {
1709 fn can_cast(kind: SyntaxKind) -> bool { kind == MACRO_DEF }
1710 fn cast(syntax: SyntaxNode) -> Option<Self> {
1711 if Self::can_cast(syntax.kind()) {
1712 Some(Self { syntax })
1713 } else {
1714 None
1715 }
1716 }
1717 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1718}
1692impl AstNode for Module { 1719impl AstNode for Module {
1693 fn can_cast(kind: SyntaxKind) -> bool { kind == MODULE } 1720 fn can_cast(kind: SyntaxKind) -> bool { kind == MODULE }
1694 fn cast(syntax: SyntaxNode) -> Option<Self> { 1721 fn cast(syntax: SyntaxNode) -> Option<Self> {
@@ -3086,6 +3113,9 @@ impl From<MacroCall> for Item {
3086impl From<MacroRules> for Item { 3113impl From<MacroRules> for Item {
3087 fn from(node: MacroRules) -> Item { Item::MacroRules(node) } 3114 fn from(node: MacroRules) -> Item { Item::MacroRules(node) }
3088} 3115}
3116impl From<MacroDef> for Item {
3117 fn from(node: MacroDef) -> Item { Item::MacroDef(node) }
3118}
3089impl From<Module> for Item { 3119impl From<Module> for Item {
3090 fn from(node: Module) -> Item { Item::Module(node) } 3120 fn from(node: Module) -> Item { Item::Module(node) }
3091} 3121}
@@ -3111,7 +3141,7 @@ impl AstNode for Item {
3111 fn can_cast(kind: SyntaxKind) -> bool { 3141 fn can_cast(kind: SyntaxKind) -> bool {
3112 match kind { 3142 match kind {
3113 CONST | ENUM | EXTERN_BLOCK | EXTERN_CRATE | FN | IMPL | MACRO_CALL | MACRO_RULES 3143 CONST | ENUM | EXTERN_BLOCK | EXTERN_CRATE | FN | IMPL | MACRO_CALL | MACRO_RULES
3114 | MODULE | STATIC | STRUCT | TRAIT | TYPE_ALIAS | UNION | USE => true, 3144 | MACRO_DEF | MODULE | STATIC | STRUCT | TRAIT | TYPE_ALIAS | UNION | USE => true,
3115 _ => false, 3145 _ => false,
3116 } 3146 }
3117 } 3147 }
@@ -3125,6 +3155,7 @@ impl AstNode for Item {
3125 IMPL => Item::Impl(Impl { syntax }), 3155 IMPL => Item::Impl(Impl { syntax }),
3126 MACRO_CALL => Item::MacroCall(MacroCall { syntax }), 3156 MACRO_CALL => Item::MacroCall(MacroCall { syntax }),
3127 MACRO_RULES => Item::MacroRules(MacroRules { syntax }), 3157 MACRO_RULES => Item::MacroRules(MacroRules { syntax }),
3158 MACRO_DEF => Item::MacroDef(MacroDef { syntax }),
3128 MODULE => Item::Module(Module { syntax }), 3159 MODULE => Item::Module(Module { syntax }),
3129 STATIC => Item::Static(Static { syntax }), 3160 STATIC => Item::Static(Static { syntax }),
3130 STRUCT => Item::Struct(Struct { syntax }), 3161 STRUCT => Item::Struct(Struct { syntax }),
@@ -3146,6 +3177,7 @@ impl AstNode for Item {
3146 Item::Impl(it) => &it.syntax, 3177 Item::Impl(it) => &it.syntax,
3147 Item::MacroCall(it) => &it.syntax, 3178 Item::MacroCall(it) => &it.syntax,
3148 Item::MacroRules(it) => &it.syntax, 3179 Item::MacroRules(it) => &it.syntax,
3180 Item::MacroDef(it) => &it.syntax,
3149 Item::Module(it) => &it.syntax, 3181 Item::Module(it) => &it.syntax,
3150 Item::Static(it) => &it.syntax, 3182 Item::Static(it) => &it.syntax,
3151 Item::Struct(it) => &it.syntax, 3183 Item::Struct(it) => &it.syntax,
@@ -3495,6 +3527,11 @@ impl std::fmt::Display for NameRef {
3495 std::fmt::Display::fmt(self.syntax(), f) 3527 std::fmt::Display::fmt(self.syntax(), f)
3496 } 3528 }
3497} 3529}
3530impl std::fmt::Display for Lifetime {
3531 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3532 std::fmt::Display::fmt(self.syntax(), f)
3533 }
3534}
3498impl std::fmt::Display for Path { 3535impl std::fmt::Display for Path {
3499 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3536 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3500 std::fmt::Display::fmt(self.syntax(), f) 3537 std::fmt::Display::fmt(self.syntax(), f)
@@ -3615,6 +3652,11 @@ impl std::fmt::Display for MacroRules {
3615 std::fmt::Display::fmt(self.syntax(), f) 3652 std::fmt::Display::fmt(self.syntax(), f)
3616 } 3653 }
3617} 3654}
3655impl std::fmt::Display for MacroDef {
3656 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3657 std::fmt::Display::fmt(self.syntax(), f)
3658 }
3659}
3618impl std::fmt::Display for Module { 3660impl std::fmt::Display for Module {
3619 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3661 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3620 std::fmt::Display::fmt(self.syntax(), f) 3662 std::fmt::Display::fmt(self.syntax(), f)
diff --git a/crates/syntax/src/ast/node_ext.rs b/crates/syntax/src/ast/node_ext.rs
index c59a29eab..c45cb514a 100644
--- a/crates/syntax/src/ast/node_ext.rs
+++ b/crates/syntax/src/ast/node_ext.rs
@@ -3,6 +3,7 @@
3 3
4use std::fmt; 4use std::fmt;
5 5
6use ast::AttrsOwner;
6use itertools::Itertools; 7use itertools::Itertools;
7use parser::SyntaxKind; 8use parser::SyntaxKind;
8 9
@@ -11,6 +12,12 @@ use crate::{
11 SmolStr, SyntaxElement, SyntaxToken, T, 12 SmolStr, SyntaxElement, SyntaxToken, T,
12}; 13};
13 14
15impl ast::Lifetime {
16 pub fn text(&self) -> &SmolStr {
17 text_of_first_token(self.syntax())
18 }
19}
20
14impl ast::Name { 21impl ast::Name {
15 pub fn text(&self) -> &SmolStr { 22 pub fn text(&self) -> &SmolStr {
16 text_of_first_token(self.syntax()) 23 text_of_first_token(self.syntax())
@@ -31,6 +38,57 @@ fn text_of_first_token(node: &SyntaxNode) -> &SmolStr {
31 node.green().children().next().and_then(|it| it.into_token()).unwrap().text() 38 node.green().children().next().and_then(|it| it.into_token()).unwrap().text()
32} 39}
33 40
41pub enum Macro {
42 MacroRules(ast::MacroRules),
43 MacroDef(ast::MacroDef),
44}
45
46impl From<ast::MacroRules> for Macro {
47 fn from(it: ast::MacroRules) -> Self {
48 Macro::MacroRules(it)
49 }
50}
51
52impl From<ast::MacroDef> for Macro {
53 fn from(it: ast::MacroDef) -> Self {
54 Macro::MacroDef(it)
55 }
56}
57
58impl AstNode for Macro {
59 fn can_cast(kind: SyntaxKind) -> bool {
60 match kind {
61 SyntaxKind::MACRO_RULES | SyntaxKind::MACRO_DEF => true,
62 _ => false,
63 }
64 }
65 fn cast(syntax: SyntaxNode) -> Option<Self> {
66 let res = match syntax.kind() {
67 SyntaxKind::MACRO_RULES => Macro::MacroRules(ast::MacroRules { syntax }),
68 SyntaxKind::MACRO_DEF => Macro::MacroDef(ast::MacroDef { syntax }),
69 _ => return None,
70 };
71 Some(res)
72 }
73 fn syntax(&self) -> &SyntaxNode {
74 match self {
75 Macro::MacroRules(it) => it.syntax(),
76 Macro::MacroDef(it) => it.syntax(),
77 }
78 }
79}
80
81impl NameOwner for Macro {
82 fn name(&self) -> Option<ast::Name> {
83 match self {
84 Macro::MacroRules(mac) => mac.name(),
85 Macro::MacroDef(mac) => mac.name(),
86 }
87 }
88}
89
90impl AttrsOwner for Macro {}
91
34#[derive(Debug, Clone, PartialEq, Eq)] 92#[derive(Debug, Clone, PartialEq, Eq)]
35pub enum AttrKind { 93pub enum AttrKind {
36 Inner, 94 Inner,
@@ -341,7 +399,7 @@ pub enum TypeBoundKind {
341 /// for<'a> ... 399 /// for<'a> ...
342 ForType(ast::ForType), 400 ForType(ast::ForType),
343 /// 'a 401 /// 'a
344 Lifetime(SyntaxToken), 402 Lifetime(ast::Lifetime),
345} 403}
346 404
347impl ast::TypeBound { 405impl ast::TypeBound {
@@ -350,7 +408,7 @@ impl ast::TypeBound {
350 TypeBoundKind::PathType(path_type) 408 TypeBoundKind::PathType(path_type)
351 } else if let Some(for_type) = support::children(self.syntax()).next() { 409 } else if let Some(for_type) = support::children(self.syntax()).next() {
352 TypeBoundKind::ForType(for_type) 410 TypeBoundKind::ForType(for_type)
353 } else if let Some(lifetime) = self.lifetime_token() { 411 } else if let Some(lifetime) = self.lifetime() {
354 TypeBoundKind::Lifetime(lifetime) 412 TypeBoundKind::Lifetime(lifetime)
355 } else { 413 } else {
356 unreachable!() 414 unreachable!()
@@ -388,7 +446,7 @@ impl ast::LifetimeParam {
388 .children_with_tokens() 446 .children_with_tokens()
389 .filter_map(|it| it.into_token()) 447 .filter_map(|it| it.into_token())
390 .skip_while(|x| x.kind() != T![:]) 448 .skip_while(|x| x.kind() != T![:])
391 .filter(|it| it.kind() == T![lifetime]) 449 .filter(|it| it.kind() == T![lifetime_ident])
392 } 450 }
393} 451}
394 452
@@ -462,4 +520,6 @@ impl ast::DocCommentsOwner for ast::Const {}
462impl ast::DocCommentsOwner for ast::TypeAlias {} 520impl ast::DocCommentsOwner for ast::TypeAlias {}
463impl ast::DocCommentsOwner for ast::Impl {} 521impl ast::DocCommentsOwner for ast::Impl {}
464impl ast::DocCommentsOwner for ast::MacroRules {} 522impl ast::DocCommentsOwner for ast::MacroRules {}
523impl ast::DocCommentsOwner for ast::MacroDef {}
524impl ast::DocCommentsOwner for ast::Macro {}
465impl ast::DocCommentsOwner for ast::Use {} 525impl ast::DocCommentsOwner for ast::Use {}
diff --git a/crates/syntax/src/display.rs b/crates/syntax/src/display.rs
index d33bde30c..391647fc6 100644
--- a/crates/syntax/src/display.rs
+++ b/crates/syntax/src/display.rs
@@ -76,8 +76,20 @@ pub fn type_label(node: &ast::TypeAlias) -> String {
76 label.trim().to_owned() 76 label.trim().to_owned()
77} 77}
78 78
79pub fn macro_label(node: &ast::MacroRules) -> String { 79pub fn macro_label(node: &ast::Macro) -> String {
80 let name = node.name().map(|name| name.syntax().text().to_string()).unwrap_or_default(); 80 let name = node.name().map(|name| name.syntax().text().to_string()).unwrap_or_default();
81 let vis = if node.has_atom_attr("macro_export") { "#[macro_export]\n" } else { "" }; 81 match node {
82 format!("{}macro_rules! {}", vis, name) 82 ast::Macro::MacroRules(node) => {
83 let vis = if node.has_atom_attr("macro_export") { "#[macro_export]\n" } else { "" };
84 format!("{}macro_rules! {}", vis, name)
85 }
86 ast::Macro::MacroDef(node) => {
87 let mut s = String::new();
88 if let Some(vis) = node.visibility() {
89 format_to!(s, "{} ", vis);
90 }
91 format_to!(s, "macro {}", name);
92 s
93 }
94 }
83} 95}
diff --git a/crates/syntax/src/parsing/lexer.rs b/crates/syntax/src/parsing/lexer.rs
index 8afd7e53b..0cbba73c5 100644
--- a/crates/syntax/src/parsing/lexer.rs
+++ b/crates/syntax/src/parsing/lexer.rs
@@ -146,9 +146,9 @@ fn rustc_token_kind_to_syntax_kind(
146 rustc_lexer::TokenKind::RawIdent => IDENT, 146 rustc_lexer::TokenKind::RawIdent => IDENT,
147 rustc_lexer::TokenKind::Literal { kind, .. } => return match_literal_kind(&kind), 147 rustc_lexer::TokenKind::Literal { kind, .. } => return match_literal_kind(&kind),
148 148
149 rustc_lexer::TokenKind::Lifetime { starts_with_number: false } => LIFETIME, 149 rustc_lexer::TokenKind::Lifetime { starts_with_number: false } => LIFETIME_IDENT,
150 rustc_lexer::TokenKind::Lifetime { starts_with_number: true } => { 150 rustc_lexer::TokenKind::Lifetime { starts_with_number: true } => {
151 return (LIFETIME, Some("Lifetime name cannot start with a number")) 151 return (LIFETIME_IDENT, Some("Lifetime name cannot start with a number"))
152 } 152 }
153 153
154 rustc_lexer::TokenKind::Semi => T![;], 154 rustc_lexer::TokenKind::Semi => T![;],