diff options
-rw-r--r-- | crates/ra_assists/src/handlers/inline_local_variable.rs | 2 | ||||
-rw-r--r-- | crates/ra_assists/src/handlers/introduce_variable.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir_def/src/body/lower.rs | 7 | ||||
-rw-r--r-- | crates/ra_hir_def/src/data.rs | 6 | ||||
-rw-r--r-- | crates/ra_hir_def/src/generics.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres/raw.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir_def/src/type_ref.rs | 4 | ||||
-rw-r--r-- | crates/ra_ide/src/completion/completion_context.rs | 5 | ||||
-rw-r--r-- | crates/ra_ide/src/references.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide/src/typing.rs | 2 | ||||
-rw-r--r-- | crates/ra_syntax/src/ast/edit.rs | 4 | ||||
-rw-r--r-- | crates/ra_syntax/src/ast/extensions.rs | 104 | ||||
-rw-r--r-- | crates/ra_syntax/src/ast/generated/nodes.rs | 3 | ||||
-rw-r--r-- | xtask/src/ast_src.rs | 5 |
14 files changed, 36 insertions, 114 deletions
diff --git a/crates/ra_assists/src/handlers/inline_local_variable.rs b/crates/ra_assists/src/handlers/inline_local_variable.rs index 3bfcba8ff..b9eb09676 100644 --- a/crates/ra_assists/src/handlers/inline_local_variable.rs +++ b/crates/ra_assists/src/handlers/inline_local_variable.rs | |||
@@ -29,7 +29,7 @@ pub(crate) fn inline_local_variable(ctx: AssistCtx) -> Option<Assist> { | |||
29 | ast::Pat::BindPat(pat) => pat, | 29 | ast::Pat::BindPat(pat) => pat, |
30 | _ => return None, | 30 | _ => return None, |
31 | }; | 31 | }; |
32 | if bind_pat.is_mutable() { | 32 | if bind_pat.mut_kw_token().is_some() { |
33 | tested_by!(test_not_inline_mut_variable); | 33 | tested_by!(test_not_inline_mut_variable); |
34 | return None; | 34 | return None; |
35 | } | 35 | } |
diff --git a/crates/ra_assists/src/handlers/introduce_variable.rs b/crates/ra_assists/src/handlers/introduce_variable.rs index 8a02f1a32..ab6bdf6bb 100644 --- a/crates/ra_assists/src/handlers/introduce_variable.rs +++ b/crates/ra_assists/src/handlers/introduce_variable.rs | |||
@@ -61,7 +61,7 @@ pub(crate) fn introduce_variable(ctx: AssistCtx) -> Option<Assist> { | |||
61 | }; | 61 | }; |
62 | if is_full_stmt { | 62 | if is_full_stmt { |
63 | tested_by!(test_introduce_var_expr_stmt); | 63 | tested_by!(test_introduce_var_expr_stmt); |
64 | if !full_stmt.unwrap().has_semi() { | 64 | if full_stmt.unwrap().semi_token().is_none() { |
65 | buf.push_str(";"); | 65 | buf.push_str(";"); |
66 | } | 66 | } |
67 | edit.replace(expr.syntax().text_range(), buf); | 67 | edit.replace(expr.syntax().text_range(), buf); |
diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index b02de5d67..c4a5ec59c 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs | |||
@@ -572,7 +572,10 @@ impl ExprCollector<'_> { | |||
572 | let pattern = match &pat { | 572 | let pattern = match &pat { |
573 | ast::Pat::BindPat(bp) => { | 573 | ast::Pat::BindPat(bp) => { |
574 | let name = bp.name().map(|nr| nr.as_name()).unwrap_or_else(Name::missing); | 574 | let name = bp.name().map(|nr| nr.as_name()).unwrap_or_else(Name::missing); |
575 | let annotation = BindingAnnotation::new(bp.is_mutable(), bp.is_ref()); | 575 | let annotation = BindingAnnotation::new( |
576 | bp.mut_kw_token().is_some(), | ||
577 | bp.ref_kw_token().is_some(), | ||
578 | ); | ||
576 | let subpat = bp.pat().map(|subpat| self.collect_pat(subpat)); | 579 | let subpat = bp.pat().map(|subpat| self.collect_pat(subpat)); |
577 | if annotation == BindingAnnotation::Unannotated && subpat.is_none() { | 580 | if annotation == BindingAnnotation::Unannotated && subpat.is_none() { |
578 | // This could also be a single-segment path pattern. To | 581 | // This could also be a single-segment path pattern. To |
@@ -613,7 +616,7 @@ impl ExprCollector<'_> { | |||
613 | } | 616 | } |
614 | ast::Pat::RefPat(p) => { | 617 | ast::Pat::RefPat(p) => { |
615 | let pat = self.collect_pat_opt(p.pat()); | 618 | let pat = self.collect_pat_opt(p.pat()); |
616 | let mutability = Mutability::from_mutable(p.is_mut()); | 619 | let mutability = Mutability::from_mutable(p.mut_kw_token().is_some()); |
617 | Pat::Ref { pat, mutability } | 620 | Pat::Ref { pat, mutability } |
618 | } | 621 | } |
619 | ast::Pat::PathPat(p) => { | 622 | ast::Pat::PathPat(p) => { |
diff --git a/crates/ra_hir_def/src/data.rs b/crates/ra_hir_def/src/data.rs index 606ec48b0..689bb6c5c 100644 --- a/crates/ra_hir_def/src/data.rs +++ b/crates/ra_hir_def/src/data.rs | |||
@@ -75,7 +75,7 @@ impl FunctionData { | |||
75 | TypeRef::unit() | 75 | TypeRef::unit() |
76 | }; | 76 | }; |
77 | 77 | ||
78 | let ret_type = if src.value.is_async() { | 78 | let ret_type = if src.value.async_kw_token().is_some() { |
79 | let future_impl = desugar_future_path(ret_type); | 79 | let future_impl = desugar_future_path(ret_type); |
80 | let ty_bound = TypeBound::Path(future_impl); | 80 | let ty_bound = TypeBound::Path(future_impl); |
81 | TypeRef::ImplTrait(vec![ty_bound]) | 81 | TypeRef::ImplTrait(vec![ty_bound]) |
@@ -136,7 +136,7 @@ impl TraitData { | |||
136 | pub(crate) fn trait_data_query(db: &dyn DefDatabase, tr: TraitId) -> Arc<TraitData> { | 136 | pub(crate) fn trait_data_query(db: &dyn DefDatabase, tr: TraitId) -> Arc<TraitData> { |
137 | let src = tr.lookup(db).source(db); | 137 | let src = tr.lookup(db).source(db); |
138 | let name = src.value.name().map_or_else(Name::missing, |n| n.as_name()); | 138 | let name = src.value.name().map_or_else(Name::missing, |n| n.as_name()); |
139 | let auto = src.value.is_auto(); | 139 | let auto = src.value.auto_kw_token().is_some(); |
140 | let ast_id_map = db.ast_id_map(src.file_id); | 140 | let ast_id_map = db.ast_id_map(src.file_id); |
141 | 141 | ||
142 | let container = AssocContainerId::TraitId(tr); | 142 | let container = AssocContainerId::TraitId(tr); |
@@ -213,7 +213,7 @@ impl ImplData { | |||
213 | 213 | ||
214 | let target_trait = src.value.target_trait().map(TypeRef::from_ast); | 214 | let target_trait = src.value.target_trait().map(TypeRef::from_ast); |
215 | let target_type = TypeRef::from_ast_opt(src.value.target_type()); | 215 | let target_type = TypeRef::from_ast_opt(src.value.target_type()); |
216 | let is_negative = src.value.is_negative(); | 216 | let is_negative = src.value.excl_token().is_some(); |
217 | let module_id = impl_loc.container.module(db); | 217 | let module_id = impl_loc.container.module(db); |
218 | 218 | ||
219 | let mut items = Vec::new(); | 219 | let mut items = Vec::new(); |
diff --git a/crates/ra_hir_def/src/generics.rs b/crates/ra_hir_def/src/generics.rs index b687ce2b2..d850244c4 100644 --- a/crates/ra_hir_def/src/generics.rs +++ b/crates/ra_hir_def/src/generics.rs | |||
@@ -194,7 +194,7 @@ impl GenericParams { | |||
194 | } | 194 | } |
195 | 195 | ||
196 | fn add_where_predicate_from_bound(&mut self, bound: ast::TypeBound, type_ref: TypeRef) { | 196 | fn add_where_predicate_from_bound(&mut self, bound: ast::TypeBound, type_ref: TypeRef) { |
197 | if bound.has_question_mark() { | 197 | if bound.question_token().is_some() { |
198 | // FIXME: remove this bound | 198 | // FIXME: remove this bound |
199 | return; | 199 | return; |
200 | } | 200 | } |
diff --git a/crates/ra_hir_def/src/nameres/raw.rs b/crates/ra_hir_def/src/nameres/raw.rs index a9dff3a5d..e72ba52cf 100644 --- a/crates/ra_hir_def/src/nameres/raw.rs +++ b/crates/ra_hir_def/src/nameres/raw.rs | |||
@@ -287,7 +287,7 @@ impl RawItemsCollector { | |||
287 | let visibility = RawVisibility::from_ast_with_hygiene(module.visibility(), &self.hygiene); | 287 | let visibility = RawVisibility::from_ast_with_hygiene(module.visibility(), &self.hygiene); |
288 | 288 | ||
289 | let ast_id = self.source_ast_id_map.ast_id(&module); | 289 | let ast_id = self.source_ast_id_map.ast_id(&module); |
290 | if module.has_semi() { | 290 | if module.semi_token().is_some() { |
291 | let item = | 291 | let item = |
292 | self.raw_items.modules.alloc(ModuleData::Declaration { name, visibility, ast_id }); | 292 | self.raw_items.modules.alloc(ModuleData::Declaration { name, visibility, ast_id }); |
293 | self.push_item(current_module, attrs, RawItemKind::Module(item)); | 293 | self.push_item(current_module, attrs, RawItemKind::Module(item)); |
diff --git a/crates/ra_hir_def/src/type_ref.rs b/crates/ra_hir_def/src/type_ref.rs index 01cc392db..7a8338937 100644 --- a/crates/ra_hir_def/src/type_ref.rs +++ b/crates/ra_hir_def/src/type_ref.rs | |||
@@ -77,7 +77,7 @@ impl TypeRef { | |||
77 | } | 77 | } |
78 | ast::TypeRef::PointerType(inner) => { | 78 | ast::TypeRef::PointerType(inner) => { |
79 | let inner_ty = TypeRef::from_ast_opt(inner.type_ref()); | 79 | let inner_ty = TypeRef::from_ast_opt(inner.type_ref()); |
80 | let mutability = Mutability::from_mutable(inner.is_mut()); | 80 | let mutability = Mutability::from_mutable(inner.mut_kw_token().is_some()); |
81 | TypeRef::RawPtr(Box::new(inner_ty), mutability) | 81 | TypeRef::RawPtr(Box::new(inner_ty), mutability) |
82 | } | 82 | } |
83 | ast::TypeRef::ArrayType(inner) => { | 83 | ast::TypeRef::ArrayType(inner) => { |
@@ -88,7 +88,7 @@ impl TypeRef { | |||
88 | } | 88 | } |
89 | ast::TypeRef::ReferenceType(inner) => { | 89 | ast::TypeRef::ReferenceType(inner) => { |
90 | let inner_ty = TypeRef::from_ast_opt(inner.type_ref()); | 90 | let inner_ty = TypeRef::from_ast_opt(inner.type_ref()); |
91 | let mutability = Mutability::from_mutable(inner.is_mut()); | 91 | let mutability = Mutability::from_mutable(inner.mut_kw_token().is_some()); |
92 | TypeRef::Reference(Box::new(inner_ty), mutability) | 92 | TypeRef::Reference(Box::new(inner_ty), mutability) |
93 | } | 93 | } |
94 | ast::TypeRef::PlaceholderType(_inner) => TypeRef::Placeholder, | 94 | ast::TypeRef::PlaceholderType(_inner) => TypeRef::Placeholder, |
diff --git a/crates/ra_ide/src/completion/completion_context.rs b/crates/ra_ide/src/completion/completion_context.rs index f833d2a9a..0e34d85db 100644 --- a/crates/ra_ide/src/completion/completion_context.rs +++ b/crates/ra_ide/src/completion/completion_context.rs | |||
@@ -190,7 +190,10 @@ impl<'a> CompletionContext<'a> { | |||
190 | if let Some(name) = find_node_at_offset::<ast::Name>(&file_with_fake_ident, offset) { | 190 | if let Some(name) = find_node_at_offset::<ast::Name>(&file_with_fake_ident, offset) { |
191 | if let Some(bind_pat) = name.syntax().ancestors().find_map(ast::BindPat::cast) { | 191 | if let Some(bind_pat) = name.syntax().ancestors().find_map(ast::BindPat::cast) { |
192 | self.is_pat_binding_or_const = true; | 192 | self.is_pat_binding_or_const = true; |
193 | if bind_pat.has_at() || bind_pat.is_ref() || bind_pat.is_mutable() { | 193 | if bind_pat.at_token().is_some() |
194 | || bind_pat.ref_kw_token().is_some() | ||
195 | || bind_pat.mut_kw_token().is_some() | ||
196 | { | ||
194 | self.is_pat_binding_or_const = false; | 197 | self.is_pat_binding_or_const = false; |
195 | } | 198 | } |
196 | if bind_pat.syntax().parent().and_then(ast::RecordFieldPatList::cast).is_some() { | 199 | if bind_pat.syntax().parent().and_then(ast::RecordFieldPatList::cast).is_some() { |
diff --git a/crates/ra_ide/src/references.rs b/crates/ra_ide/src/references.rs index 746cc86ba..ad6fd50aa 100644 --- a/crates/ra_ide/src/references.rs +++ b/crates/ra_ide/src/references.rs | |||
@@ -152,7 +152,7 @@ fn decl_access(def: &Definition, syntax: &SyntaxNode, range: TextRange) -> Optio | |||
152 | if stmt.initializer().is_some() { | 152 | if stmt.initializer().is_some() { |
153 | let pat = stmt.pat()?; | 153 | let pat = stmt.pat()?; |
154 | if let ast::Pat::BindPat(it) = pat { | 154 | if let ast::Pat::BindPat(it) = pat { |
155 | if it.is_mutable() { | 155 | if it.mut_kw_token().is_some() { |
156 | return Some(ReferenceAccess::Write); | 156 | return Some(ReferenceAccess::Write); |
157 | } | 157 | } |
158 | } | 158 | } |
diff --git a/crates/ra_ide/src/typing.rs b/crates/ra_ide/src/typing.rs index cb2cd2479..71d2bcb04 100644 --- a/crates/ra_ide/src/typing.rs +++ b/crates/ra_ide/src/typing.rs | |||
@@ -63,7 +63,7 @@ fn on_char_typed_inner( | |||
63 | fn on_eq_typed(file: &SourceFile, offset: TextUnit) -> Option<SingleFileChange> { | 63 | fn on_eq_typed(file: &SourceFile, offset: TextUnit) -> Option<SingleFileChange> { |
64 | assert_eq!(file.syntax().text().char_at(offset), Some('=')); | 64 | assert_eq!(file.syntax().text().char_at(offset), Some('=')); |
65 | let let_stmt: ast::LetStmt = find_node_at_offset(file.syntax(), offset)?; | 65 | let let_stmt: ast::LetStmt = find_node_at_offset(file.syntax(), offset)?; |
66 | if let_stmt.has_semi() { | 66 | if let_stmt.semi_token().is_some() { |
67 | return None; | 67 | return None; |
68 | } | 68 | } |
69 | if let Some(expr) = let_stmt.initializer() { | 69 | if let Some(expr) = let_stmt.initializer() { |
diff --git a/crates/ra_syntax/src/ast/edit.rs b/crates/ra_syntax/src/ast/edit.rs index 62153f199..069c6ee82 100644 --- a/crates/ra_syntax/src/ast/edit.rs +++ b/crates/ra_syntax/src/ast/edit.rs | |||
@@ -33,9 +33,9 @@ impl ast::FnDef { | |||
33 | let mut to_insert: ArrayVec<[SyntaxElement; 2]> = ArrayVec::new(); | 33 | let mut to_insert: ArrayVec<[SyntaxElement; 2]> = ArrayVec::new(); |
34 | let old_body_or_semi: SyntaxElement = if let Some(old_body) = self.body() { | 34 | let old_body_or_semi: SyntaxElement = if let Some(old_body) = self.body() { |
35 | old_body.syntax().clone().into() | 35 | old_body.syntax().clone().into() |
36 | } else if let Some(semi) = self.semicolon_token() { | 36 | } else if let Some(semi) = self.semi_token() { |
37 | to_insert.push(make::tokens::single_space().into()); | 37 | to_insert.push(make::tokens::single_space().into()); |
38 | semi.into() | 38 | semi.syntax.clone().into() |
39 | } else { | 39 | } else { |
40 | to_insert.push(make::tokens::single_space().into()); | 40 | to_insert.push(make::tokens::single_space().into()); |
41 | to_insert.push(body.syntax().clone().into()); | 41 | to_insert.push(body.syntax().clone().into()); |
diff --git a/crates/ra_syntax/src/ast/extensions.rs b/crates/ra_syntax/src/ast/extensions.rs index ff3525c84..b50a89864 100644 --- a/crates/ra_syntax/src/ast/extensions.rs +++ b/crates/ra_syntax/src/ast/extensions.rs | |||
@@ -136,12 +136,6 @@ impl ast::Path { | |||
136 | } | 136 | } |
137 | } | 137 | } |
138 | 138 | ||
139 | impl ast::Module { | ||
140 | pub fn has_semi(&self) -> bool { | ||
141 | self.semi_token().is_some() | ||
142 | } | ||
143 | } | ||
144 | |||
145 | impl ast::UseTreeList { | 139 | impl ast::UseTreeList { |
146 | pub fn parent_use_tree(&self) -> ast::UseTree { | 140 | pub fn parent_use_tree(&self) -> ast::UseTree { |
147 | self.syntax() | 141 | self.syntax() |
@@ -172,10 +166,6 @@ impl ast::ImplDef { | |||
172 | let second = types.next(); | 166 | let second = types.next(); |
173 | (first, second) | 167 | (first, second) |
174 | } | 168 | } |
175 | |||
176 | pub fn is_negative(&self) -> bool { | ||
177 | self.excl_token().is_some() | ||
178 | } | ||
179 | } | 169 | } |
180 | 170 | ||
181 | #[derive(Debug, Clone, PartialEq, Eq)] | 171 | #[derive(Debug, Clone, PartialEq, Eq)] |
@@ -216,31 +206,6 @@ impl ast::EnumVariant { | |||
216 | } | 206 | } |
217 | } | 207 | } |
218 | 208 | ||
219 | impl ast::FnDef { | ||
220 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { | ||
221 | Some(self.semi_token()?.syntax().clone()) | ||
222 | } | ||
223 | |||
224 | pub fn is_async(&self) -> bool { | ||
225 | self.async_kw_token().is_some() | ||
226 | } | ||
227 | } | ||
228 | |||
229 | impl ast::LetStmt { | ||
230 | pub fn has_semi(&self) -> bool { | ||
231 | match self.syntax().last_child_or_token() { | ||
232 | None => false, | ||
233 | Some(node) => node.kind() == T![;], | ||
234 | } | ||
235 | } | ||
236 | } | ||
237 | |||
238 | impl ast::ExprStmt { | ||
239 | pub fn has_semi(&self) -> bool { | ||
240 | self.semi_token().is_some() | ||
241 | } | ||
242 | } | ||
243 | |||
244 | #[derive(Debug, Clone, PartialEq, Eq)] | 209 | #[derive(Debug, Clone, PartialEq, Eq)] |
245 | pub enum FieldKind { | 210 | pub enum FieldKind { |
246 | Name(ast::NameRef), | 211 | Name(ast::NameRef), |
@@ -269,25 +234,6 @@ impl ast::FieldExpr { | |||
269 | } | 234 | } |
270 | } | 235 | } |
271 | 236 | ||
272 | impl ast::RefPat { | ||
273 | pub fn is_mut(&self) -> bool { | ||
274 | self.syntax().children_with_tokens().any(|n| n.kind() == T![mut]) | ||
275 | } | ||
276 | } | ||
277 | |||
278 | impl ast::BindPat { | ||
279 | pub fn is_mutable(&self) -> bool { | ||
280 | self.syntax().children_with_tokens().any(|n| n.kind() == T![mut]) | ||
281 | } | ||
282 | |||
283 | pub fn is_ref(&self) -> bool { | ||
284 | self.syntax().children_with_tokens().any(|n| n.kind() == T![ref]) | ||
285 | } | ||
286 | pub fn has_at(&self) -> bool { | ||
287 | self.syntax().children_with_tokens().any(|it| it.kind() == T![@]) | ||
288 | } | ||
289 | } | ||
290 | |||
291 | pub struct SlicePatComponents { | 237 | pub struct SlicePatComponents { |
292 | pub prefix: Vec<ast::Pat>, | 238 | pub prefix: Vec<ast::Pat>, |
293 | pub slice: Option<ast::Pat>, | 239 | pub slice: Option<ast::Pat>, |
@@ -322,18 +268,6 @@ impl ast::SlicePat { | |||
322 | } | 268 | } |
323 | } | 269 | } |
324 | 270 | ||
325 | impl ast::PointerType { | ||
326 | pub fn is_mut(&self) -> bool { | ||
327 | self.syntax().children_with_tokens().any(|n| n.kind() == T![mut]) | ||
328 | } | ||
329 | } | ||
330 | |||
331 | impl ast::ReferenceType { | ||
332 | pub fn is_mut(&self) -> bool { | ||
333 | self.syntax().children_with_tokens().any(|n| n.kind() == T![mut]) | ||
334 | } | ||
335 | } | ||
336 | |||
337 | #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] | 271 | #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] |
338 | pub enum SelfParamKind { | 272 | pub enum SelfParamKind { |
339 | /// self | 273 | /// self |
@@ -347,7 +281,7 @@ pub enum SelfParamKind { | |||
347 | impl ast::SelfParam { | 281 | impl ast::SelfParam { |
348 | pub fn kind(&self) -> SelfParamKind { | 282 | pub fn kind(&self) -> SelfParamKind { |
349 | if self.amp_token().is_some() { | 283 | if self.amp_token().is_some() { |
350 | if self.amp_mut_kw().is_some() { | 284 | if self.amp_mut_kw_token().is_some() { |
351 | SelfParamKind::MutRef | 285 | SelfParamKind::MutRef |
352 | } else { | 286 | } else { |
353 | SelfParamKind::Ref | 287 | SelfParamKind::Ref |
@@ -358,7 +292,7 @@ impl ast::SelfParam { | |||
358 | } | 292 | } |
359 | 293 | ||
360 | /// the "mut" in "mut self", not the one in "&mut self" | 294 | /// the "mut" in "mut self", not the one in "&mut self" |
361 | pub fn mut_kw(&self) -> Option<ast::MutKw> { | 295 | pub fn mut_kw_token(&self) -> Option<ast::MutKw> { |
362 | self.syntax() | 296 | self.syntax() |
363 | .children_with_tokens() | 297 | .children_with_tokens() |
364 | .filter_map(|it| it.into_token()) | 298 | .filter_map(|it| it.into_token()) |
@@ -367,7 +301,7 @@ impl ast::SelfParam { | |||
367 | } | 301 | } |
368 | 302 | ||
369 | /// the "mut" in "&mut self", not the one in "mut self" | 303 | /// the "mut" in "&mut self", not the one in "mut self" |
370 | pub fn amp_mut_kw(&self) -> Option<ast::MutKw> { | 304 | pub fn amp_mut_kw_token(&self) -> Option<ast::MutKw> { |
371 | self.syntax() | 305 | self.syntax() |
372 | .children_with_tokens() | 306 | .children_with_tokens() |
373 | .filter_map(|it| it.into_token()) | 307 | .filter_map(|it| it.into_token()) |
@@ -399,11 +333,7 @@ impl ast::TypeBound { | |||
399 | } | 333 | } |
400 | } | 334 | } |
401 | 335 | ||
402 | pub fn has_question_mark(&self) -> bool { | 336 | pub fn const_question_token(&self) -> Option<ast::Question> { |
403 | self.question().is_some() | ||
404 | } | ||
405 | |||
406 | pub fn const_question(&self) -> Option<ast::Question> { | ||
407 | self.syntax() | 337 | self.syntax() |
408 | .children_with_tokens() | 338 | .children_with_tokens() |
409 | .filter_map(|it| it.into_token()) | 339 | .filter_map(|it| it.into_token()) |
@@ -411,7 +341,7 @@ impl ast::TypeBound { | |||
411 | .find_map(ast::Question::cast) | 341 | .find_map(ast::Question::cast) |
412 | } | 342 | } |
413 | 343 | ||
414 | pub fn question(&self) -> Option<ast::Question> { | 344 | pub fn question_token(&self) -> Option<ast::Question> { |
415 | if self.const_kw_token().is_some() { | 345 | if self.const_kw_token().is_some() { |
416 | self.syntax() | 346 | self.syntax() |
417 | .children_with_tokens() | 347 | .children_with_tokens() |
@@ -424,12 +354,6 @@ impl ast::TypeBound { | |||
424 | } | 354 | } |
425 | } | 355 | } |
426 | 356 | ||
427 | impl ast::TraitDef { | ||
428 | pub fn is_auto(&self) -> bool { | ||
429 | self.syntax().children_with_tokens().any(|t| t.kind() == T![auto]) | ||
430 | } | ||
431 | } | ||
432 | |||
433 | pub enum VisibilityKind { | 357 | pub enum VisibilityKind { |
434 | In(ast::Path), | 358 | In(ast::Path), |
435 | PubCrate, | 359 | PubCrate, |
@@ -442,28 +366,16 @@ impl ast::Visibility { | |||
442 | pub fn kind(&self) -> VisibilityKind { | 366 | pub fn kind(&self) -> VisibilityKind { |
443 | if let Some(path) = children(self).next() { | 367 | if let Some(path) = children(self).next() { |
444 | VisibilityKind::In(path) | 368 | VisibilityKind::In(path) |
445 | } else if self.is_pub_crate() { | 369 | } else if self.crate_kw_token().is_some() { |
446 | VisibilityKind::PubCrate | 370 | VisibilityKind::PubCrate |
447 | } else if self.is_pub_super() { | 371 | } else if self.super_kw_token().is_some() { |
448 | VisibilityKind::PubSuper | 372 | VisibilityKind::PubSuper |
449 | } else if self.is_pub_self() { | 373 | } else if self.self_kw_token().is_some() { |
450 | VisibilityKind::PubSuper | 374 | VisibilityKind::PubSuper |
451 | } else { | 375 | } else { |
452 | VisibilityKind::Pub | 376 | VisibilityKind::Pub |
453 | } | 377 | } |
454 | } | 378 | } |
455 | |||
456 | fn is_pub_crate(&self) -> bool { | ||
457 | self.syntax().children_with_tokens().any(|it| it.kind() == T![crate]) | ||
458 | } | ||
459 | |||
460 | fn is_pub_super(&self) -> bool { | ||
461 | self.syntax().children_with_tokens().any(|it| it.kind() == T![super]) | ||
462 | } | ||
463 | |||
464 | fn is_pub_self(&self) -> bool { | ||
465 | self.syntax().children_with_tokens().any(|it| it.kind() == T![self]) | ||
466 | } | ||
467 | } | 379 | } |
468 | 380 | ||
469 | impl ast::MacroCall { | 381 | impl ast::MacroCall { |
diff --git a/crates/ra_syntax/src/ast/generated/nodes.rs b/crates/ra_syntax/src/ast/generated/nodes.rs index 0bcb7fe61..bcbfd1129 100644 --- a/crates/ra_syntax/src/ast/generated/nodes.rs +++ b/crates/ra_syntax/src/ast/generated/nodes.rs | |||
@@ -555,6 +555,7 @@ impl AstNode for PointerType { | |||
555 | impl PointerType { | 555 | impl PointerType { |
556 | pub fn star_token(&self) -> Option<Star> { support::token(&self.syntax) } | 556 | pub fn star_token(&self) -> Option<Star> { support::token(&self.syntax) } |
557 | pub fn const_kw_token(&self) -> Option<ConstKw> { support::token(&self.syntax) } | 557 | pub fn const_kw_token(&self) -> Option<ConstKw> { support::token(&self.syntax) } |
558 | pub fn mut_kw_token(&self) -> Option<MutKw> { support::token(&self.syntax) } | ||
558 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } | 559 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } |
559 | } | 560 | } |
560 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 561 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
@@ -1532,6 +1533,7 @@ impl ast::NameOwner for BindPat {} | |||
1532 | impl BindPat { | 1533 | impl BindPat { |
1533 | pub fn ref_kw_token(&self) -> Option<RefKw> { support::token(&self.syntax) } | 1534 | pub fn ref_kw_token(&self) -> Option<RefKw> { support::token(&self.syntax) } |
1534 | pub fn mut_kw_token(&self) -> Option<MutKw> { support::token(&self.syntax) } | 1535 | pub fn mut_kw_token(&self) -> Option<MutKw> { support::token(&self.syntax) } |
1536 | pub fn at_token(&self) -> Option<At> { support::token(&self.syntax) } | ||
1535 | pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } | 1537 | pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } |
1536 | } | 1538 | } |
1537 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1539 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
@@ -2114,6 +2116,7 @@ impl LetStmt { | |||
2114 | pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } | 2116 | pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } |
2115 | pub fn eq_token(&self) -> Option<Eq> { support::token(&self.syntax) } | 2117 | pub fn eq_token(&self) -> Option<Eq> { support::token(&self.syntax) } |
2116 | pub fn initializer(&self) -> Option<Expr> { support::child(&self.syntax) } | 2118 | pub fn initializer(&self) -> Option<Expr> { support::child(&self.syntax) } |
2119 | pub fn semi_token(&self) -> Option<Semi> { support::token(&self.syntax) } | ||
2117 | } | 2120 | } |
2118 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2121 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2119 | pub struct Condition { | 2122 | pub struct Condition { |
diff --git a/xtask/src/ast_src.rs b/xtask/src/ast_src.rs index eba66ff4d..74a87e900 100644 --- a/xtask/src/ast_src.rs +++ b/xtask/src/ast_src.rs | |||
@@ -408,7 +408,7 @@ pub(crate) const AST_SRC: AstSrc = AstSrc { | |||
408 | struct TupleType { LParen, fields: [TypeRef], RParen } | 408 | struct TupleType { LParen, fields: [TypeRef], RParen } |
409 | struct NeverType { Excl } | 409 | struct NeverType { Excl } |
410 | struct PathType { Path } | 410 | struct PathType { Path } |
411 | struct PointerType { Star, ConstKw, TypeRef } | 411 | struct PointerType { Star, ConstKw, MutKw, TypeRef } |
412 | struct ArrayType { LBrack, TypeRef, Semi, Expr, RBrack } | 412 | struct ArrayType { LBrack, TypeRef, Semi, Expr, RBrack } |
413 | struct SliceType { LBrack, TypeRef, RBrack } | 413 | struct SliceType { LBrack, TypeRef, RBrack } |
414 | struct ReferenceType { Amp, Lifetime, MutKw, TypeRef } | 414 | struct ReferenceType { Amp, Lifetime, MutKw, TypeRef } |
@@ -485,7 +485,7 @@ pub(crate) const AST_SRC: AstSrc = AstSrc { | |||
485 | struct ParenPat { LParen, Pat, RParen } | 485 | struct ParenPat { LParen, Pat, RParen } |
486 | struct RefPat { Amp, MutKw, Pat } | 486 | struct RefPat { Amp, MutKw, Pat } |
487 | struct BoxPat { BoxKw, Pat } | 487 | struct BoxPat { BoxKw, Pat } |
488 | struct BindPat: AttrsOwner, NameOwner { RefKw, MutKw, Pat } | 488 | struct BindPat: AttrsOwner, NameOwner { RefKw, MutKw, At, Pat } |
489 | struct PlaceholderPat { Underscore } | 489 | struct PlaceholderPat { Underscore } |
490 | struct DotDotPat { Dotdot } | 490 | struct DotDotPat { Dotdot } |
491 | struct PathPat { Path } | 491 | struct PathPat { Path } |
@@ -545,6 +545,7 @@ pub(crate) const AST_SRC: AstSrc = AstSrc { | |||
545 | Pat, | 545 | Pat, |
546 | Eq, | 546 | Eq, |
547 | initializer: Expr, | 547 | initializer: Expr, |
548 | Semi, | ||
548 | } | 549 | } |
549 | struct Condition { LetKw, Pat, Eq, Expr } | 550 | struct Condition { LetKw, Pat, Eq, Expr } |
550 | struct Block: AttrsOwner, ModuleItemOwner { | 551 | struct Block: AttrsOwner, ModuleItemOwner { |