aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/ast/extensions.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax/src/ast/extensions.rs')
-rw-r--r--crates/ra_syntax/src/ast/extensions.rs30
1 files changed, 15 insertions, 15 deletions
diff --git a/crates/ra_syntax/src/ast/extensions.rs b/crates/ra_syntax/src/ast/extensions.rs
index 87592bfd8..342581faf 100644
--- a/crates/ra_syntax/src/ast/extensions.rs
+++ b/crates/ra_syntax/src/ast/extensions.rs
@@ -159,27 +159,27 @@ impl ast::ImplBlock {
159} 159}
160 160
161#[derive(Debug, Clone, PartialEq, Eq)] 161#[derive(Debug, Clone, PartialEq, Eq)]
162pub enum StructFlavor<'a> { 162pub enum StructKind<'a> {
163 Tuple(&'a ast::PosFieldDefList), 163 Tuple(&'a ast::PosFieldDefList),
164 Named(&'a ast::NamedFieldDefList), 164 Named(&'a ast::NamedFieldDefList),
165 Unit, 165 Unit,
166} 166}
167 167
168impl StructFlavor<'_> { 168impl StructKind<'_> {
169 fn from_node<N: AstNode>(node: &N) -> StructFlavor { 169 fn from_node<N: AstNode>(node: &N) -> StructKind {
170 if let Some(nfdl) = child_opt::<_, ast::NamedFieldDefList>(node) { 170 if let Some(nfdl) = child_opt::<_, ast::NamedFieldDefList>(node) {
171 StructFlavor::Named(nfdl) 171 StructKind::Named(nfdl)
172 } else if let Some(pfl) = child_opt::<_, ast::PosFieldDefList>(node) { 172 } else if let Some(pfl) = child_opt::<_, ast::PosFieldDefList>(node) {
173 StructFlavor::Tuple(pfl) 173 StructKind::Tuple(pfl)
174 } else { 174 } else {
175 StructFlavor::Unit 175 StructKind::Unit
176 } 176 }
177 } 177 }
178} 178}
179 179
180impl ast::StructDef { 180impl ast::StructDef {
181 pub fn flavor(&self) -> StructFlavor { 181 pub fn kind(&self) -> StructKind {
182 StructFlavor::from_node(self) 182 StructKind::from_node(self)
183 } 183 }
184} 184}
185 185
@@ -191,8 +191,8 @@ impl ast::EnumVariant {
191 .and_then(ast::EnumDef::cast) 191 .and_then(ast::EnumDef::cast)
192 .expect("EnumVariants are always nested in Enums") 192 .expect("EnumVariants are always nested in Enums")
193 } 193 }
194 pub fn flavor(&self) -> StructFlavor { 194 pub fn kind(&self) -> StructKind {
195 StructFlavor::from_node(self) 195 StructKind::from_node(self)
196 } 196 }
197} 197}
198 198
@@ -243,7 +243,7 @@ impl ast::ReferenceType {
243} 243}
244 244
245#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] 245#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
246pub enum SelfParamFlavor { 246pub enum SelfParamKind {
247 /// self 247 /// self
248 Owned, 248 Owned,
249 /// &self 249 /// &self
@@ -261,7 +261,7 @@ impl ast::SelfParam {
261 .expect("invalid tree: self param must have self") 261 .expect("invalid tree: self param must have self")
262 } 262 }
263 263
264 pub fn flavor(&self) -> SelfParamFlavor { 264 pub fn kind(&self) -> SelfParamKind {
265 let borrowed = self.syntax().children_with_tokens().any(|n| n.kind() == AMP); 265 let borrowed = self.syntax().children_with_tokens().any(|n| n.kind() == AMP);
266 if borrowed { 266 if borrowed {
267 // check for a `mut` coming after the & -- `mut &self` != `&mut self` 267 // check for a `mut` coming after the & -- `mut &self` != `&mut self`
@@ -271,12 +271,12 @@ impl ast::SelfParam {
271 .skip_while(|n| n.kind() != AMP) 271 .skip_while(|n| n.kind() != AMP)
272 .any(|n| n.kind() == MUT_KW) 272 .any(|n| n.kind() == MUT_KW)
273 { 273 {
274 SelfParamFlavor::MutRef 274 SelfParamKind::MutRef
275 } else { 275 } else {
276 SelfParamFlavor::Ref 276 SelfParamKind::Ref
277 } 277 }
278 } else { 278 } else {
279 SelfParamFlavor::Owned 279 SelfParamKind::Owned
280 } 280 }
281 } 281 }
282} 282}