From 8a5fbf471305894094726834f7701747fce9c961 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sun, 17 Mar 2019 19:37:09 +0100 Subject: Remove the old variants replaced by Ty::Apply --- crates/ra_ide_api/src/completion/complete_dot.rs | 27 ++++++++++------------ .../src/completion/complete_struct_literal.rs | 6 ++--- crates/ra_ide_api/src/goto_definition.rs | 14 +++++------ crates/ra_ide_api/src/hover.rs | 17 +------------- 4 files changed, 22 insertions(+), 42 deletions(-) (limited to 'crates/ra_ide_api/src') diff --git a/crates/ra_ide_api/src/completion/complete_dot.rs b/crates/ra_ide_api/src/completion/complete_dot.rs index 94c66be31..dc5206a64 100644 --- a/crates/ra_ide_api/src/completion/complete_dot.rs +++ b/crates/ra_ide_api/src/completion/complete_dot.rs @@ -1,4 +1,4 @@ -use hir::{Ty, AdtDef}; +use hir::{Ty, AdtDef, TypeName}; use crate::completion::{CompletionContext, Completions}; @@ -24,23 +24,20 @@ pub(super) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) { fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) { for receiver in receiver.autoderef(ctx.db) { match receiver { - Ty::Adt { def_id, ref substs, .. } => { - match def_id { - AdtDef::Struct(s) => { - for field in s.fields(ctx.db) { - acc.add_field(ctx, field, substs); - } + Ty::Apply(a_ty) => match a_ty.name { + TypeName::Adt(AdtDef::Struct(s)) => { + for field in s.fields(ctx.db) { + acc.add_field(ctx, field, &a_ty.parameters); } - - // TODO unions - AdtDef::Enum(_) => (), } - } - Ty::Tuple(fields) => { - for (i, ty) in fields.iter().enumerate() { - acc.add_pos_field(ctx, i, ty); + // TODO unions + TypeName::Tuple => { + for (i, ty) in a_ty.parameters.iter().enumerate() { + acc.add_pos_field(ctx, i, ty); + } } - } + _ => {} + }, _ => {} }; } diff --git a/crates/ra_ide_api/src/completion/complete_struct_literal.rs b/crates/ra_ide_api/src/completion/complete_struct_literal.rs index 6bef9624e..b75526282 100644 --- a/crates/ra_ide_api/src/completion/complete_struct_literal.rs +++ b/crates/ra_ide_api/src/completion/complete_struct_literal.rs @@ -1,4 +1,4 @@ -use hir::{Ty, AdtDef}; +use hir::AdtDef; use crate::completion::{CompletionContext, Completions}; @@ -15,8 +15,8 @@ pub(super) fn complete_struct_literal(acc: &mut Completions, ctx: &CompletionCon None => return, }; let ty = infer_result[expr].clone(); - let (adt, substs) = match ty { - Ty::Adt { def_id, ref substs, .. } => (def_id, substs), + let (adt, substs) = match ty.as_adt() { + Some(res) => res, _ => return, }; match adt { diff --git a/crates/ra_ide_api/src/goto_definition.rs b/crates/ra_ide_api/src/goto_definition.rs index d4e10b69c..f94487d94 100644 --- a/crates/ra_ide_api/src/goto_definition.rs +++ b/crates/ra_ide_api/src/goto_definition.rs @@ -87,14 +87,12 @@ pub(crate) fn reference_definition( if let Some(expr) = struct_lit.and_then(|lit| source_map.node_expr(lit.into())) { let ty = infer_result[expr].clone(); - if let hir::Ty::Adt { def_id, .. } = ty { - if let hir::AdtDef::Struct(s) = def_id { - let hir_path = hir::Path::from_name_ref(name_ref); - let hir_name = hir_path.as_ident().unwrap(); + if let Some((hir::AdtDef::Struct(s), _)) = ty.as_adt() { + let hir_path = hir::Path::from_name_ref(name_ref); + let hir_name = hir_path.as_ident().unwrap(); - if let Some(field) = s.field(db, hir_name) { - return Exact(NavigationTarget::from_field(db, field)); - } + if let Some(field) = s.field(db, hir_name) { + return Exact(NavigationTarget::from_field(db, field)); } } } @@ -124,7 +122,7 @@ pub(crate) fn reference_definition( Some(Resolution::SelfType(impl_block)) => { let ty = impl_block.target_ty(db); - if let hir::Ty::Adt { def_id, .. } = ty { + if let Some((def_id, _)) = ty.as_adt() { return Exact(NavigationTarget::from_adt_def(db, def_id)); } } diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs index f6a83dd93..f6443580d 100644 --- a/crates/ra_ide_api/src/hover.rs +++ b/crates/ra_ide_api/src/hover.rs @@ -517,23 +517,8 @@ The Some variant assert_eq!("u32", &type_name); } - // FIXME: improve type_of to make this work #[test] - fn test_type_of_for_expr_1() { - let (analysis, range) = single_file_with_range( - " - fn main() { - let foo = <|>1 + foo_test<|>; - } - ", - ); - - let type_name = analysis.type_of(range).unwrap().unwrap(); - assert_eq!("{unknown}", &type_name); - } - - #[test] - fn test_type_of_for_expr_2() { + fn test_type_of_for_expr() { let (analysis, range) = single_file_with_range( " fn main() { -- cgit v1.2.3