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/generics.rs | 2 +- crates/ra_hir_def/src/item_tree/lower.rs | 4 ++-- crates/ra_hir_def/src/path/lower.rs | 4 ++-- crates/ra_hir_def/src/type_ref.rs | 30 +++++++++++++++--------------- 4 files changed, 20 insertions(+), 20 deletions(-) (limited to 'crates/ra_hir_def') diff --git a/crates/ra_hir_def/src/generics.rs b/crates/ra_hir_def/src/generics.rs index 8ea61fcf2..be0b45af3 100644 --- a/crates/ra_hir_def/src/generics.rs +++ b/crates/ra_hir_def/src/generics.rs @@ -253,7 +253,7 @@ impl GenericParams { fn fill_where_predicates(&mut self, lower_ctx: &LowerCtx, where_clause: ast::WhereClause) { for pred in where_clause.predicates() { - let type_ref = match pred.type_ref() { + let type_ref = match pred.ty() { Some(type_ref) => type_ref, None => continue, }; diff --git a/crates/ra_hir_def/src/item_tree/lower.rs b/crates/ra_hir_def/src/item_tree/lower.rs index feb31579e..b5d416acb 100644 --- a/crates/ra_hir_def/src/item_tree/lower.rs +++ b/crates/ra_hir_def/src/item_tree/lower.rs @@ -648,10 +648,10 @@ impl Ctx { self.data().vis.alloc(vis) } - fn lower_type_ref(&self, type_ref: &ast::TypeRef) -> TypeRef { + fn lower_type_ref(&self, type_ref: &ast::Type) -> TypeRef { TypeRef::from_ast(&self.body_ctx, type_ref.clone()) } - fn lower_type_ref_opt(&self, type_ref: Option) -> TypeRef { + fn lower_type_ref_opt(&self, type_ref: Option) -> TypeRef { type_ref.map(|ty| self.lower_type_ref(&ty)).unwrap_or(TypeRef::Error) } 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 { diff --git a/crates/ra_hir_def/src/type_ref.rs b/crates/ra_hir_def/src/type_ref.rs index a5dc10eac..9386b91cb 100644 --- a/crates/ra_hir_def/src/type_ref.rs +++ b/crates/ra_hir_def/src/type_ref.rs @@ -80,14 +80,14 @@ pub enum TypeBound { impl TypeRef { /// Converts an `ast::TypeRef` to a `hir::TypeRef`. - pub(crate) fn from_ast(ctx: &LowerCtx, node: ast::TypeRef) -> Self { + pub(crate) fn from_ast(ctx: &LowerCtx, node: ast::Type) -> Self { match node { - ast::TypeRef::ParenType(inner) => TypeRef::from_ast_opt(&ctx, inner.ty()), - ast::TypeRef::TupleType(inner) => { + ast::Type::ParenType(inner) => TypeRef::from_ast_opt(&ctx, inner.ty()), + ast::Type::TupleType(inner) => { TypeRef::Tuple(inner.fields().map(|it| TypeRef::from_ast(ctx, it)).collect()) } - ast::TypeRef::NeverType(..) => TypeRef::Never, - ast::TypeRef::PathType(inner) => { + ast::Type::NeverType(..) => TypeRef::Never, + ast::Type::PathType(inner) => { // FIXME: Use `Path::from_src` inner .path() @@ -95,24 +95,24 @@ impl TypeRef { .map(TypeRef::Path) .unwrap_or(TypeRef::Error) } - ast::TypeRef::PointerType(inner) => { + ast::Type::PointerType(inner) => { let inner_ty = TypeRef::from_ast_opt(&ctx, inner.ty()); let mutability = Mutability::from_mutable(inner.mut_token().is_some()); TypeRef::RawPtr(Box::new(inner_ty), mutability) } - ast::TypeRef::ArrayType(inner) => { + ast::Type::ArrayType(inner) => { TypeRef::Array(Box::new(TypeRef::from_ast_opt(&ctx, inner.ty()))) } - ast::TypeRef::SliceType(inner) => { + ast::Type::SliceType(inner) => { TypeRef::Slice(Box::new(TypeRef::from_ast_opt(&ctx, inner.ty()))) } - ast::TypeRef::ReferenceType(inner) => { + ast::Type::ReferenceType(inner) => { let inner_ty = TypeRef::from_ast_opt(&ctx, inner.ty()); let mutability = Mutability::from_mutable(inner.mut_token().is_some()); TypeRef::Reference(Box::new(inner_ty), mutability) } - ast::TypeRef::PlaceholderType(_inner) => TypeRef::Placeholder, - ast::TypeRef::FnPointerType(inner) => { + ast::Type::PlaceholderType(_inner) => TypeRef::Placeholder, + ast::Type::FnPointerType(inner) => { let ret_ty = inner .ret_type() .and_then(|rt| rt.ty()) @@ -132,17 +132,17 @@ impl TypeRef { TypeRef::Fn(params, is_varargs) } // for types are close enough for our purposes to the inner type for now... - ast::TypeRef::ForType(inner) => TypeRef::from_ast_opt(&ctx, inner.ty()), - ast::TypeRef::ImplTraitType(inner) => { + ast::Type::ForType(inner) => TypeRef::from_ast_opt(&ctx, inner.ty()), + ast::Type::ImplTraitType(inner) => { TypeRef::ImplTrait(type_bounds_from_ast(ctx, inner.type_bound_list())) } - ast::TypeRef::DynTraitType(inner) => { + ast::Type::DynTraitType(inner) => { TypeRef::DynTrait(type_bounds_from_ast(ctx, inner.type_bound_list())) } } } - pub(crate) fn from_ast_opt(ctx: &LowerCtx, node: Option) -> Self { + pub(crate) fn from_ast_opt(ctx: &LowerCtx, node: Option) -> Self { if let Some(node) = node { TypeRef::from_ast(ctx, node) } else { -- cgit v1.2.3