aboutsummaryrefslogtreecommitdiff
path: root/crates/syntax/src/ast
diff options
context:
space:
mode:
Diffstat (limited to 'crates/syntax/src/ast')
-rw-r--r--crates/syntax/src/ast/generated/nodes.rs40
-rw-r--r--crates/syntax/src/ast/node_ext.rs33
2 files changed, 56 insertions, 17 deletions
diff --git a/crates/syntax/src/ast/generated/nodes.rs b/crates/syntax/src/ast/generated/nodes.rs
index 1d722db3c..5baa54a3f 100644
--- a/crates/syntax/src/ast/generated/nodes.rs
+++ b/crates/syntax/src/ast/generated/nodes.rs
@@ -11,6 +11,7 @@ pub struct Name {
11} 11}
12impl Name { 12impl Name {
13 pub fn ident_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![ident]) } 13 pub fn ident_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![ident]) }
14 pub fn self_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![self]) }
14} 15}
15#[derive(Debug, Clone, PartialEq, Eq, Hash)] 16#[derive(Debug, Clone, PartialEq, Eq, Hash)]
16pub struct NameRef { 17pub struct NameRef {
@@ -238,7 +239,6 @@ impl ExternCrate {
238 pub fn extern_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![extern]) } 239 pub fn extern_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![extern]) }
239 pub fn crate_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![crate]) } 240 pub fn crate_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![crate]) }
240 pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) } 241 pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) }
241 pub fn self_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![self]) }
242 pub fn rename(&self) -> Option<Rename> { support::child(&self.syntax) } 242 pub fn rename(&self) -> Option<Rename> { support::child(&self.syntax) }
243 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } 243 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
244} 244}
@@ -406,9 +406,6 @@ pub struct Visibility {
406impl Visibility { 406impl Visibility {
407 pub fn pub_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![pub]) } 407 pub fn pub_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![pub]) }
408 pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) } 408 pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) }
409 pub fn super_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![super]) }
410 pub fn self_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![self]) }
411 pub fn crate_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![crate]) }
412 pub fn in_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![in]) } 409 pub fn in_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![in]) }
413 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } 410 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) }
414 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } 411 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
@@ -492,11 +489,11 @@ pub struct SelfParam {
492 pub(crate) syntax: SyntaxNode, 489 pub(crate) syntax: SyntaxNode,
493} 490}
494impl ast::AttrsOwner for SelfParam {} 491impl ast::AttrsOwner for SelfParam {}
492impl ast::NameOwner for SelfParam {}
495impl SelfParam { 493impl SelfParam {
496 pub fn amp_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![&]) } 494 pub fn amp_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![&]) }
497 pub fn lifetime(&self) -> Option<Lifetime> { support::child(&self.syntax) } 495 pub fn lifetime(&self) -> Option<Lifetime> { support::child(&self.syntax) }
498 pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) } 496 pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) }
499 pub fn self_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![self]) }
500 pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) } 497 pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) }
501 pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) } 498 pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
502} 499}
@@ -1075,6 +1072,13 @@ impl InferType {
1075 pub fn underscore_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![_]) } 1072 pub fn underscore_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![_]) }
1076} 1073}
1077#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1074#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1075pub struct MacroType {
1076 pub(crate) syntax: SyntaxNode,
1077}
1078impl MacroType {
1079 pub fn macro_call(&self) -> Option<MacroCall> { support::child(&self.syntax) }
1080}
1081#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1078pub struct NeverType { 1082pub struct NeverType {
1079 pub(crate) syntax: SyntaxNode, 1083 pub(crate) syntax: SyntaxNode,
1080} 1084}
@@ -1303,6 +1307,7 @@ pub enum Type {
1303 ForType(ForType), 1307 ForType(ForType),
1304 ImplTraitType(ImplTraitType), 1308 ImplTraitType(ImplTraitType),
1305 InferType(InferType), 1309 InferType(InferType),
1310 MacroType(MacroType),
1306 NeverType(NeverType), 1311 NeverType(NeverType),
1307 ParenType(ParenType), 1312 ParenType(ParenType),
1308 PathType(PathType), 1313 PathType(PathType),
@@ -2561,6 +2566,17 @@ impl AstNode for InferType {
2561 } 2566 }
2562 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2567 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2563} 2568}
2569impl AstNode for MacroType {
2570 fn can_cast(kind: SyntaxKind) -> bool { kind == MACRO_TYPE }
2571 fn cast(syntax: SyntaxNode) -> Option<Self> {
2572 if Self::can_cast(syntax.kind()) {
2573 Some(Self { syntax })
2574 } else {
2575 None
2576 }
2577 }
2578 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2579}
2564impl AstNode for NeverType { 2580impl AstNode for NeverType {
2565 fn can_cast(kind: SyntaxKind) -> bool { kind == NEVER_TYPE } 2581 fn can_cast(kind: SyntaxKind) -> bool { kind == NEVER_TYPE }
2566 fn cast(syntax: SyntaxNode) -> Option<Self> { 2582 fn cast(syntax: SyntaxNode) -> Option<Self> {
@@ -2892,6 +2908,9 @@ impl From<ImplTraitType> for Type {
2892impl From<InferType> for Type { 2908impl From<InferType> for Type {
2893 fn from(node: InferType) -> Type { Type::InferType(node) } 2909 fn from(node: InferType) -> Type { Type::InferType(node) }
2894} 2910}
2911impl From<MacroType> for Type {
2912 fn from(node: MacroType) -> Type { Type::MacroType(node) }
2913}
2895impl From<NeverType> for Type { 2914impl From<NeverType> for Type {
2896 fn from(node: NeverType) -> Type { Type::NeverType(node) } 2915 fn from(node: NeverType) -> Type { Type::NeverType(node) }
2897} 2916}
@@ -2917,8 +2936,8 @@ impl AstNode for Type {
2917 fn can_cast(kind: SyntaxKind) -> bool { 2936 fn can_cast(kind: SyntaxKind) -> bool {
2918 match kind { 2937 match kind {
2919 ARRAY_TYPE | DYN_TRAIT_TYPE | FN_PTR_TYPE | FOR_TYPE | IMPL_TRAIT_TYPE | INFER_TYPE 2938 ARRAY_TYPE | DYN_TRAIT_TYPE | FN_PTR_TYPE | FOR_TYPE | IMPL_TRAIT_TYPE | INFER_TYPE
2920 | NEVER_TYPE | PAREN_TYPE | PATH_TYPE | PTR_TYPE | REF_TYPE | SLICE_TYPE 2939 | MACRO_TYPE | NEVER_TYPE | PAREN_TYPE | PATH_TYPE | PTR_TYPE | REF_TYPE
2921 | TUPLE_TYPE => true, 2940 | SLICE_TYPE | TUPLE_TYPE => true,
2922 _ => false, 2941 _ => false,
2923 } 2942 }
2924 } 2943 }
@@ -2930,6 +2949,7 @@ impl AstNode for Type {
2930 FOR_TYPE => Type::ForType(ForType { syntax }), 2949 FOR_TYPE => Type::ForType(ForType { syntax }),
2931 IMPL_TRAIT_TYPE => Type::ImplTraitType(ImplTraitType { syntax }), 2950 IMPL_TRAIT_TYPE => Type::ImplTraitType(ImplTraitType { syntax }),
2932 INFER_TYPE => Type::InferType(InferType { syntax }), 2951 INFER_TYPE => Type::InferType(InferType { syntax }),
2952 MACRO_TYPE => Type::MacroType(MacroType { syntax }),
2933 NEVER_TYPE => Type::NeverType(NeverType { syntax }), 2953 NEVER_TYPE => Type::NeverType(NeverType { syntax }),
2934 PAREN_TYPE => Type::ParenType(ParenType { syntax }), 2954 PAREN_TYPE => Type::ParenType(ParenType { syntax }),
2935 PATH_TYPE => Type::PathType(PathType { syntax }), 2955 PATH_TYPE => Type::PathType(PathType { syntax }),
@@ -2949,6 +2969,7 @@ impl AstNode for Type {
2949 Type::ForType(it) => &it.syntax, 2969 Type::ForType(it) => &it.syntax,
2950 Type::ImplTraitType(it) => &it.syntax, 2970 Type::ImplTraitType(it) => &it.syntax,
2951 Type::InferType(it) => &it.syntax, 2971 Type::InferType(it) => &it.syntax,
2972 Type::MacroType(it) => &it.syntax,
2952 Type::NeverType(it) => &it.syntax, 2973 Type::NeverType(it) => &it.syntax,
2953 Type::ParenType(it) => &it.syntax, 2974 Type::ParenType(it) => &it.syntax,
2954 Type::PathType(it) => &it.syntax, 2975 Type::PathType(it) => &it.syntax,
@@ -4085,6 +4106,11 @@ impl std::fmt::Display for InferType {
4085 std::fmt::Display::fmt(self.syntax(), f) 4106 std::fmt::Display::fmt(self.syntax(), f)
4086 } 4107 }
4087} 4108}
4109impl std::fmt::Display for MacroType {
4110 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4111 std::fmt::Display::fmt(self.syntax(), f)
4112 }
4113}
4088impl std::fmt::Display for NeverType { 4114impl std::fmt::Display for NeverType {
4089 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 4115 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4090 std::fmt::Display::fmt(self.syntax(), f) 4116 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 b8ce71d27..738c92a5b 100644
--- a/crates/syntax/src/ast/node_ext.rs
+++ b/crates/syntax/src/ast/node_ext.rs
@@ -198,6 +198,13 @@ impl ast::Path {
198 pub fn parent_path(&self) -> Option<ast::Path> { 198 pub fn parent_path(&self) -> Option<ast::Path> {
199 self.syntax().parent().and_then(ast::Path::cast) 199 self.syntax().parent().and_then(ast::Path::cast)
200 } 200 }
201
202 pub fn as_single_segment(&self) -> Option<ast::PathSegment> {
203 match self.qualifier() {
204 Some(_) => None,
205 None => self.segment(),
206 }
207 }
201} 208}
202 209
203impl ast::UseTreeList { 210impl ast::UseTreeList {
@@ -448,16 +455,22 @@ pub enum VisibilityKind {
448 455
449impl ast::Visibility { 456impl ast::Visibility {
450 pub fn kind(&self) -> VisibilityKind { 457 pub fn kind(&self) -> VisibilityKind {
451 if let Some(path) = support::children(self.syntax()).next() { 458 match self.path() {
452 VisibilityKind::In(path) 459 Some(path) => {
453 } else if self.crate_token().is_some() { 460 if let Some(segment) =
454 VisibilityKind::PubCrate 461 path.as_single_segment().filter(|it| it.coloncolon_token().is_none())
455 } else if self.super_token().is_some() { 462 {
456 VisibilityKind::PubSuper 463 if segment.crate_token().is_some() {
457 } else if self.self_token().is_some() { 464 return VisibilityKind::PubCrate;
458 VisibilityKind::PubSelf 465 } else if segment.super_token().is_some() {
459 } else { 466 return VisibilityKind::PubSuper;
460 VisibilityKind::Pub 467 } else if segment.self_token().is_some() {
468 return VisibilityKind::PubSelf;
469 }
470 }
471 VisibilityKind::In(path)
472 }
473 None => VisibilityKind::Pub,
461 } 474 }
462 } 475 }
463} 476}