diff options
author | Florian Diebold <[email protected]> | 2019-03-17 18:37:09 +0000 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2019-03-21 21:17:00 +0000 |
commit | 8a5fbf471305894094726834f7701747fce9c961 (patch) | |
tree | d210d1a25099ca381bac2f0f2f3247fbd69b366d /crates/ra_ide_api/src | |
parent | 7a8ba535422a4e3d2b649acde75b5c400ef5e7c6 (diff) |
Remove the old variants replaced by Ty::Apply
Diffstat (limited to 'crates/ra_ide_api/src')
-rw-r--r-- | crates/ra_ide_api/src/completion/complete_dot.rs | 27 | ||||
-rw-r--r-- | crates/ra_ide_api/src/completion/complete_struct_literal.rs | 6 | ||||
-rw-r--r-- | crates/ra_ide_api/src/goto_definition.rs | 14 | ||||
-rw-r--r-- | crates/ra_ide_api/src/hover.rs | 17 |
4 files changed, 22 insertions, 42 deletions
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 @@ | |||
1 | use hir::{Ty, AdtDef}; | 1 | use hir::{Ty, AdtDef, TypeName}; |
2 | 2 | ||
3 | use crate::completion::{CompletionContext, Completions}; | 3 | use crate::completion::{CompletionContext, Completions}; |
4 | 4 | ||
@@ -24,23 +24,20 @@ pub(super) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) { | |||
24 | fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) { | 24 | fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) { |
25 | for receiver in receiver.autoderef(ctx.db) { | 25 | for receiver in receiver.autoderef(ctx.db) { |
26 | match receiver { | 26 | match receiver { |
27 | Ty::Adt { def_id, ref substs, .. } => { | 27 | Ty::Apply(a_ty) => match a_ty.name { |
28 | match def_id { | 28 | TypeName::Adt(AdtDef::Struct(s)) => { |
29 | AdtDef::Struct(s) => { | 29 | for field in s.fields(ctx.db) { |
30 | for field in s.fields(ctx.db) { | 30 | acc.add_field(ctx, field, &a_ty.parameters); |
31 | acc.add_field(ctx, field, substs); | ||
32 | } | ||
33 | } | 31 | } |
34 | |||
35 | // TODO unions | ||
36 | AdtDef::Enum(_) => (), | ||
37 | } | 32 | } |
38 | } | 33 | // TODO unions |
39 | Ty::Tuple(fields) => { | 34 | TypeName::Tuple => { |
40 | for (i, ty) in fields.iter().enumerate() { | 35 | for (i, ty) in a_ty.parameters.iter().enumerate() { |
41 | acc.add_pos_field(ctx, i, ty); | 36 | acc.add_pos_field(ctx, i, ty); |
37 | } | ||
42 | } | 38 | } |
43 | } | 39 | _ => {} |
40 | }, | ||
44 | _ => {} | 41 | _ => {} |
45 | }; | 42 | }; |
46 | } | 43 | } |
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 @@ | |||
1 | use hir::{Ty, AdtDef}; | 1 | use hir::AdtDef; |
2 | 2 | ||
3 | use crate::completion::{CompletionContext, Completions}; | 3 | use crate::completion::{CompletionContext, Completions}; |
4 | 4 | ||
@@ -15,8 +15,8 @@ pub(super) fn complete_struct_literal(acc: &mut Completions, ctx: &CompletionCon | |||
15 | None => return, | 15 | None => return, |
16 | }; | 16 | }; |
17 | let ty = infer_result[expr].clone(); | 17 | let ty = infer_result[expr].clone(); |
18 | let (adt, substs) = match ty { | 18 | let (adt, substs) = match ty.as_adt() { |
19 | Ty::Adt { def_id, ref substs, .. } => (def_id, substs), | 19 | Some(res) => res, |
20 | _ => return, | 20 | _ => return, |
21 | }; | 21 | }; |
22 | match adt { | 22 | 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( | |||
87 | 87 | ||
88 | if let Some(expr) = struct_lit.and_then(|lit| source_map.node_expr(lit.into())) { | 88 | if let Some(expr) = struct_lit.and_then(|lit| source_map.node_expr(lit.into())) { |
89 | let ty = infer_result[expr].clone(); | 89 | let ty = infer_result[expr].clone(); |
90 | if let hir::Ty::Adt { def_id, .. } = ty { | 90 | if let Some((hir::AdtDef::Struct(s), _)) = ty.as_adt() { |
91 | if let hir::AdtDef::Struct(s) = def_id { | 91 | let hir_path = hir::Path::from_name_ref(name_ref); |
92 | let hir_path = hir::Path::from_name_ref(name_ref); | 92 | let hir_name = hir_path.as_ident().unwrap(); |
93 | let hir_name = hir_path.as_ident().unwrap(); | ||
94 | 93 | ||
95 | if let Some(field) = s.field(db, hir_name) { | 94 | if let Some(field) = s.field(db, hir_name) { |
96 | return Exact(NavigationTarget::from_field(db, field)); | 95 | return Exact(NavigationTarget::from_field(db, field)); |
97 | } | ||
98 | } | 96 | } |
99 | } | 97 | } |
100 | } | 98 | } |
@@ -124,7 +122,7 @@ pub(crate) fn reference_definition( | |||
124 | Some(Resolution::SelfType(impl_block)) => { | 122 | Some(Resolution::SelfType(impl_block)) => { |
125 | let ty = impl_block.target_ty(db); | 123 | let ty = impl_block.target_ty(db); |
126 | 124 | ||
127 | if let hir::Ty::Adt { def_id, .. } = ty { | 125 | if let Some((def_id, _)) = ty.as_adt() { |
128 | return Exact(NavigationTarget::from_adt_def(db, def_id)); | 126 | return Exact(NavigationTarget::from_adt_def(db, def_id)); |
129 | } | 127 | } |
130 | } | 128 | } |
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 | |||
517 | assert_eq!("u32", &type_name); | 517 | assert_eq!("u32", &type_name); |
518 | } | 518 | } |
519 | 519 | ||
520 | // FIXME: improve type_of to make this work | ||
521 | #[test] | 520 | #[test] |
522 | fn test_type_of_for_expr_1() { | 521 | fn test_type_of_for_expr() { |
523 | let (analysis, range) = single_file_with_range( | ||
524 | " | ||
525 | fn main() { | ||
526 | let foo = <|>1 + foo_test<|>; | ||
527 | } | ||
528 | ", | ||
529 | ); | ||
530 | |||
531 | let type_name = analysis.type_of(range).unwrap().unwrap(); | ||
532 | assert_eq!("{unknown}", &type_name); | ||
533 | } | ||
534 | |||
535 | #[test] | ||
536 | fn test_type_of_for_expr_2() { | ||
537 | let (analysis, range) = single_file_with_range( | 522 | let (analysis, range) = single_file_with_range( |
538 | " | 523 | " |
539 | fn main() { | 524 | fn main() { |