From cb3ef552e873a86e94a3792160fadb5d937a6f5f Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 30 Apr 2021 11:52:31 +0300 Subject: internal: normalize name All def types in hir are unsubstituted --- crates/hir/src/display.rs | 2 +- crates/hir/src/lib.rs | 2 +- crates/ide_assists/src/handlers/generate_from_impl_for_enum.rs | 2 +- crates/ide_completion/src/context.rs | 4 ++-- crates/ide_completion/src/render/enum_variant.rs | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) (limited to 'crates') diff --git a/crates/hir/src/display.rs b/crates/hir/src/display.rs index 01a4d205f..508ac37c2 100644 --- a/crates/hir/src/display.rs +++ b/crates/hir/src/display.rs @@ -170,7 +170,7 @@ impl HirDisplay for Field { fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { write_visibility(self.parent.module(f.db).id, self.visibility(f.db), f)?; write!(f, "{}: ", self.name(f.db))?; - self.signature_ty(f.db).hir_fmt(f) + self.ty(f.db).hir_fmt(f) } } diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index 0acfa582a..9eb7672da 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -509,7 +509,7 @@ impl Field { /// placeholder types for type parameters). This is good for showing /// signature help, but not so good to actually get the type of the field /// when you actually have a variable of the struct. - pub fn signature_ty(&self, db: &dyn HirDatabase) -> Type { + pub fn ty(&self, db: &dyn HirDatabase) -> Type { let var_id = self.parent.into(); let generic_def_id: GenericDefId = match self.parent { VariantDef::Struct(it) => it.id.into(), diff --git a/crates/ide_assists/src/handlers/generate_from_impl_for_enum.rs b/crates/ide_assists/src/handlers/generate_from_impl_for_enum.rs index c13c6eebe..ce6998d82 100644 --- a/crates/ide_assists/src/handlers/generate_from_impl_for_enum.rs +++ b/crates/ide_assists/src/handlers/generate_from_impl_for_enum.rs @@ -91,7 +91,7 @@ fn existing_from_impl( let enum_type = enum_.ty(sema.db); - let wrapped_type = variant.fields(sema.db).get(0)?.signature_ty(sema.db); + let wrapped_type = variant.fields(sema.db).get(0)?.ty(sema.db); if enum_type.impls_trait(sema.db, from_trait, &[wrapped_type]) { Some(()) diff --git a/crates/ide_completion/src/context.rs b/crates/ide_completion/src/context.rs index 32f81aec1..b005bd773 100644 --- a/crates/ide_completion/src/context.rs +++ b/crates/ide_completion/src/context.rs @@ -347,7 +347,7 @@ impl<'a> CompletionContext<'a> { .and_then(|node| ast::RecordExprField::cast(node)) .and_then(|rf| self.sema.resolve_record_field(&rf).zip(Some(rf))) .map(|(f, rf)|( - Some(f.0.signature_ty(self.db)), + Some(f.0.ty(self.db)), rf.field_name().map(NameOrNameRef::NameRef), )) .unwrap_or((None, None)) @@ -357,7 +357,7 @@ impl<'a> CompletionContext<'a> { self.sema .resolve_record_field(&it) .map(|f|( - Some(f.0.signature_ty(self.db)), + Some(f.0.ty(self.db)), it.field_name().map(NameOrNameRef::NameRef), )) .unwrap_or((None, None)) diff --git a/crates/ide_completion/src/render/enum_variant.rs b/crates/ide_completion/src/render/enum_variant.rs index 832f5ced1..0c0c71134 100644 --- a/crates/ide_completion/src/render/enum_variant.rs +++ b/crates/ide_completion/src/render/enum_variant.rs @@ -93,7 +93,7 @@ impl<'a> EnumRender<'a> { .variant .fields(self.ctx.db()) .into_iter() - .map(|field| (field.name(self.ctx.db()), field.signature_ty(self.ctx.db()))); + .map(|field| (field.name(self.ctx.db()), field.ty(self.ctx.db()))); match self.variant_kind { StructKind::Tuple | StructKind::Unit => format!( -- cgit v1.2.3 From 1a01a5ae190ad02e44c3550ac0336b1f0983be51 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 30 Apr 2021 11:55:59 +0300 Subject: internal: fix naming polarity Type Constructors have *parameters*, when they are substituted with type *arguments*, we have a type. --- crates/hir/src/lib.rs | 2 +- crates/ide/src/runnables.rs | 6 +++--- crates/ide_assists/src/handlers/extract_function.rs | 2 +- crates/ide_assists/src/utils/suggest_name.rs | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) (limited to 'crates') diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index 9eb7672da..d8ccfde0c 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -1984,7 +1984,7 @@ impl Type { None } - pub fn type_parameters(&self) -> impl Iterator + '_ { + pub fn type_arguments(&self) -> impl Iterator + '_ { self.ty .strip_references() .as_adt() diff --git a/crates/ide/src/runnables.rs b/crates/ide/src/runnables.rs index 3eb9e27ee..f76715d84 100644 --- a/crates/ide/src/runnables.rs +++ b/crates/ide/src/runnables.rs @@ -304,11 +304,11 @@ fn module_def_doctest(sema: &Semantics, def: hir::ModuleDef) -> Op let name = adt.name(sema.db); let idx = path.rfind(':').map_or(0, |idx| idx + 1); let (prefix, suffix) = path.split_at(idx); - let mut ty_params = ty.type_parameters().peekable(); - let params = if ty_params.peek().is_some() { + let mut ty_args = ty.type_arguments().peekable(); + let params = if ty_args.peek().is_some() { format!( "<{}>", - ty_params.format_with(", ", |ty, cb| cb(&ty.display(sema.db))) + ty_args.format_with(", ", |ty, cb| cb(&ty.display(sema.db))) ) } else { String::new() diff --git a/crates/ide_assists/src/handlers/extract_function.rs b/crates/ide_assists/src/handlers/extract_function.rs index 5f80a40c8..b30652a9d 100644 --- a/crates/ide_assists/src/handlers/extract_function.rs +++ b/crates/ide_assists/src/handlers/extract_function.rs @@ -1183,7 +1183,7 @@ fn make_ret_ty(ctx: &AssistContext, module: hir::Module, fun: &Function) -> Opti } FlowHandler::Try { kind: TryKind::Result { ty: parent_ret_ty } } => { let handler_ty = parent_ret_ty - .type_parameters() + .type_arguments() .nth(1) .map(|ty| make_ty(&ty, ctx, module)) .unwrap_or_else(make::ty_unit); diff --git a/crates/ide_assists/src/utils/suggest_name.rs b/crates/ide_assists/src/utils/suggest_name.rs index 533624c1f..deafcd630 100644 --- a/crates/ide_assists/src/utils/suggest_name.rs +++ b/crates/ide_assists/src/utils/suggest_name.rs @@ -227,7 +227,7 @@ fn name_of_type(ty: &hir::Type, db: &RootDatabase) -> Option { let name = adt.name(db).to_string(); if WRAPPER_TYPES.contains(&name.as_str()) { - let inner_ty = ty.type_parameters().next()?; + let inner_ty = ty.type_arguments().next()?; return name_of_type(&inner_ty, db); } -- cgit v1.2.3