aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-11-26 18:42:52 +0000
committerGitHub <[email protected]>2019-11-26 18:42:52 +0000
commitd770f22c53a88035e2836cc01533dab4223f80d5 (patch)
tree186c1272704f589a67837b82823c31e91234f52b /crates
parent3206b83a70b4e9140a5f0d9d8454abb7864b543a (diff)
parent936c6950e78d073f54c9ba66795f7f6f3abb351b (diff)
Merge #2420
2420: Remove last traces of adt from Ty r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_hir/src/code_model.rs4
-rw-r--r--crates/ra_hir/src/expr.rs4
-rw-r--r--crates/ra_hir/src/ty.rs7
-rw-r--r--crates/ra_ide_api/src/goto_definition.rs23
-rw-r--r--crates/ra_ide_api/src/hover.rs95
-rw-r--r--crates/ra_ide_api/src/references.rs5
-rw-r--r--crates/ra_ide_api/src/references/classify.rs3
-rw-r--r--crates/ra_ide_api/src/references/name_definition.rs6
8 files changed, 70 insertions, 77 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs
index c5cf39ee1..a842dfed6 100644
--- a/crates/ra_hir/src/code_model.rs
+++ b/crates/ra_hir/src/code_model.rs
@@ -982,7 +982,7 @@ impl ImplBlock {
982 } 982 }
983} 983}
984 984
985#[derive(Clone, PartialEq, Eq)] 985#[derive(Clone, PartialEq, Eq, Debug)]
986pub struct Type { 986pub struct Type {
987 pub(crate) krate: CrateId, 987 pub(crate) krate: CrateId,
988 pub(crate) ty: InEnvironment<Ty>, 988 pub(crate) ty: InEnvironment<Ty>,
@@ -1104,7 +1104,7 @@ impl Type {
1104 1104
1105 pub fn as_adt(&self) -> Option<Adt> { 1105 pub fn as_adt(&self) -> Option<Adt> {
1106 let (adt, _subst) = self.ty.value.as_adt()?; 1106 let (adt, _subst) = self.ty.value.as_adt()?;
1107 Some(adt) 1107 Some(adt.into())
1108 } 1108 }
1109 1109
1110 fn derived(&self, ty: Ty) -> Type { 1110 fn derived(&self, ty: Ty) -> Type {
diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs
index adb9805ab..5c82c23d6 100644
--- a/crates/ra_hir/src/expr.rs
+++ b/crates/ra_hir/src/expr.rs
@@ -12,7 +12,7 @@ use crate::{
12 db::HirDatabase, 12 db::HirDatabase,
13 diagnostics::{MissingFields, MissingOkInTailExpr}, 13 diagnostics::{MissingFields, MissingOkInTailExpr},
14 ty::{ApplicationTy, InferenceResult, Ty, TypeCtor}, 14 ty::{ApplicationTy, InferenceResult, Ty, TypeCtor},
15 Adt, Function, Name, Path, 15 Function, Name, Path, Struct,
16}; 16};
17 17
18pub use hir_def::{ 18pub use hir_def::{
@@ -69,7 +69,7 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
69 } 69 }
70 70
71 let struct_def = match self.infer[id].as_adt() { 71 let struct_def = match self.infer[id].as_adt() {
72 Some((Adt::Struct(s), _)) => s, 72 Some((AdtId::StructId(s), _)) => Struct::from(s),
73 _ => return, 73 _ => return,
74 }; 74 };
75 75
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs
index 680ddc2f9..791b6064a 100644
--- a/crates/ra_hir/src/ty.rs
+++ b/crates/ra_hir/src/ty.rs
@@ -22,13 +22,14 @@ use hir_def::{
22 expr::ExprId, generics::GenericParams, type_ref::Mutability, AdtId, ContainerId, DefWithBodyId, 22 expr::ExprId, generics::GenericParams, type_ref::Mutability, AdtId, ContainerId, DefWithBodyId,
23 GenericDefId, HasModule, Lookup, TraitId, TypeAliasId, 23 GenericDefId, HasModule, Lookup, TraitId, TypeAliasId,
24}; 24};
25use hir_expand::name::Name;
25use ra_db::{impl_intern_key, salsa}; 26use ra_db::{impl_intern_key, salsa};
26 27
27use crate::{ 28use crate::{
28 db::HirDatabase, 29 db::HirDatabase,
29 ty::primitive::{FloatTy, IntTy, Uncertain}, 30 ty::primitive::{FloatTy, IntTy, Uncertain},
30 util::make_mut_slice, 31 util::make_mut_slice,
31 Adt, Crate, Name, 32 Crate,
32}; 33};
33use display::{HirDisplay, HirFormatter}; 34use display::{HirDisplay, HirFormatter};
34 35
@@ -598,10 +599,10 @@ impl Ty {
598 } 599 }
599 } 600 }
600 601
601 pub fn as_adt(&self) -> Option<(Adt, &Substs)> { 602 pub fn as_adt(&self) -> Option<(AdtId, &Substs)> {
602 match self { 603 match self {
603 Ty::Apply(ApplicationTy { ctor: TypeCtor::Adt(adt_def), parameters }) => { 604 Ty::Apply(ApplicationTy { ctor: TypeCtor::Adt(adt_def), parameters }) => {
604 Some(((*adt_def).into(), parameters)) 605 Some((*adt_def, parameters))
605 } 606 }
606 _ => None, 607 _ => None,
607 } 608 }
diff --git a/crates/ra_ide_api/src/goto_definition.rs b/crates/ra_ide_api/src/goto_definition.rs
index b6c72efdf..c10a6c844 100644
--- a/crates/ra_ide_api/src/goto_definition.rs
+++ b/crates/ra_ide_api/src/goto_definition.rs
@@ -71,10 +71,11 @@ pub(crate) fn reference_definition(
71 Some(nav) => return Exact(nav), 71 Some(nav) => return Exact(nav),
72 None => return Approximate(vec![]), 72 None => return Approximate(vec![]),
73 }, 73 },
74 Some(SelfType(ty)) => { 74 Some(SelfType(imp)) => {
75 if let Some((adt, _)) = ty.as_adt() { 75 // FIXME: ideally, this should point to the type in the impl, and
76 return Exact(adt.to_nav(db)); 76 // not at the whole impl. And goto **type** definition should bring
77 } 77 // us to the actual type
78 return Exact(imp.to_nav(db));
78 } 79 }
79 Some(Local(local)) => return Exact(local.to_nav(db)), 80 Some(Local(local)) => return Exact(local.to_nav(db)),
80 Some(GenericParam(_)) => { 81 Some(GenericParam(_)) => {
@@ -503,7 +504,7 @@ mod tests {
503 } 504 }
504 } 505 }
505 ", 506 ",
506 "Foo STRUCT_DEF FileId(1) [0; 11) [7; 10)", 507 "impl IMPL_BLOCK FileId(1) [12; 73)",
507 ); 508 );
508 509
509 check_goto( 510 check_goto(
@@ -516,7 +517,7 @@ mod tests {
516 } 517 }
517 } 518 }
518 ", 519 ",
519 "Foo STRUCT_DEF FileId(1) [0; 11) [7; 10)", 520 "impl IMPL_BLOCK FileId(1) [12; 73)",
520 ); 521 );
521 522
522 check_goto( 523 check_goto(
@@ -529,7 +530,7 @@ mod tests {
529 } 530 }
530 } 531 }
531 ", 532 ",
532 "Foo ENUM_DEF FileId(1) [0; 14) [5; 8)", 533 "impl IMPL_BLOCK FileId(1) [15; 75)",
533 ); 534 );
534 535
535 check_goto( 536 check_goto(
@@ -541,7 +542,7 @@ mod tests {
541 } 542 }
542 } 543 }
543 ", 544 ",
544 "Foo ENUM_DEF FileId(1) [0; 14) [5; 8)", 545 "impl IMPL_BLOCK FileId(1) [15; 62)",
545 ); 546 );
546 } 547 }
547 548
@@ -560,7 +561,7 @@ mod tests {
560 } 561 }
561 } 562 }
562 ", 563 ",
563 "Foo STRUCT_DEF FileId(1) [0; 11) [7; 10)", 564 "impl IMPL_BLOCK FileId(1) [49; 115)",
564 ); 565 );
565 566
566 check_goto( 567 check_goto(
@@ -572,11 +573,11 @@ mod tests {
572 } 573 }
573 impl Make for Foo { 574 impl Make for Foo {
574 fn new() -> Self<|> { 575 fn new() -> Self<|> {
575 Self{} 576 Self {}
576 } 577 }
577 } 578 }
578 ", 579 ",
579 "Foo STRUCT_DEF FileId(1) [0; 11) [7; 10)", 580 "impl IMPL_BLOCK FileId(1) [49; 115)",
580 ); 581 );
581 } 582 }
582 583
diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs
index 9839be985..260a7b869 100644
--- a/crates/ra_ide_api/src/hover.rs
+++ b/crates/ra_ide_api/src/hover.rs
@@ -133,20 +133,12 @@ fn hover_text_from_name_kind(
133 hir::ModuleDef::TypeAlias(it) => from_def_source(db, it), 133 hir::ModuleDef::TypeAlias(it) => from_def_source(db, it),
134 hir::ModuleDef::BuiltinType(it) => Some(it.to_string()), 134 hir::ModuleDef::BuiltinType(it) => Some(it.to_string()),
135 }, 135 },
136 SelfType(ty) => match ty.as_adt() {
137 Some((adt_def, _)) => match adt_def {
138 hir::Adt::Struct(it) => from_def_source(db, it),
139 hir::Adt::Union(it) => from_def_source(db, it),
140 hir::Adt::Enum(it) => from_def_source(db, it),
141 },
142 _ => None,
143 },
144 Local(_) => { 136 Local(_) => {
145 // Hover for these shows type names 137 // Hover for these shows type names
146 *no_fallback = true; 138 *no_fallback = true;
147 None 139 None
148 } 140 }
149 GenericParam(_) => { 141 GenericParam(_) | SelfType(_) => {
150 // FIXME: Hover for generic param 142 // FIXME: Hover for generic param
151 None 143 None
152 } 144 }
@@ -622,49 +614,52 @@ fn func(foo: i32) { if true { <|>foo; }; }
622 ", 614 ",
623 ); 615 );
624 let hover = analysis.hover(position).unwrap().unwrap(); 616 let hover = analysis.hover(position).unwrap().unwrap();
625 assert_eq!(trim_markup_opt(hover.info.first()), Some("struct Thing")); 617 assert_eq!(trim_markup_opt(hover.info.first()), Some("Thing"));
626 assert_eq!(hover.info.is_exact(), true);
627
628 let (analysis, position) = single_file_with_position(
629 "
630 struct Thing { x: u32 }
631 impl Thing {
632 fn new() -> Self<|> {
633 Self { x: 0 }
634 }
635 }
636 ",
637 );
638 let hover = analysis.hover(position).unwrap().unwrap();
639 assert_eq!(trim_markup_opt(hover.info.first()), Some("struct Thing"));
640 assert_eq!(hover.info.is_exact(), true);
641
642 let (analysis, position) = single_file_with_position(
643 "
644 enum Thing { A }
645 impl Thing {
646 pub fn new() -> Self<|> {
647 Thing::A
648 }
649 }
650 ",
651 );
652 let hover = analysis.hover(position).unwrap().unwrap();
653 assert_eq!(trim_markup_opt(hover.info.first()), Some("enum Thing"));
654 assert_eq!(hover.info.is_exact(), true); 618 assert_eq!(hover.info.is_exact(), true);
655 619
656 let (analysis, position) = single_file_with_position( 620 /* FIXME: revive these tests
657 " 621 let (analysis, position) = single_file_with_position(
658 enum Thing { A } 622 "
659 impl Thing { 623 struct Thing { x: u32 }
660 pub fn thing(a: Self<|>) { 624 impl Thing {
661 } 625 fn new() -> Self<|> {
662 } 626 Self { x: 0 }
663 ", 627 }
664 ); 628 }
665 let hover = analysis.hover(position).unwrap().unwrap(); 629 ",
666 assert_eq!(trim_markup_opt(hover.info.first()), Some("enum Thing")); 630 );
667 assert_eq!(hover.info.is_exact(), true); 631
632 let hover = analysis.hover(position).unwrap().unwrap();
633 assert_eq!(trim_markup_opt(hover.info.first()), Some("Thing"));
634 assert_eq!(hover.info.is_exact(), true);
635
636 let (analysis, position) = single_file_with_position(
637 "
638 enum Thing { A }
639 impl Thing {
640 pub fn new() -> Self<|> {
641 Thing::A
642 }
643 }
644 ",
645 );
646 let hover = analysis.hover(position).unwrap().unwrap();
647 assert_eq!(trim_markup_opt(hover.info.first()), Some("enum Thing"));
648 assert_eq!(hover.info.is_exact(), true);
649
650 let (analysis, position) = single_file_with_position(
651 "
652 enum Thing { A }
653 impl Thing {
654 pub fn thing(a: Self<|>) {
655 }
656 }
657 ",
658 );
659 let hover = analysis.hover(position).unwrap().unwrap();
660 assert_eq!(trim_markup_opt(hover.info.first()), Some("enum Thing"));
661 assert_eq!(hover.info.is_exact(), true);
662 */
668 } 663 }
669 664
670 #[test] 665 #[test]
diff --git a/crates/ra_ide_api/src/references.rs b/crates/ra_ide_api/src/references.rs
index cb343e59a..21a1ea69e 100644
--- a/crates/ra_ide_api/src/references.rs
+++ b/crates/ra_ide_api/src/references.rs
@@ -83,10 +83,7 @@ pub(crate) fn find_all_refs(
83 NameKind::Field(field) => field.to_nav(db), 83 NameKind::Field(field) => field.to_nav(db),
84 NameKind::AssocItem(assoc) => assoc.to_nav(db), 84 NameKind::AssocItem(assoc) => assoc.to_nav(db),
85 NameKind::Def(def) => NavigationTarget::from_def(db, def)?, 85 NameKind::Def(def) => NavigationTarget::from_def(db, def)?,
86 NameKind::SelfType(ref ty) => match ty.as_adt() { 86 NameKind::SelfType(imp) => imp.to_nav(db),
87 Some((adt, _)) => adt.to_nav(db),
88 None => return None,
89 },
90 NameKind::Local(local) => local.to_nav(db), 87 NameKind::Local(local) => local.to_nav(db),
91 NameKind::GenericParam(_) => return None, 88 NameKind::GenericParam(_) => return None,
92 }; 89 };
diff --git a/crates/ra_ide_api/src/references/classify.rs b/crates/ra_ide_api/src/references/classify.rs
index 227737ad2..5cea805ec 100644
--- a/crates/ra_ide_api/src/references/classify.rs
+++ b/crates/ra_ide_api/src/references/classify.rs
@@ -178,8 +178,7 @@ pub(crate) fn classify_name_ref(
178 Some(NameDefinition { kind, container, visibility }) 178 Some(NameDefinition { kind, container, visibility })
179 } 179 }
180 PathResolution::SelfType(impl_block) => { 180 PathResolution::SelfType(impl_block) => {
181 let ty = impl_block.target_ty(db); 181 let kind = NameKind::SelfType(impl_block);
182 let kind = NameKind::SelfType(ty);
183 let container = impl_block.module(db); 182 let container = impl_block.module(db);
184 Some(NameDefinition { kind, container, visibility }) 183 Some(NameDefinition { kind, container, visibility })
185 } 184 }
diff --git a/crates/ra_ide_api/src/references/name_definition.rs b/crates/ra_ide_api/src/references/name_definition.rs
index cf12db066..10d3a2364 100644
--- a/crates/ra_ide_api/src/references/name_definition.rs
+++ b/crates/ra_ide_api/src/references/name_definition.rs
@@ -4,8 +4,8 @@
4//! Note that the reference search is possible for not all of the classified items. 4//! Note that the reference search is possible for not all of the classified items.
5 5
6use hir::{ 6use hir::{
7 Adt, AssocItem, GenericParam, HasSource, Local, MacroDef, Module, ModuleDef, StructField, Ty, 7 Adt, AssocItem, GenericParam, HasSource, ImplBlock, Local, MacroDef, Module, ModuleDef,
8 VariantDef, 8 StructField, VariantDef,
9}; 9};
10use ra_syntax::{ast, ast::VisibilityOwner}; 10use ra_syntax::{ast, ast::VisibilityOwner};
11 11
@@ -17,7 +17,7 @@ pub enum NameKind {
17 Field(StructField), 17 Field(StructField),
18 AssocItem(AssocItem), 18 AssocItem(AssocItem),
19 Def(ModuleDef), 19 Def(ModuleDef),
20 SelfType(Ty), 20 SelfType(ImplBlock),
21 Local(Local), 21 Local(Local),
22 GenericParam(GenericParam), 22 GenericParam(GenericParam),
23} 23}