aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_assists/src/handlers/add_explicit_type.rs16
-rw-r--r--crates/ra_assists/src/handlers/generate_new.rs9
-rw-r--r--crates/ra_assists/src/handlers/introduce_named_lifetime.rs4
-rw-r--r--crates/ra_hir_def/src/adt.rs4
-rw-r--r--crates/ra_hir_def/src/body/lower.rs8
-rw-r--r--crates/ra_hir_def/src/item_tree.rs2
-rw-r--r--crates/ra_hir_def/src/item_tree/lower.rs10
-rw-r--r--crates/ra_hir_def/src/path/lower.rs4
-rw-r--r--crates/ra_hir_def/src/type_ref.rs7
-rw-r--r--crates/ra_ide/src/display/short_label.rs14
-rw-r--r--crates/ra_ide/src/file_structure.rs28
-rw-r--r--crates/ra_ide/src/inlay_hints.rs6
-rw-r--r--crates/ra_ide/src/references/rename.rs5
-rw-r--r--crates/ra_syntax/src/ast/generated/nodes.rs14
-rw-r--r--crates/ra_syntax/src/ast/traits.rs6
-rw-r--r--xtask/src/codegen/gen_syntax.rs1
-rw-r--r--xtask/src/codegen/rust.ungram16
17 files changed, 64 insertions, 90 deletions
diff --git a/crates/ra_assists/src/handlers/add_explicit_type.rs b/crates/ra_assists/src/handlers/add_explicit_type.rs
index 39a5321d1..e69f0a89b 100644
--- a/crates/ra_assists/src/handlers/add_explicit_type.rs
+++ b/crates/ra_assists/src/handlers/add_explicit_type.rs
@@ -1,6 +1,6 @@
1use hir::HirDisplay; 1use hir::HirDisplay;
2use ra_syntax::{ 2use ra_syntax::{
3 ast::{self, AstNode, LetStmt, NameOwner, TypeAscriptionOwner}, 3 ast::{self, AstNode, LetStmt, NameOwner},
4 TextRange, 4 TextRange,
5}; 5};
6 6
@@ -22,11 +22,11 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
22// } 22// }
23// ``` 23// ```
24pub(crate) fn add_explicit_type(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { 24pub(crate) fn add_explicit_type(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
25 let stmt = ctx.find_node_at_offset::<LetStmt>()?; 25 let let_stmt = ctx.find_node_at_offset::<LetStmt>()?;
26 let module = ctx.sema.scope(stmt.syntax()).module()?; 26 let module = ctx.sema.scope(let_stmt.syntax()).module()?;
27 let expr = stmt.initializer()?; 27 let expr = let_stmt.initializer()?;
28 // Must be a binding 28 // Must be a binding
29 let pat = match stmt.pat()? { 29 let pat = match let_stmt.pat()? {
30 ast::Pat::BindPat(bind_pat) => bind_pat, 30 ast::Pat::BindPat(bind_pat) => bind_pat,
31 _ => return None, 31 _ => return None,
32 }; 32 };
@@ -34,8 +34,8 @@ pub(crate) fn add_explicit_type(acc: &mut Assists, ctx: &AssistContext) -> Optio
34 // The binding must have a name 34 // The binding must have a name
35 let name = pat.name()?; 35 let name = pat.name()?;
36 let name_range = name.syntax().text_range(); 36 let name_range = name.syntax().text_range();
37 let stmt_range = stmt.syntax().text_range(); 37 let stmt_range = let_stmt.syntax().text_range();
38 let eq_range = stmt.eq_token()?.text_range(); 38 let eq_range = let_stmt.eq_token()?.text_range();
39 // Assist should only be applicable if cursor is between 'let' and '=' 39 // Assist should only be applicable if cursor is between 'let' and '='
40 let let_range = TextRange::new(stmt_range.start(), eq_range.start()); 40 let let_range = TextRange::new(stmt_range.start(), eq_range.start());
41 let cursor_in_range = let_range.contains_range(ctx.frange.range); 41 let cursor_in_range = let_range.contains_range(ctx.frange.range);
@@ -44,7 +44,7 @@ pub(crate) fn add_explicit_type(acc: &mut Assists, ctx: &AssistContext) -> Optio
44 } 44 }
45 // Assist not applicable if the type has already been specified 45 // Assist not applicable if the type has already been specified
46 // and it has no placeholders 46 // and it has no placeholders
47 let ascribed_ty = stmt.ascribed_type(); 47 let ascribed_ty = let_stmt.ty();
48 if let Some(ty) = &ascribed_ty { 48 if let Some(ty) = &ascribed_ty {
49 if ty.syntax().descendants().find_map(ast::PlaceholderType::cast).is_none() { 49 if ty.syntax().descendants().find_map(ast::PlaceholderType::cast).is_none() {
50 return None; 50 return None;
diff --git a/crates/ra_assists/src/handlers/generate_new.rs b/crates/ra_assists/src/handlers/generate_new.rs
index 3c67749ee..b84aa24b6 100644
--- a/crates/ra_assists/src/handlers/generate_new.rs
+++ b/crates/ra_assists/src/handlers/generate_new.rs
@@ -1,9 +1,6 @@
1use hir::Adt; 1use hir::Adt;
2use ra_syntax::{ 2use ra_syntax::{
3 ast::{ 3 ast::{self, AstNode, GenericParamsOwner, NameOwner, StructKind, VisibilityOwner},
4 self, AstNode, GenericParamsOwner, NameOwner, StructKind, TypeAscriptionOwner,
5 VisibilityOwner,
6 },
7 T, 4 T,
8}; 5};
9use stdx::{format_to, SepBy}; 6use stdx::{format_to, SepBy};
@@ -54,9 +51,7 @@ pub(crate) fn generate_new(acc: &mut Assists, ctx: &AssistContext) -> Option<()>
54 51
55 let params = field_list 52 let params = field_list
56 .fields() 53 .fields()
57 .filter_map(|f| { 54 .filter_map(|f| Some(format!("{}: {}", f.name()?.syntax(), f.ty()?.syntax())))
58 Some(format!("{}: {}", f.name()?.syntax(), f.ascribed_type()?.syntax()))
59 })
60 .sep_by(", "); 55 .sep_by(", ");
61 let fields = field_list.fields().filter_map(|f| f.name()).sep_by(", "); 56 let fields = field_list.fields().filter_map(|f| f.name()).sep_by(", ");
62 57
diff --git a/crates/ra_assists/src/handlers/introduce_named_lifetime.rs b/crates/ra_assists/src/handlers/introduce_named_lifetime.rs
index 92a1a5925..c3134f64d 100644
--- a/crates/ra_assists/src/handlers/introduce_named_lifetime.rs
+++ b/crates/ra_assists/src/handlers/introduce_named_lifetime.rs
@@ -1,5 +1,5 @@
1use ra_syntax::{ 1use ra_syntax::{
2 ast::{self, GenericParamsOwner, NameOwner, TypeAscriptionOwner}, 2 ast::{self, GenericParamsOwner, NameOwner},
3 AstNode, SyntaxKind, TextRange, TextSize, 3 AstNode, SyntaxKind, TextRange, TextSize,
4}; 4};
5use rustc_hash::FxHashSet; 5use rustc_hash::FxHashSet;
@@ -67,7 +67,7 @@ fn generate_fn_def_assist(
67 // otherwise, if there's a single reference parameter without a named liftime, use that 67 // otherwise, if there's a single reference parameter without a named liftime, use that
68 let fn_params_without_lifetime: Vec<_> = param_list 68 let fn_params_without_lifetime: Vec<_> = param_list
69 .params() 69 .params()
70 .filter_map(|param| match param.ascribed_type() { 70 .filter_map(|param| match param.ty() {
71 Some(ast::TypeRef::ReferenceType(ascribed_type)) 71 Some(ast::TypeRef::ReferenceType(ascribed_type))
72 if ascribed_type.lifetime_token() == None => 72 if ascribed_type.lifetime_token() == None =>
73 { 73 {
diff --git a/crates/ra_hir_def/src/adt.rs b/crates/ra_hir_def/src/adt.rs
index 231c1dfab..f8523d03f 100644
--- a/crates/ra_hir_def/src/adt.rs
+++ b/crates/ra_hir_def/src/adt.rs
@@ -8,7 +8,7 @@ use hir_expand::{
8 InFile, 8 InFile,
9}; 9};
10use ra_arena::{map::ArenaMap, Arena}; 10use ra_arena::{map::ArenaMap, Arena};
11use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner, VisibilityOwner}; 11use ra_syntax::ast::{self, NameOwner, VisibilityOwner};
12 12
13use crate::{ 13use crate::{
14 body::{CfgExpander, LowerCtx}, 14 body::{CfgExpander, LowerCtx},
@@ -251,7 +251,7 @@ fn lower_struct(
251 || Either::Right(fd.clone()), 251 || Either::Right(fd.clone()),
252 || FieldData { 252 || FieldData {
253 name: fd.name().map(|n| n.as_name()).unwrap_or_else(Name::missing), 253 name: fd.name().map(|n| n.as_name()).unwrap_or_else(Name::missing),
254 type_ref: TypeRef::from_ast_opt(&ctx, fd.ascribed_type()), 254 type_ref: TypeRef::from_ast_opt(&ctx, fd.ty()),
255 visibility: RawVisibility::from_ast(db, ast.with_value(fd.visibility())), 255 visibility: RawVisibility::from_ast(db, ast.with_value(fd.visibility())),
256 }, 256 },
257 ); 257 );
diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs
index 78f6da5b8..288ca76c3 100644
--- a/crates/ra_hir_def/src/body/lower.rs
+++ b/crates/ra_hir_def/src/body/lower.rs
@@ -11,7 +11,7 @@ use ra_arena::Arena;
11use ra_syntax::{ 11use ra_syntax::{
12 ast::{ 12 ast::{
13 self, ArgListOwner, ArrayExprKind, LiteralKind, LoopBodyOwner, ModuleItemOwner, NameOwner, 13 self, ArgListOwner, ArrayExprKind, LiteralKind, LoopBodyOwner, ModuleItemOwner, NameOwner,
14 SlicePatComponents, TypeAscriptionOwner, 14 SlicePatComponents,
15 }, 15 },
16 AstNode, AstPtr, 16 AstNode, AstPtr,
17}; 17};
@@ -466,8 +466,7 @@ impl ExprCollector<'_> {
466 if let Some(pl) = e.param_list() { 466 if let Some(pl) = e.param_list() {
467 for param in pl.params() { 467 for param in pl.params() {
468 let pat = self.collect_pat_opt(param.pat()); 468 let pat = self.collect_pat_opt(param.pat());
469 let type_ref = 469 let type_ref = param.ty().map(|it| TypeRef::from_ast(&self.ctx(), it));
470 param.ascribed_type().map(|it| TypeRef::from_ast(&self.ctx(), it));
471 args.push(pat); 470 args.push(pat);
472 arg_types.push(type_ref); 471 arg_types.push(type_ref);
473 } 472 }
@@ -607,8 +606,7 @@ impl ExprCollector<'_> {
607 .map(|s| match s { 606 .map(|s| match s {
608 ast::Stmt::LetStmt(stmt) => { 607 ast::Stmt::LetStmt(stmt) => {
609 let pat = self.collect_pat_opt(stmt.pat()); 608 let pat = self.collect_pat_opt(stmt.pat());
610 let type_ref = 609 let type_ref = stmt.ty().map(|it| TypeRef::from_ast(&self.ctx(), it));
611 stmt.ascribed_type().map(|it| TypeRef::from_ast(&self.ctx(), it));
612 let initializer = stmt.initializer().map(|e| self.collect_expr(e)); 610 let initializer = stmt.initializer().map(|e| self.collect_expr(e));
613 Statement::Let { pat, type_ref, initializer } 611 Statement::Let { pat, type_ref, initializer }
614 } 612 }
diff --git a/crates/ra_hir_def/src/item_tree.rs b/crates/ra_hir_def/src/item_tree.rs
index 63b56405c..a67e75dac 100644
--- a/crates/ra_hir_def/src/item_tree.rs
+++ b/crates/ra_hir_def/src/item_tree.rs
@@ -13,7 +13,7 @@ use std::{
13 sync::Arc, 13 sync::Arc,
14}; 14};
15 15
16use ast::{AstNode, AttrsOwner, NameOwner, StructKind, TypeAscriptionOwner}; 16use ast::{AstNode, AttrsOwner, NameOwner, StructKind};
17use either::Either; 17use either::Either;
18use hir_expand::{ 18use hir_expand::{
19 ast_id_map::FileAstId, 19 ast_id_map::FileAstId,
diff --git a/crates/ra_hir_def/src/item_tree/lower.rs b/crates/ra_hir_def/src/item_tree/lower.rs
index 29f1de547..f0ced1f79 100644
--- a/crates/ra_hir_def/src/item_tree/lower.rs
+++ b/crates/ra_hir_def/src/item_tree/lower.rs
@@ -209,7 +209,7 @@ impl Ctx {
209 fn lower_record_field(&mut self, field: &ast::RecordField) -> Option<Field> { 209 fn lower_record_field(&mut self, field: &ast::RecordField) -> Option<Field> {
210 let name = field.name()?.as_name(); 210 let name = field.name()?.as_name();
211 let visibility = self.lower_visibility(field); 211 let visibility = self.lower_visibility(field);
212 let type_ref = self.lower_type_ref_opt(field.ascribed_type()); 212 let type_ref = self.lower_type_ref_opt(field.ty());
213 let res = Field { name, type_ref, visibility }; 213 let res = Field { name, type_ref, visibility };
214 Some(res) 214 Some(res)
215 } 215 }
@@ -286,7 +286,7 @@ impl Ctx {
286 let mut has_self_param = false; 286 let mut has_self_param = false;
287 if let Some(param_list) = func.param_list() { 287 if let Some(param_list) = func.param_list() {
288 if let Some(self_param) = param_list.self_param() { 288 if let Some(self_param) = param_list.self_param() {
289 let self_type = match self_param.ascribed_type() { 289 let self_type = match self_param.ty() {
290 Some(type_ref) => TypeRef::from_ast(&self.body_ctx, type_ref), 290 Some(type_ref) => TypeRef::from_ast(&self.body_ctx, type_ref),
291 None => { 291 None => {
292 let self_type = TypeRef::Path(name![Self].into()); 292 let self_type = TypeRef::Path(name![Self].into());
@@ -305,7 +305,7 @@ impl Ctx {
305 has_self_param = true; 305 has_self_param = true;
306 } 306 }
307 for param in param_list.params() { 307 for param in param_list.params() {
308 let type_ref = TypeRef::from_ast_opt(&self.body_ctx, param.ascribed_type()); 308 let type_ref = TypeRef::from_ast_opt(&self.body_ctx, param.ty());
309 params.push(type_ref); 309 params.push(type_ref);
310 } 310 }
311 } 311 }
@@ -370,7 +370,7 @@ impl Ctx {
370 370
371 fn lower_static(&mut self, static_: &ast::Static) -> Option<FileItemTreeId<Static>> { 371 fn lower_static(&mut self, static_: &ast::Static) -> Option<FileItemTreeId<Static>> {
372 let name = static_.name()?.as_name(); 372 let name = static_.name()?.as_name();
373 let type_ref = self.lower_type_ref_opt(static_.ascribed_type()); 373 let type_ref = self.lower_type_ref_opt(static_.ty());
374 let visibility = self.lower_visibility(static_); 374 let visibility = self.lower_visibility(static_);
375 let mutable = static_.mut_token().is_some(); 375 let mutable = static_.mut_token().is_some();
376 let ast_id = self.source_ast_id_map.ast_id(static_); 376 let ast_id = self.source_ast_id_map.ast_id(static_);
@@ -380,7 +380,7 @@ impl Ctx {
380 380
381 fn lower_const(&mut self, konst: &ast::Const) -> FileItemTreeId<Const> { 381 fn lower_const(&mut self, konst: &ast::Const) -> FileItemTreeId<Const> {
382 let name = konst.name().map(|it| it.as_name()); 382 let name = konst.name().map(|it| it.as_name());
383 let type_ref = self.lower_type_ref_opt(konst.ascribed_type()); 383 let type_ref = self.lower_type_ref_opt(konst.ty());
384 let visibility = self.lower_visibility(konst); 384 let visibility = self.lower_visibility(konst);
385 let ast_id = self.source_ast_id_map.ast_id(konst); 385 let ast_id = self.source_ast_id_map.ast_id(konst);
386 let res = Const { name, visibility, type_ref, ast_id }; 386 let res = Const { name, visibility, type_ref, ast_id };
diff --git a/crates/ra_hir_def/src/path/lower.rs b/crates/ra_hir_def/src/path/lower.rs
index 6a0c019fd..dfab15948 100644
--- a/crates/ra_hir_def/src/path/lower.rs
+++ b/crates/ra_hir_def/src/path/lower.rs
@@ -9,7 +9,7 @@ use hir_expand::{
9 hygiene::Hygiene, 9 hygiene::Hygiene,
10 name::{name, AsName}, 10 name::{name, AsName},
11}; 11};
12use ra_syntax::ast::{self, AstNode, TypeAscriptionOwner, TypeBoundsOwner}; 12use ra_syntax::ast::{self, AstNode, TypeBoundsOwner};
13 13
14use super::AssociatedTypeBinding; 14use super::AssociatedTypeBinding;
15use crate::{ 15use crate::{
@@ -189,7 +189,7 @@ fn lower_generic_args_from_fn_path(
189 if let Some(params) = params { 189 if let Some(params) = params {
190 let mut param_types = Vec::new(); 190 let mut param_types = Vec::new();
191 for param in params.params() { 191 for param in params.params() {
192 let type_ref = TypeRef::from_ast_opt(&ctx, param.ascribed_type()); 192 let type_ref = TypeRef::from_ast_opt(&ctx, param.ty());
193 param_types.push(type_ref); 193 param_types.push(type_ref);
194 } 194 }
195 let arg = GenericArg::Type(TypeRef::Tuple(param_types)); 195 let arg = GenericArg::Type(TypeRef::Tuple(param_types));
diff --git a/crates/ra_hir_def/src/type_ref.rs b/crates/ra_hir_def/src/type_ref.rs
index 970fc9af5..4059302df 100644
--- a/crates/ra_hir_def/src/type_ref.rs
+++ b/crates/ra_hir_def/src/type_ref.rs
@@ -1,7 +1,7 @@
1//! HIR for references to types. Paths in these are not yet resolved. They can 1//! HIR for references to types. Paths in these are not yet resolved. They can
2//! be directly created from an ast::TypeRef, without further queries. 2//! be directly created from an ast::TypeRef, without further queries.
3 3
4use ra_syntax::ast::{self, TypeAscriptionOwner}; 4use ra_syntax::ast::{self};
5 5
6use crate::{body::LowerCtx, path::Path}; 6use crate::{body::LowerCtx, path::Path};
7 7
@@ -124,10 +124,7 @@ impl TypeRef {
124 is_varargs = param.dotdotdot_token().is_some(); 124 is_varargs = param.dotdotdot_token().is_some();
125 } 125 }
126 126
127 pl.params() 127 pl.params().map(|p| p.ty()).map(|it| TypeRef::from_ast_opt(&ctx, it)).collect()
128 .map(|p| p.ascribed_type())
129 .map(|it| TypeRef::from_ast_opt(&ctx, it))
130 .collect()
131 } else { 128 } else {
132 Vec::new() 129 Vec::new()
133 }; 130 };
diff --git a/crates/ra_ide/src/display/short_label.rs b/crates/ra_ide/src/display/short_label.rs
index c600908a4..bddf1bd47 100644
--- a/crates/ra_ide/src/display/short_label.rs
+++ b/crates/ra_ide/src/display/short_label.rs
@@ -1,6 +1,6 @@
1//! FIXME: write short doc here 1//! FIXME: write short doc here
2 2
3use ra_syntax::ast::{self, AstNode, NameOwner, TypeAscriptionOwner, VisibilityOwner}; 3use ra_syntax::ast::{self, AstNode, NameOwner, VisibilityOwner};
4use stdx::format_to; 4use stdx::format_to;
5 5
6pub(crate) trait ShortLabel { 6pub(crate) trait ShortLabel {
@@ -55,19 +55,19 @@ impl ShortLabel for ast::TypeAlias {
55 55
56impl ShortLabel for ast::Const { 56impl ShortLabel for ast::Const {
57 fn short_label(&self) -> Option<String> { 57 fn short_label(&self) -> Option<String> {
58 short_label_from_ascribed_node(self, "const ") 58 short_label_from_ty(self, self.ty(), "const ")
59 } 59 }
60} 60}
61 61
62impl ShortLabel for ast::Static { 62impl ShortLabel for ast::Static {
63 fn short_label(&self) -> Option<String> { 63 fn short_label(&self) -> Option<String> {
64 short_label_from_ascribed_node(self, "static ") 64 short_label_from_ty(self, self.ty(), "static ")
65 } 65 }
66} 66}
67 67
68impl ShortLabel for ast::RecordField { 68impl ShortLabel for ast::RecordField {
69 fn short_label(&self) -> Option<String> { 69 fn short_label(&self) -> Option<String> {
70 short_label_from_ascribed_node(self, "") 70 short_label_from_ty(self, self.ty(), "")
71 } 71 }
72} 72}
73 73
@@ -77,13 +77,13 @@ impl ShortLabel for ast::Variant {
77 } 77 }
78} 78}
79 79
80fn short_label_from_ascribed_node<T>(node: &T, prefix: &str) -> Option<String> 80fn short_label_from_ty<T>(node: &T, ty: Option<ast::TypeRef>, prefix: &str) -> Option<String>
81where 81where
82 T: NameOwner + VisibilityOwner + TypeAscriptionOwner, 82 T: NameOwner + VisibilityOwner,
83{ 83{
84 let mut buf = short_label_from_node(node, prefix)?; 84 let mut buf = short_label_from_node(node, prefix)?;
85 85
86 if let Some(type_ref) = node.ascribed_type() { 86 if let Some(type_ref) = ty {
87 format_to!(buf, ": {}", type_ref.syntax()); 87 format_to!(buf, ": {}", type_ref.syntax());
88 } 88 }
89 89
diff --git a/crates/ra_ide/src/file_structure.rs b/crates/ra_ide/src/file_structure.rs
index 7d378f2d0..22cf8637a 100644
--- a/crates/ra_ide/src/file_structure.rs
+++ b/crates/ra_ide/src/file_structure.rs
@@ -1,5 +1,5 @@
1use ra_syntax::{ 1use ra_syntax::{
2 ast::{self, AttrsOwner, GenericParamsOwner, NameOwner, TypeAscriptionOwner}, 2 ast::{self, AttrsOwner, GenericParamsOwner, NameOwner},
3 match_ast, AstNode, SourceFile, SyntaxKind, SyntaxNode, TextRange, WalkEvent, 3 match_ast, AstNode, SourceFile, SyntaxKind, SyntaxNode, TextRange, WalkEvent,
4}; 4};
5 5
@@ -52,18 +52,11 @@ pub fn file_structure(file: &SourceFile) -> Vec<StructureNode> {
52 52
53fn structure_node(node: &SyntaxNode) -> Option<StructureNode> { 53fn structure_node(node: &SyntaxNode) -> Option<StructureNode> {
54 fn decl<N: NameOwner + AttrsOwner>(node: N) -> Option<StructureNode> { 54 fn decl<N: NameOwner + AttrsOwner>(node: N) -> Option<StructureNode> {
55 decl_with_detail(node, None) 55 decl_with_detail(&node, None)
56 }
57
58 fn decl_with_ascription<N: NameOwner + AttrsOwner + TypeAscriptionOwner>(
59 node: N,
60 ) -> Option<StructureNode> {
61 let ty = node.ascribed_type();
62 decl_with_type_ref(node, ty)
63 } 56 }
64 57
65 fn decl_with_type_ref<N: NameOwner + AttrsOwner>( 58 fn decl_with_type_ref<N: NameOwner + AttrsOwner>(
66 node: N, 59 node: &N,
67 type_ref: Option<ast::TypeRef>, 60 type_ref: Option<ast::TypeRef>,
68 ) -> Option<StructureNode> { 61 ) -> Option<StructureNode> {
69 let detail = type_ref.map(|type_ref| { 62 let detail = type_ref.map(|type_ref| {
@@ -75,7 +68,7 @@ fn structure_node(node: &SyntaxNode) -> Option<StructureNode> {
75 } 68 }
76 69
77 fn decl_with_detail<N: NameOwner + AttrsOwner>( 70 fn decl_with_detail<N: NameOwner + AttrsOwner>(
78 node: N, 71 node: &N,
79 detail: Option<String>, 72 detail: Option<String>,
80 ) -> Option<StructureNode> { 73 ) -> Option<StructureNode> {
81 let name = node.name()?; 74 let name = node.name()?;
@@ -124,7 +117,7 @@ fn structure_node(node: &SyntaxNode) -> Option<StructureNode> {
124 collapse_ws(ret_type.syntax(), &mut detail); 117 collapse_ws(ret_type.syntax(), &mut detail);
125 } 118 }
126 119
127 decl_with_detail(it, Some(detail)) 120 decl_with_detail(&it, Some(detail))
128 }, 121 },
129 ast::Struct(it) => decl(it), 122 ast::Struct(it) => decl(it),
130 ast::Union(it) => decl(it), 123 ast::Union(it) => decl(it),
@@ -132,13 +125,10 @@ fn structure_node(node: &SyntaxNode) -> Option<StructureNode> {
132 ast::Variant(it) => decl(it), 125 ast::Variant(it) => decl(it),
133 ast::Trait(it) => decl(it), 126 ast::Trait(it) => decl(it),
134 ast::Module(it) => decl(it), 127 ast::Module(it) => decl(it),
135 ast::TypeAlias(it) => { 128 ast::TypeAlias(it) => decl_with_type_ref(&it, it.type_ref()),
136 let ty = it.type_ref(); 129 ast::RecordField(it) => decl_with_type_ref(&it, it.ty()),
137 decl_with_type_ref(it, ty) 130 ast::Const(it) => decl_with_type_ref(&it, it.ty()),
138 }, 131 ast::Static(it) => decl_with_type_ref(&it, it.ty()),
139 ast::RecordField(it) => decl_with_ascription(it),
140 ast::Const(it) => decl_with_ascription(it),
141 ast::Static(it) => decl_with_ascription(it),
142 ast::Impl(it) => { 132 ast::Impl(it) => {
143 let target_type = it.target_type()?; 133 let target_type = it.target_type()?;
144 let target_trait = it.target_trait(); 134 let target_trait = it.target_trait();
diff --git a/crates/ra_ide/src/inlay_hints.rs b/crates/ra_ide/src/inlay_hints.rs
index 714ba6bd9..4bbbcd258 100644
--- a/crates/ra_ide/src/inlay_hints.rs
+++ b/crates/ra_ide/src/inlay_hints.rs
@@ -2,7 +2,7 @@ use hir::{Adt, Callable, HirDisplay, Semantics, Type};
2use ra_ide_db::RootDatabase; 2use ra_ide_db::RootDatabase;
3use ra_prof::profile; 3use ra_prof::profile;
4use ra_syntax::{ 4use ra_syntax::{
5 ast::{self, ArgListOwner, AstNode, TypeAscriptionOwner}, 5 ast::{self, ArgListOwner, AstNode},
6 match_ast, Direction, NodeOrToken, SmolStr, SyntaxKind, TextRange, T, 6 match_ast, Direction, NodeOrToken, SmolStr, SyntaxKind, TextRange, T,
7}; 7};
8use stdx::to_lower_snake_case; 8use stdx::to_lower_snake_case;
@@ -230,10 +230,10 @@ fn should_not_display_type_hint(db: &RootDatabase, bind_pat: &ast::BindPat, pat_
230 match_ast! { 230 match_ast! {
231 match node { 231 match node {
232 ast::LetStmt(it) => { 232 ast::LetStmt(it) => {
233 return it.ascribed_type().is_some() 233 return it.ty().is_some()
234 }, 234 },
235 ast::Param(it) => { 235 ast::Param(it) => {
236 return it.ascribed_type().is_some() 236 return it.ty().is_some()
237 }, 237 },
238 ast::MatchArm(_it) => { 238 ast::MatchArm(_it) => {
239 return pat_is_enum_variant(db, bind_pat, pat_ty); 239 return pat_is_enum_variant(db, bind_pat, pat_ty);
diff --git a/crates/ra_ide/src/references/rename.rs b/crates/ra_ide/src/references/rename.rs
index d330109f1..31654bf79 100644
--- a/crates/ra_ide/src/references/rename.rs
+++ b/crates/ra_ide/src/references/rename.rs
@@ -7,7 +7,8 @@ use ra_ide_db::{
7 RootDatabase, 7 RootDatabase,
8}; 8};
9use ra_syntax::{ 9use ra_syntax::{
10 algo::find_node_at_offset, ast, ast::NameOwner, ast::TypeAscriptionOwner, 10 algo::find_node_at_offset,
11 ast::{self, NameOwner},
11 lex_single_valid_syntax_kind, match_ast, AstNode, SyntaxKind, SyntaxNode, SyntaxToken, 12 lex_single_valid_syntax_kind, match_ast, AstNode, SyntaxKind, SyntaxNode, SyntaxToken,
12}; 13};
13use ra_text_edit::TextEdit; 14use ra_text_edit::TextEdit;
@@ -155,7 +156,7 @@ fn rename_to_self(
155 return None; // method already has self param 156 return None; // method already has self param
156 } 157 }
157 let first_param = params.params().next()?; 158 let first_param = params.params().next()?;
158 let mutable = match first_param.ascribed_type() { 159 let mutable = match first_param.ty() {
159 Some(ast::TypeRef::ReferenceType(rt)) => rt.mut_token().is_some(), 160 Some(ast::TypeRef::ReferenceType(rt)) => rt.mut_token().is_some(),
160 _ => return None, // not renaming other types 161 _ => return None, // not renaming other types
161 }; 162 };
diff --git a/crates/ra_syntax/src/ast/generated/nodes.rs b/crates/ra_syntax/src/ast/generated/nodes.rs
index c20ff53bf..207826979 100644
--- a/crates/ra_syntax/src/ast/generated/nodes.rs
+++ b/crates/ra_syntax/src/ast/generated/nodes.rs
@@ -35,12 +35,12 @@ pub struct Const {
35impl ast::AttrsOwner for Const {} 35impl ast::AttrsOwner for Const {}
36impl ast::NameOwner for Const {} 36impl ast::NameOwner for Const {}
37impl ast::VisibilityOwner for Const {} 37impl ast::VisibilityOwner for Const {}
38impl ast::TypeAscriptionOwner for Const {}
39impl Const { 38impl Const {
40 pub fn default_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![default]) } 39 pub fn default_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![default]) }
41 pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) } 40 pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) }
42 pub fn underscore_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![_]) } 41 pub fn underscore_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![_]) }
43 pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) } 42 pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) }
43 pub fn ty(&self) -> Option<TypeRef> { support::child(&self.syntax) }
44 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } 44 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) }
45 pub fn body(&self) -> Option<Expr> { support::child(&self.syntax) } 45 pub fn body(&self) -> Option<Expr> { support::child(&self.syntax) }
46 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } 46 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
@@ -148,11 +148,11 @@ pub struct Static {
148impl ast::AttrsOwner for Static {} 148impl ast::AttrsOwner for Static {}
149impl ast::NameOwner for Static {} 149impl ast::NameOwner for Static {}
150impl ast::VisibilityOwner for Static {} 150impl ast::VisibilityOwner for Static {}
151impl ast::TypeAscriptionOwner for Static {}
152impl Static { 151impl Static {
153 pub fn static_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![static]) } 152 pub fn static_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![static]) }
154 pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) } 153 pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) }
155 pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) } 154 pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) }
155 pub fn ty(&self) -> Option<TypeRef> { support::child(&self.syntax) }
156 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } 156 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) }
157 pub fn body(&self) -> Option<Expr> { support::child(&self.syntax) } 157 pub fn body(&self) -> Option<Expr> { support::child(&self.syntax) }
158 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } 158 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
@@ -361,7 +361,6 @@ pub struct SelfParam {
361 pub(crate) syntax: SyntaxNode, 361 pub(crate) syntax: SyntaxNode,
362} 362}
363impl ast::AttrsOwner for SelfParam {} 363impl ast::AttrsOwner for SelfParam {}
364impl ast::TypeAscriptionOwner for SelfParam {}
365impl SelfParam { 364impl SelfParam {
366 pub fn amp_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![&]) } 365 pub fn amp_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![&]) }
367 pub fn lifetime_token(&self) -> Option<SyntaxToken> { 366 pub fn lifetime_token(&self) -> Option<SyntaxToken> {
@@ -370,16 +369,17 @@ impl SelfParam {
370 pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) } 369 pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) }
371 pub fn self_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![self]) } 370 pub fn self_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![self]) }
372 pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) } 371 pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) }
372 pub fn ty(&self) -> Option<TypeRef> { support::child(&self.syntax) }
373} 373}
374#[derive(Debug, Clone, PartialEq, Eq, Hash)] 374#[derive(Debug, Clone, PartialEq, Eq, Hash)]
375pub struct Param { 375pub struct Param {
376 pub(crate) syntax: SyntaxNode, 376 pub(crate) syntax: SyntaxNode,
377} 377}
378impl ast::AttrsOwner for Param {} 378impl ast::AttrsOwner for Param {}
379impl ast::TypeAscriptionOwner for Param {}
380impl Param { 379impl Param {
381 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } 380 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) }
382 pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) } 381 pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) }
382 pub fn ty(&self) -> Option<TypeRef> { support::child(&self.syntax) }
383 pub fn dotdotdot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![...]) } 383 pub fn dotdotdot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![...]) }
384} 384}
385#[derive(Debug, Clone, PartialEq, Eq, Hash)] 385#[derive(Debug, Clone, PartialEq, Eq, Hash)]
@@ -414,9 +414,9 @@ pub struct RecordField {
414impl ast::AttrsOwner for RecordField {} 414impl ast::AttrsOwner for RecordField {}
415impl ast::NameOwner for RecordField {} 415impl ast::NameOwner for RecordField {}
416impl ast::VisibilityOwner for RecordField {} 416impl ast::VisibilityOwner for RecordField {}
417impl ast::TypeAscriptionOwner for RecordField {}
418impl RecordField { 417impl RecordField {
419 pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) } 418 pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) }
419 pub fn ty(&self) -> Option<TypeRef> { support::child(&self.syntax) }
420} 420}
421#[derive(Debug, Clone, PartialEq, Eq, Hash)] 421#[derive(Debug, Clone, PartialEq, Eq, Hash)]
422pub struct TupleField { 422pub struct TupleField {
@@ -495,10 +495,10 @@ pub struct ConstParam {
495} 495}
496impl ast::AttrsOwner for ConstParam {} 496impl ast::AttrsOwner for ConstParam {}
497impl ast::NameOwner for ConstParam {} 497impl ast::NameOwner for ConstParam {}
498impl ast::TypeAscriptionOwner for ConstParam {}
499impl ConstParam { 498impl ConstParam {
500 pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) } 499 pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) }
501 pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) } 500 pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) }
501 pub fn ty(&self) -> Option<TypeRef> { support::child(&self.syntax) }
502 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } 502 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) }
503 pub fn default_val(&self) -> Option<Expr> { support::child(&self.syntax) } 503 pub fn default_val(&self) -> Option<Expr> { support::child(&self.syntax) }
504} 504}
@@ -1203,11 +1203,11 @@ pub struct LetStmt {
1203 pub(crate) syntax: SyntaxNode, 1203 pub(crate) syntax: SyntaxNode,
1204} 1204}
1205impl ast::AttrsOwner for LetStmt {} 1205impl ast::AttrsOwner for LetStmt {}
1206impl ast::TypeAscriptionOwner for LetStmt {}
1207impl LetStmt { 1206impl LetStmt {
1208 pub fn let_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![let]) } 1207 pub fn let_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![let]) }
1209 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } 1208 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) }
1210 pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) } 1209 pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) }
1210 pub fn ty(&self) -> Option<TypeRef> { support::child(&self.syntax) }
1211 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } 1211 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) }
1212 pub fn initializer(&self) -> Option<Expr> { support::child(&self.syntax) } 1212 pub fn initializer(&self) -> Option<Expr> { support::child(&self.syntax) }
1213 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } 1213 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
diff --git a/crates/ra_syntax/src/ast/traits.rs b/crates/ra_syntax/src/ast/traits.rs
index 113bd5d82..3a56b1674 100644
--- a/crates/ra_syntax/src/ast/traits.rs
+++ b/crates/ra_syntax/src/ast/traits.rs
@@ -9,12 +9,6 @@ use crate::{
9 SyntaxToken, T, 9 SyntaxToken, T,
10}; 10};
11 11
12pub trait TypeAscriptionOwner: AstNode {
13 fn ascribed_type(&self) -> Option<ast::TypeRef> {
14 support::child(self.syntax())
15 }
16}
17
18pub trait NameOwner: AstNode { 12pub trait NameOwner: AstNode {
19 fn name(&self) -> Option<ast::Name> { 13 fn name(&self) -> Option<ast::Name> {
20 support::child(self.syntax()) 14 support::child(self.syntax())
diff --git a/xtask/src/codegen/gen_syntax.rs b/xtask/src/codegen/gen_syntax.rs
index e993a750c..45b788bdb 100644
--- a/xtask/src/codegen/gen_syntax.rs
+++ b/xtask/src/codegen/gen_syntax.rs
@@ -660,7 +660,6 @@ fn extract_struct_traits(ast: &mut AstSrc) {
660 ("GenericParamsOwner", &["generic_param_list", "where_clause"]), 660 ("GenericParamsOwner", &["generic_param_list", "where_clause"]),
661 ("TypeBoundsOwner", &["type_bound_list", "colon_token"]), 661 ("TypeBoundsOwner", &["type_bound_list", "colon_token"]),
662 ("ModuleItemOwner", &["items"]), 662 ("ModuleItemOwner", &["items"]),
663 ("TypeAscriptionOwner", &["ascribed_type"]),
664 ("LoopBodyOwner", &["label", "loop_body"]), 663 ("LoopBodyOwner", &["label", "loop_body"]),
665 ("ArgListOwner", &["arg_list"]), 664 ("ArgListOwner", &["arg_list"]),
666 ]; 665 ];
diff --git a/xtask/src/codegen/rust.ungram b/xtask/src/codegen/rust.ungram
index 8c4f953b0..e09bc875a 100644
--- a/xtask/src/codegen/rust.ungram
+++ b/xtask/src/codegen/rust.ungram
@@ -61,13 +61,13 @@ ParamList =
61SelfParam = 61SelfParam =
62 Attr* ( 62 Attr* (
63 ('&' 'lifetime'?)? 'mut'? 'self' 63 ('&' 'lifetime'?)? 'mut'? 'self'
64 | 'mut'? 'self' ':' ascribed_type:TypeRef 64 | 'mut'? 'self' ':' ty:TypeRef
65 ) 65 )
66 66
67Param = 67Param =
68 Attr* ( 68 Attr* (
69 Pat (':' ascribed_type:TypeRef) 69 Pat (':' ty:TypeRef)
70 | ascribed_type:TypeRef 70 | ty:TypeRef
71 | '...' 71 | '...'
72 ) 72 )
73 73
@@ -88,7 +88,7 @@ RecordFieldList =
88 '{' fields:(RecordField (',' RecordField)* ','?)? '}' 88 '{' fields:(RecordField (',' RecordField)* ','?)? '}'
89 89
90RecordField = 90RecordField =
91 Attr* Visibility? Name ':' ascribed_type:TypeRef 91 Attr* Visibility? Name ':' ty:TypeRef
92 92
93TupleFieldList = 93TupleFieldList =
94 '(' fields:(TupleField (',' TupleField)* ','?)? ')' 94 '(' fields:(TupleField (',' TupleField)* ','?)? ')'
@@ -115,11 +115,11 @@ Union =
115 RecordFieldList 115 RecordFieldList
116 116
117Const = 117Const =
118 Attr* Visibility? 'default'? 'const' (Name | '_') ':' ascribed_type:TypeRef 118 Attr* Visibility? 'default'? 'const' (Name | '_') ':' ty:TypeRef
119 '=' body:Expr ';' 119 '=' body:Expr ';'
120 120
121Static = 121Static =
122 Attr* Visibility? 'static'? 'mut'? Name ':' ascribed_type:TypeRef 122 Attr* Visibility? 'static'? 'mut'? Name ':' ty:TypeRef
123 '=' body:Expr ';' 123 '=' body:Expr ';'
124 124
125Trait = 125Trait =
@@ -166,7 +166,7 @@ TypeParam =
166 ('=' default_type:TypeRef)? 166 ('=' default_type:TypeRef)?
167 167
168ConstParam = 168ConstParam =
169 Attr* 'const' Name ':' ascribed_type:TypeRef 169 Attr* 'const' Name ':' ty:TypeRef
170 ('=' default_val:Expr)? 170 ('=' default_val:Expr)?
171 171
172LifetimeParam = 172LifetimeParam =
@@ -439,7 +439,7 @@ ExprStmt =
439 Attr* Expr ';' 439 Attr* Expr ';'
440 440
441LetStmt = 441LetStmt =
442 Attr* 'let' Pat (':' ascribed_type:TypeRef) 442 Attr* 'let' Pat (':' ty:TypeRef)
443 '=' initializer:Expr ';' 443 '=' initializer:Expr ';'
444 444
445Path = 445Path =