diff options
author | Benjamin Coenen <[email protected]> | 2020-04-09 17:37:34 +0100 |
---|---|---|
committer | Benjamin Coenen <[email protected]> | 2020-04-09 18:12:50 +0100 |
commit | c1317d692321ba5ba8f138067ebefbb9559d098d (patch) | |
tree | e29a44577e4d2cf55b6f53e3428abea43bbd33d7 /crates/ra_syntax/src/ast.rs | |
parent | fc70cf9458c5234decafdd52b9aced790ac43d7a (diff) | |
parent | 30f0ad159a0f260f54356385de63c171722adb72 (diff) |
feat: add support for feature attributes in struct literal
Signed-off-by: Benjamin Coenen <[email protected]>
Diffstat (limited to 'crates/ra_syntax/src/ast.rs')
-rw-r--r-- | crates/ra_syntax/src/ast.rs | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs index ab0f44dd2..a42eec91a 100644 --- a/crates/ra_syntax/src/ast.rs +++ b/crates/ra_syntax/src/ast.rs | |||
@@ -21,7 +21,7 @@ pub use self::{ | |||
21 | AttrKind, FieldKind, PathSegmentKind, SelfParamKind, SlicePatComponents, StructKind, | 21 | AttrKind, FieldKind, PathSegmentKind, SelfParamKind, SlicePatComponents, StructKind, |
22 | TypeBoundKind, VisibilityKind, | 22 | TypeBoundKind, VisibilityKind, |
23 | }, | 23 | }, |
24 | generated::*, | 24 | generated::{nodes::*, tokens::*}, |
25 | tokens::*, | 25 | tokens::*, |
26 | traits::*, | 26 | traits::*, |
27 | }; | 27 | }; |
@@ -64,6 +64,22 @@ pub trait AstToken { | |||
64 | } | 64 | } |
65 | } | 65 | } |
66 | 66 | ||
67 | mod support { | ||
68 | use super::{AstChildren, AstNode, AstToken, SyntaxNode}; | ||
69 | |||
70 | pub(super) fn child<N: AstNode>(parent: &SyntaxNode) -> Option<N> { | ||
71 | parent.children().find_map(N::cast) | ||
72 | } | ||
73 | |||
74 | pub(super) fn children<N: AstNode>(parent: &SyntaxNode) -> AstChildren<N> { | ||
75 | AstChildren::new(parent) | ||
76 | } | ||
77 | |||
78 | pub(super) fn token<T: AstToken>(parent: &SyntaxNode) -> Option<T> { | ||
79 | parent.children_with_tokens().filter_map(|it| it.into_token()).find_map(T::cast) | ||
80 | } | ||
81 | } | ||
82 | |||
67 | /// An iterator over `SyntaxNode` children of a particular AST type. | 83 | /// An iterator over `SyntaxNode` children of a particular AST type. |
68 | #[derive(Debug, Clone)] | 84 | #[derive(Debug, Clone)] |
69 | pub struct AstChildren<N> { | 85 | pub struct AstChildren<N> { |
@@ -271,7 +287,7 @@ where | |||
271 | let pred = predicates.next().unwrap(); | 287 | let pred = predicates.next().unwrap(); |
272 | let mut bounds = pred.type_bound_list().unwrap().bounds(); | 288 | let mut bounds = pred.type_bound_list().unwrap().bounds(); |
273 | 289 | ||
274 | assert_eq!("'a", pred.lifetime_token().unwrap().text()); | 290 | assert_eq!("'a", pred.lifetime().unwrap().text()); |
275 | 291 | ||
276 | assert_bound("'b", bounds.next()); | 292 | assert_bound("'b", bounds.next()); |
277 | assert_bound("'c", bounds.next()); | 293 | assert_bound("'c", bounds.next()); |