diff options
author | vsrs <[email protected]> | 2020-06-11 12:41:42 +0100 |
---|---|---|
committer | vsrs <[email protected]> | 2020-06-18 08:15:43 +0100 |
commit | 7ec0064409f90334f6b0dd61e572a65702702985 (patch) | |
tree | 4a97c35ea8f6defd4718fdfdc801f3646105de7e /crates/ra_hir | |
parent | 7e986d1504e6fd6dc1fc9b64f5fb9eac2bef952a (diff) |
Remove AdtOrTrait
Diffstat (limited to 'crates/ra_hir')
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 51 | ||||
-rw-r--r-- | crates/ra_hir/src/lib.rs | 8 |
2 files changed, 26 insertions, 33 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 64b9a4cc3..5137a16e6 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -186,6 +186,22 @@ impl ModuleDef { | |||
186 | 186 | ||
187 | module.visibility_of(db, self) | 187 | module.visibility_of(db, self) |
188 | } | 188 | } |
189 | |||
190 | pub fn name(self, db: &dyn HirDatabase) -> Option<Name> { | ||
191 | match self { | ||
192 | ModuleDef::Adt(it) => Some(it.name(db)), | ||
193 | ModuleDef::Trait(it) => Some(it.name(db)), | ||
194 | ModuleDef::Function(it) => Some(it.name(db)), | ||
195 | ModuleDef::EnumVariant(it) => Some(it.name(db)), | ||
196 | ModuleDef::TypeAlias(it) => Some(it.name(db)), | ||
197 | |||
198 | ModuleDef::Module(it) => it.name(db), | ||
199 | ModuleDef::Const(it) => it.name(db), | ||
200 | ModuleDef::Static(it) => it.name(db), | ||
201 | |||
202 | ModuleDef::BuiltinType(it) => Some(it.as_name()), | ||
203 | } | ||
204 | } | ||
189 | } | 205 | } |
190 | 206 | ||
191 | pub use hir_def::{ | 207 | pub use hir_def::{ |
@@ -1382,8 +1398,8 @@ impl Type { | |||
1382 | } | 1398 | } |
1383 | 1399 | ||
1384 | /// Returns a flattened list of all ADTs and Traits mentioned in the type | 1400 | /// Returns a flattened list of all ADTs and Traits mentioned in the type |
1385 | pub fn flattened_type_items(&self, db: &dyn HirDatabase) -> Vec<AdtOrTrait> { | 1401 | pub fn flattened_type_items(&self, db: &dyn HirDatabase) -> Vec<ModuleDef> { |
1386 | fn push_new_item(item: AdtOrTrait, acc: &mut Vec<AdtOrTrait>) { | 1402 | fn push_new_item(item: ModuleDef, acc: &mut Vec<ModuleDef>) { |
1387 | if !acc.contains(&item) { | 1403 | if !acc.contains(&item) { |
1388 | acc.push(item); | 1404 | acc.push(item); |
1389 | } | 1405 | } |
@@ -1392,7 +1408,7 @@ impl Type { | |||
1392 | fn push_bounds( | 1408 | fn push_bounds( |
1393 | db: &dyn HirDatabase, | 1409 | db: &dyn HirDatabase, |
1394 | predicates: &[GenericPredicate], | 1410 | predicates: &[GenericPredicate], |
1395 | acc: &mut Vec<AdtOrTrait>, | 1411 | acc: &mut Vec<ModuleDef>, |
1396 | ) { | 1412 | ) { |
1397 | for p in predicates.iter() { | 1413 | for p in predicates.iter() { |
1398 | match p { | 1414 | match p { |
@@ -1407,13 +1423,13 @@ impl Type { | |||
1407 | } | 1423 | } |
1408 | 1424 | ||
1409 | // TypeWalk::walk does not preserve items order! | 1425 | // TypeWalk::walk does not preserve items order! |
1410 | fn walk_substs(db: &dyn HirDatabase, substs: &Substs, acc: &mut Vec<AdtOrTrait>) { | 1426 | fn walk_substs(db: &dyn HirDatabase, substs: &Substs, acc: &mut Vec<ModuleDef>) { |
1411 | for ty in substs.iter() { | 1427 | for ty in substs.iter() { |
1412 | walk_type(db, ty, acc); | 1428 | walk_type(db, ty, acc); |
1413 | } | 1429 | } |
1414 | } | 1430 | } |
1415 | 1431 | ||
1416 | fn walk_type(db: &dyn HirDatabase, ty: &Ty, acc: &mut Vec<AdtOrTrait>) { | 1432 | fn walk_type(db: &dyn HirDatabase, ty: &Ty, acc: &mut Vec<ModuleDef>) { |
1417 | match ty.strip_references() { | 1433 | match ty.strip_references() { |
1418 | Ty::Apply(ApplicationTy { ctor, parameters, .. }) => { | 1434 | Ty::Apply(ApplicationTy { ctor, parameters, .. }) => { |
1419 | match ctor { | 1435 | match ctor { |
@@ -1468,7 +1484,7 @@ impl Type { | |||
1468 | } | 1484 | } |
1469 | } | 1485 | } |
1470 | 1486 | ||
1471 | let mut res: Vec<AdtOrTrait> = Vec::new(); // not a Set to preserve the order | 1487 | let mut res: Vec<ModuleDef> = Vec::new(); // not a Set to preserve the order |
1472 | walk_type(db, &self.ty.value, &mut res); | 1488 | walk_type(db, &self.ty.value, &mut res); |
1473 | res | 1489 | res |
1474 | } | 1490 | } |
@@ -1580,26 +1596,3 @@ pub trait HasVisibility { | |||
1580 | vis.is_visible_from(db.upcast(), module.id) | 1596 | vis.is_visible_from(db.upcast(), module.id) |
1581 | } | 1597 | } |
1582 | } | 1598 | } |
1583 | |||
1584 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] | ||
1585 | pub enum AdtOrTrait { | ||
1586 | Adt(Adt), | ||
1587 | Trait(Trait), | ||
1588 | } | ||
1589 | impl_froms!(AdtOrTrait: Adt, Trait); | ||
1590 | |||
1591 | impl AdtOrTrait { | ||
1592 | pub fn module(self, db: &dyn HirDatabase) -> Module { | ||
1593 | match self { | ||
1594 | AdtOrTrait::Adt(adt) => adt.module(db), | ||
1595 | AdtOrTrait::Trait(trait_) => trait_.module(db), | ||
1596 | } | ||
1597 | } | ||
1598 | |||
1599 | pub fn name(self, db: &dyn HirDatabase) -> Name { | ||
1600 | match self { | ||
1601 | AdtOrTrait::Adt(adt) => adt.name(db), | ||
1602 | AdtOrTrait::Trait(trait_) => trait_.name(db), | ||
1603 | } | ||
1604 | } | ||
1605 | } | ||
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index eded039e4..3364a822f 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs | |||
@@ -51,10 +51,10 @@ mod has_source; | |||
51 | 51 | ||
52 | pub use crate::{ | 52 | pub use crate::{ |
53 | code_model::{ | 53 | code_model::{ |
54 | Adt, AdtOrTrait, AsAssocItem, AssocItem, AssocItemContainer, AttrDef, Const, Crate, | 54 | Adt, AsAssocItem, AssocItem, AssocItemContainer, AttrDef, Const, Crate, CrateDependency, |
55 | CrateDependency, DefWithBody, Docs, Enum, EnumVariant, Field, FieldSource, Function, | 55 | DefWithBody, Docs, Enum, EnumVariant, Field, FieldSource, Function, GenericDef, HasAttrs, |
56 | GenericDef, HasAttrs, HasVisibility, ImplDef, Local, MacroDef, Module, ModuleDef, ScopeDef, | 56 | HasVisibility, ImplDef, Local, MacroDef, Module, ModuleDef, ScopeDef, Static, Struct, |
57 | Static, Struct, Trait, Type, TypeAlias, TypeParam, Union, VariantDef, Visibility, | 57 | Trait, Type, TypeAlias, TypeParam, Union, VariantDef, Visibility, |
58 | }, | 58 | }, |
59 | has_source::HasSource, | 59 | has_source::HasSource, |
60 | semantics::{original_range, PathResolution, Semantics, SemanticsScope}, | 60 | semantics::{original_range, PathResolution, Semantics, SemanticsScope}, |