aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/ast/traits.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax/src/ast/traits.rs')
-rw-r--r--crates/ra_syntax/src/ast/traits.rs50
1 files changed, 25 insertions, 25 deletions
diff --git a/crates/ra_syntax/src/ast/traits.rs b/crates/ra_syntax/src/ast/traits.rs
index 29cb53e35..ecbd2d427 100644
--- a/crates/ra_syntax/src/ast/traits.rs
+++ b/crates/ra_syntax/src/ast/traits.rs
@@ -10,37 +10,37 @@ use crate::{
10}; 10};
11 11
12pub trait TypeAscriptionOwner: AstNode { 12pub trait TypeAscriptionOwner: AstNode {
13 fn ascribed_type(&self) -> Option<&ast::TypeRef> { 13 fn ascribed_type(&self) -> Option<ast::TypeRef> {
14 child_opt(self) 14 child_opt(self)
15 } 15 }
16} 16}
17 17
18pub trait NameOwner: AstNode { 18pub trait NameOwner: AstNode {
19 fn name(&self) -> Option<&ast::Name> { 19 fn name(&self) -> Option<ast::Name> {
20 child_opt(self) 20 child_opt(self)
21 } 21 }
22} 22}
23 23
24pub trait VisibilityOwner: AstNode { 24pub trait VisibilityOwner: AstNode {
25 fn visibility(&self) -> Option<&ast::Visibility> { 25 fn visibility(&self) -> Option<ast::Visibility> {
26 child_opt(self) 26 child_opt(self)
27 } 27 }
28} 28}
29 29
30pub trait LoopBodyOwner: AstNode { 30pub trait LoopBodyOwner: AstNode {
31 fn loop_body(&self) -> Option<&ast::Block> { 31 fn loop_body(&self) -> Option<ast::Block> {
32 child_opt(self) 32 child_opt(self)
33 } 33 }
34} 34}
35 35
36pub trait TryBlockBodyOwner: AstNode { 36pub trait TryBlockBodyOwner: AstNode {
37 fn try_body(&self) -> Option<&ast::Block> { 37 fn try_body(&self) -> Option<ast::Block> {
38 child_opt(self) 38 child_opt(self)
39 } 39 }
40} 40}
41 41
42pub trait ArgListOwner: AstNode { 42pub trait ArgListOwner: AstNode {
43 fn arg_list(&self) -> Option<&ast::ArgList> { 43 fn arg_list(&self) -> Option<ast::ArgList> {
44 child_opt(self) 44 child_opt(self)
45 } 45 }
46} 46}
@@ -51,10 +51,10 @@ pub trait FnDefOwner: AstNode {
51 } 51 }
52} 52}
53 53
54#[derive(Debug, Clone, Copy, PartialEq, Eq)] 54#[derive(Debug, Clone, PartialEq, Eq)]
55pub enum ItemOrMacro<'a> { 55pub enum ItemOrMacro {
56 Item(&'a ast::ModuleItem), 56 Item(ast::ModuleItem),
57 Macro(&'a ast::MacroCall), 57 Macro(ast::MacroCall),
58} 58}
59 59
60pub trait ModuleItemOwner: AstNode { 60pub trait ModuleItemOwner: AstNode {
@@ -67,14 +67,14 @@ pub trait ModuleItemOwner: AstNode {
67} 67}
68 68
69#[derive(Debug)] 69#[derive(Debug)]
70pub struct ItemOrMacroIter<'a>(SyntaxNodeChildren<'a>); 70pub struct ItemOrMacroIter(SyntaxNodeChildren);
71 71
72impl<'a> Iterator for ItemOrMacroIter<'a> { 72impl Iterator for ItemOrMacroIter {
73 type Item = ItemOrMacro<'a>; 73 type Item = ItemOrMacro;
74 fn next(&mut self) -> Option<ItemOrMacro<'a>> { 74 fn next(&mut self) -> Option<ItemOrMacro> {
75 loop { 75 loop {
76 let n = self.0.next()?; 76 let n = self.0.next()?;
77 if let Some(item) = ast::ModuleItem::cast(n) { 77 if let Some(item) = ast::ModuleItem::cast(n.clone()) {
78 return Some(ItemOrMacro::Item(item)); 78 return Some(ItemOrMacro::Item(item));
79 } 79 }
80 if let Some(call) = ast::MacroCall::cast(n) { 80 if let Some(call) = ast::MacroCall::cast(n) {
@@ -85,17 +85,17 @@ impl<'a> Iterator for ItemOrMacroIter<'a> {
85} 85}
86 86
87pub trait TypeParamsOwner: AstNode { 87pub trait TypeParamsOwner: AstNode {
88 fn type_param_list(&self) -> Option<&ast::TypeParamList> { 88 fn type_param_list(&self) -> Option<ast::TypeParamList> {
89 child_opt(self) 89 child_opt(self)
90 } 90 }
91 91
92 fn where_clause(&self) -> Option<&ast::WhereClause> { 92 fn where_clause(&self) -> Option<ast::WhereClause> {
93 child_opt(self) 93 child_opt(self)
94 } 94 }
95} 95}
96 96
97pub trait TypeBoundsOwner: AstNode { 97pub trait TypeBoundsOwner: AstNode {
98 fn type_bound_list(&self) -> Option<&ast::TypeBoundList> { 98 fn type_bound_list(&self) -> Option<ast::TypeBoundList> {
99 child_opt(self) 99 child_opt(self)
100 } 100 }
101} 101}
@@ -148,19 +148,19 @@ pub trait DocCommentsOwner: AstNode {
148 } 148 }
149} 149}
150 150
151pub struct CommentIter<'a> { 151pub struct CommentIter {
152 iter: SyntaxElementChildren<'a>, 152 iter: SyntaxElementChildren,
153} 153}
154 154
155impl<'a> Iterator for CommentIter<'a> { 155impl Iterator for CommentIter {
156 type Item = ast::Comment<'a>; 156 type Item = ast::Comment;
157 fn next(&mut self) -> Option<ast::Comment<'a>> { 157 fn next(&mut self) -> Option<ast::Comment> {
158 self.iter.by_ref().find_map(|el| el.as_token().and_then(ast::Comment::cast)) 158 self.iter.by_ref().find_map(|el| el.as_token().cloned().and_then(ast::Comment::cast))
159 } 159 }
160} 160}
161 161
162pub trait DefaultTypeParamOwner: AstNode { 162pub trait DefaultTypeParamOwner: AstNode {
163 fn default_type(&self) -> Option<&ast::PathType> { 163 fn default_type(&self) -> Option<ast::PathType> {
164 child_opt(self) 164 child_opt(self)
165 } 165 }
166} 166}