From c5798c4d75aa807aec47208a49101bdec3affcca Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 18:28:28 +0200 Subject: Finalize impl Grammar --- crates/ra_assists/src/ast_transform.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'crates/ra_assists/src/ast_transform.rs') diff --git a/crates/ra_assists/src/ast_transform.rs b/crates/ra_assists/src/ast_transform.rs index 01adb834c..5ea4f9f5b 100644 --- a/crates/ra_assists/src/ast_transform.rs +++ b/crates/ra_assists/src/ast_transform.rs @@ -41,7 +41,7 @@ impl<'a> SubstituteTypeParams<'a> { source_scope: &'a SemanticsScope<'a>, // FIXME: there's implicit invariant that `trait_` and `source_scope` match... trait_: hir::Trait, - impl_def: ast::ImplDef, + impl_def: ast::Impl, ) -> SubstituteTypeParams<'a> { let substs = get_syntactic_substs(impl_def).unwrap_or_default(); let generic_def: hir::GenericDef = trait_.into(); @@ -80,7 +80,7 @@ impl<'a> SubstituteTypeParams<'a> { // FIXME: It would probably be nicer if we could get this via HIR (i.e. get the // trait ref, and then go from the types in the substs back to the syntax) - fn get_syntactic_substs(impl_def: ast::ImplDef) -> Option> { + fn get_syntactic_substs(impl_def: ast::Impl) -> Option> { let target_trait = impl_def.target_trait()?; let path_type = match target_trait { ast::TypeRef::PathType(path) => path, -- 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_assists/src/ast_transform.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'crates/ra_assists/src/ast_transform.rs') diff --git a/crates/ra_assists/src/ast_transform.rs b/crates/ra_assists/src/ast_transform.rs index 5ea4f9f5b..3265bd406 100644 --- a/crates/ra_assists/src/ast_transform.rs +++ b/crates/ra_assists/src/ast_transform.rs @@ -32,7 +32,7 @@ impl<'a> AstTransform<'a> for NullTransformer { pub struct SubstituteTypeParams<'a> { source_scope: &'a SemanticsScope<'a>, - substs: FxHashMap, + substs: FxHashMap, previous: Box + 'a>, } @@ -80,17 +80,17 @@ impl<'a> SubstituteTypeParams<'a> { // FIXME: It would probably be nicer if we could get this via HIR (i.e. get the // trait ref, and then go from the types in the substs back to the syntax) - fn get_syntactic_substs(impl_def: ast::Impl) -> Option> { + fn get_syntactic_substs(impl_def: ast::Impl) -> Option> { let target_trait = impl_def.target_trait()?; let path_type = match target_trait { - ast::TypeRef::PathType(path) => path, + ast::Type::PathType(path) => path, _ => return None, }; let type_arg_list = path_type.path()?.segment()?.type_arg_list()?; let mut result = Vec::new(); for type_arg in type_arg_list.type_args() { let type_arg: ast::TypeArg = type_arg; - result.push(type_arg.type_ref()?); + result.push(type_arg.ty()?); } Some(result) } @@ -99,9 +99,9 @@ impl<'a> SubstituteTypeParams<'a> { &self, node: &ra_syntax::SyntaxNode, ) -> Option { - let type_ref = ast::TypeRef::cast(node.clone())?; + let type_ref = ast::Type::cast(node.clone())?; let path = match &type_ref { - ast::TypeRef::PathType(path_type) => path_type.path()?, + ast::Type::PathType(path_type) => path_type.path()?, _ => return None, }; // FIXME: use `hir::Path::from_src` instead. -- 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_assists/src/ast_transform.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'crates/ra_assists/src/ast_transform.rs') diff --git a/crates/ra_assists/src/ast_transform.rs b/crates/ra_assists/src/ast_transform.rs index 3265bd406..e23331773 100644 --- a/crates/ra_assists/src/ast_transform.rs +++ b/crates/ra_assists/src/ast_transform.rs @@ -86,7 +86,7 @@ impl<'a> SubstituteTypeParams<'a> { ast::Type::PathType(path) => path, _ => return None, }; - let type_arg_list = path_type.path()?.segment()?.type_arg_list()?; + let type_arg_list = path_type.path()?.segment()?.generic_arg_list()?; let mut result = Vec::new(); for type_arg in type_arg_list.type_args() { let type_arg: ast::TypeArg = type_arg; @@ -157,7 +157,7 @@ impl<'a> QualifyPaths<'a> { let type_args = p .segment() - .and_then(|s| s.type_arg_list()) + .and_then(|s| s.generic_arg_list()) .map(|arg_list| apply(self, arg_list)); if let Some(type_args) = type_args { let last_segment = path.segment().unwrap(); -- 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_assists/src/ast_transform.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'crates/ra_assists/src/ast_transform.rs') diff --git a/crates/ra_assists/src/ast_transform.rs b/crates/ra_assists/src/ast_transform.rs index e23331773..0a7be87a0 100644 --- a/crates/ra_assists/src/ast_transform.rs +++ b/crates/ra_assists/src/ast_transform.rs @@ -79,19 +79,25 @@ impl<'a> SubstituteTypeParams<'a> { }; // FIXME: It would probably be nicer if we could get this via HIR (i.e. get the - // trait ref, and then go from the types in the substs back to the syntax) + // trait ref, and then go from the types in the substs back to the syntax). fn get_syntactic_substs(impl_def: ast::Impl) -> Option> { let target_trait = impl_def.target_trait()?; let path_type = match target_trait { ast::Type::PathType(path) => path, _ => return None, }; - let type_arg_list = path_type.path()?.segment()?.generic_arg_list()?; + let generic_arg_list = path_type.path()?.segment()?.generic_arg_list()?; + let mut result = Vec::new(); - for type_arg in type_arg_list.type_args() { - let type_arg: ast::TypeArg = type_arg; - result.push(type_arg.ty()?); + for generic_arg in generic_arg_list.generic_args() { + match generic_arg { + ast::GenericArg::TypeArg(type_arg) => result.push(type_arg.ty()?), + ast::GenericArg::AssocTypeArg(_) + | ast::GenericArg::LifetimeArg(_) + | ast::GenericArg::ConstArg(_) => (), + } } + Some(result) } } -- cgit v1.2.3 From af53d5f4b081ad50d8fe08fc1e107aa6025b2491 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 31 Jul 2020 20:23:52 +0200 Subject: Rename --- crates/ra_assists/src/ast_transform.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ra_assists/src/ast_transform.rs') diff --git a/crates/ra_assists/src/ast_transform.rs b/crates/ra_assists/src/ast_transform.rs index 0a7be87a0..28f3f3546 100644 --- a/crates/ra_assists/src/ast_transform.rs +++ b/crates/ra_assists/src/ast_transform.rs @@ -81,7 +81,7 @@ impl<'a> SubstituteTypeParams<'a> { // FIXME: It would probably be nicer if we could get this via HIR (i.e. get the // trait ref, and then go from the types in the substs back to the syntax). fn get_syntactic_substs(impl_def: ast::Impl) -> Option> { - let target_trait = impl_def.target_trait()?; + let target_trait = impl_def.trait_()?; let path_type = match target_trait { ast::Type::PathType(path) => path, _ => return None, -- cgit v1.2.3 From 09d3b7d7a2ae23a0463fadee9ae8cb6a0fa2c4bf Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 5 Aug 2020 19:29:24 +0200 Subject: align names in make --- crates/ra_assists/src/ast_transform.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ra_assists/src/ast_transform.rs') diff --git a/crates/ra_assists/src/ast_transform.rs b/crates/ra_assists/src/ast_transform.rs index 28f3f3546..15ec75c95 100644 --- a/crates/ra_assists/src/ast_transform.rs +++ b/crates/ra_assists/src/ast_transform.rs @@ -63,7 +63,7 @@ impl<'a> SubstituteTypeParams<'a> { let default = k.default(source_scope.db)?; Some(( k, - ast::make::type_ref( + ast::make::ty( &default .display_source_code(source_scope.db, source_scope.module()?.into()) .ok()?, -- cgit v1.2.3