From 2e2642efccd5855e4158b01a006e7884a96982bb Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 20:51:43 +0200 Subject: Remove TypeAscriptionOwner --- crates/ra_hir_def/src/path/lower.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'crates/ra_hir_def/src/path/lower.rs') 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::{ hygiene::Hygiene, name::{name, AsName}, }; -use ra_syntax::ast::{self, AstNode, TypeAscriptionOwner, TypeBoundsOwner}; +use ra_syntax::ast::{self, AstNode, TypeBoundsOwner}; use super::AssociatedTypeBinding; use crate::{ @@ -189,7 +189,7 @@ fn lower_generic_args_from_fn_path( if let Some(params) = params { let mut param_types = Vec::new(); for param in params.params() { - let type_ref = TypeRef::from_ast_opt(&ctx, param.ascribed_type()); + let type_ref = TypeRef::from_ast_opt(&ctx, param.ty()); param_types.push(type_ref); } let arg = GenericArg::Type(TypeRef::Tuple(param_types)); -- cgit v1.2.3 From f95f425ae4199e814e6956be1d9bb59a14758c07 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 21:02:55 +0200 Subject: Use ty to access most TypeRefs --- crates/ra_hir_def/src/path/lower.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ra_hir_def/src/path/lower.rs') diff --git a/crates/ra_hir_def/src/path/lower.rs b/crates/ra_hir_def/src/path/lower.rs index dfab15948..07d17916a 100644 --- a/crates/ra_hir_def/src/path/lower.rs +++ b/crates/ra_hir_def/src/path/lower.rs @@ -196,7 +196,7 @@ fn lower_generic_args_from_fn_path( args.push(arg); } if let Some(ret_type) = ret_type { - let type_ref = TypeRef::from_ast_opt(&ctx, ret_type.type_ref()); + let type_ref = TypeRef::from_ast_opt(&ctx, ret_type.ty()); bindings.push(AssociatedTypeBinding { name: name![Output], type_ref: Some(type_ref), -- cgit v1.2.3 From 08ea2271e8050165d0aaf4c994ed3dd746aff3ba Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 31 Jul 2020 12:06:38 +0200 Subject: Rename TypeRef -> Type The TypeRef name comes from IntelliJ days, where you often have both type *syntax* as well as *semantical* representation of types in scope. And naming both Type is confusing. In rust-analyzer however, we use ast types as `ast::Type`, and have many more semantic counterparts to ast types, so avoiding name clash here is just confusing. --- crates/ra_hir_def/src/path/lower.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'crates/ra_hir_def/src/path/lower.rs') diff --git a/crates/ra_hir_def/src/path/lower.rs b/crates/ra_hir_def/src/path/lower.rs index 07d17916a..257f9a033 100644 --- a/crates/ra_hir_def/src/path/lower.rs +++ b/crates/ra_hir_def/src/path/lower.rs @@ -152,7 +152,7 @@ pub(super) fn lower_generic_args( ) -> Option { let mut args = Vec::new(); for type_arg in node.type_args() { - let type_ref = TypeRef::from_ast_opt(lower_ctx, type_arg.type_ref()); + let type_ref = TypeRef::from_ast_opt(lower_ctx, type_arg.ty()); args.push(GenericArg::Type(type_ref)); } // lifetimes ignored for now @@ -161,7 +161,7 @@ pub(super) fn lower_generic_args( let assoc_type_arg: ast::AssocTypeArg = assoc_type_arg; if let Some(name_ref) = assoc_type_arg.name_ref() { let name = name_ref.as_name(); - let type_ref = assoc_type_arg.type_ref().map(|it| TypeRef::from_ast(lower_ctx, it)); + let type_ref = assoc_type_arg.ty().map(|it| TypeRef::from_ast(lower_ctx, it)); let bounds = if let Some(l) = assoc_type_arg.type_bound_list() { l.bounds().map(|it| TypeBound::from_ast(lower_ctx, it)).collect() } else { -- cgit v1.2.3 From 91781c7ce8201b28afd56b4e35eba47e076a8498 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 31 Jul 2020 18:29:29 +0200 Subject: Rename TypeArgList -> GenericArgList --- crates/ra_hir_def/src/path/lower.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'crates/ra_hir_def/src/path/lower.rs') diff --git a/crates/ra_hir_def/src/path/lower.rs b/crates/ra_hir_def/src/path/lower.rs index 257f9a033..aefeca400 100644 --- a/crates/ra_hir_def/src/path/lower.rs +++ b/crates/ra_hir_def/src/path/lower.rs @@ -41,7 +41,7 @@ pub(super) fn lower_path(mut path: ast::Path, hygiene: &Hygiene) -> Option match hygiene.name_ref_to_name(name_ref) { Either::Left(name) => { let args = segment - .type_arg_list() + .generic_arg_list() .and_then(|it| lower_generic_args(&ctx, it)) .or_else(|| { lower_generic_args_from_fn_path( @@ -148,7 +148,7 @@ pub(super) fn lower_path(mut path: ast::Path, hygiene: &Hygiene) -> Option pub(super) fn lower_generic_args( lower_ctx: &LowerCtx, - node: ast::TypeArgList, + node: ast::GenericArgList, ) -> Option { let mut args = Vec::new(); for type_arg in node.type_args() { -- cgit v1.2.3 From 040b4c800d5279e77a6825fc90cb2921d26c7f95 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 31 Jul 2020 18:41:37 +0200 Subject: Fix GenericArgs grammar --- crates/ra_hir_def/src/path/lower.rs | 42 ++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 19 deletions(-) (limited to 'crates/ra_hir_def/src/path/lower.rs') diff --git a/crates/ra_hir_def/src/path/lower.rs b/crates/ra_hir_def/src/path/lower.rs index aefeca400..d09fc66e4 100644 --- a/crates/ra_hir_def/src/path/lower.rs +++ b/crates/ra_hir_def/src/path/lower.rs @@ -151,30 +151,34 @@ pub(super) fn lower_generic_args( node: ast::GenericArgList, ) -> Option { let mut args = Vec::new(); - for type_arg in node.type_args() { - let type_ref = TypeRef::from_ast_opt(lower_ctx, type_arg.ty()); - args.push(GenericArg::Type(type_ref)); - } - // lifetimes ignored for now let mut bindings = Vec::new(); - for assoc_type_arg in node.assoc_type_args() { - let assoc_type_arg: ast::AssocTypeArg = assoc_type_arg; - if let Some(name_ref) = assoc_type_arg.name_ref() { - let name = name_ref.as_name(); - let type_ref = assoc_type_arg.ty().map(|it| TypeRef::from_ast(lower_ctx, it)); - let bounds = if let Some(l) = assoc_type_arg.type_bound_list() { - l.bounds().map(|it| TypeBound::from_ast(lower_ctx, it)).collect() - } else { - Vec::new() - }; - bindings.push(AssociatedTypeBinding { name, type_ref, bounds }); + for generic_arg in node.generic_args() { + match generic_arg { + ast::GenericArg::TypeArg(type_arg) => { + let type_ref = TypeRef::from_ast_opt(lower_ctx, type_arg.ty()); + args.push(GenericArg::Type(type_ref)); + } + ast::GenericArg::AssocTypeArg(assoc_type_arg) => { + if let Some(name_ref) = assoc_type_arg.name_ref() { + let name = name_ref.as_name(); + let type_ref = assoc_type_arg.ty().map(|it| TypeRef::from_ast(lower_ctx, it)); + let bounds = if let Some(l) = assoc_type_arg.type_bound_list() { + l.bounds().map(|it| TypeBound::from_ast(lower_ctx, it)).collect() + } else { + Vec::new() + }; + bindings.push(AssociatedTypeBinding { name, type_ref, bounds }); + } + } + // Lifetimes and constants are ignored for now. + ast::GenericArg::LifetimeArg(_) | ast::GenericArg::ConstArg(_) => (), } } + if args.is_empty() && bindings.is_empty() { - None - } else { - Some(GenericArgs { args, has_self_type: false, bindings }) + return None; } + Some(GenericArgs { args, has_self_type: false, bindings }) } /// Collect `GenericArgs` from the parts of a fn-like path, i.e. `Fn(X, Y) -- cgit v1.2.3