From 1d6f291335c58aac95c1124f55d7fb0834baff2a Mon Sep 17 00:00:00 2001 From: Zac Pullar-Strecker Date: Sat, 13 Jun 2020 22:34:59 +1200 Subject: Move resolver into impls, work on tests --- crates/ra_hir/src/code_model.rs | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) (limited to 'crates/ra_hir/src') diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index e86077dd6..5766cc3b8 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs @@ -186,21 +186,34 @@ impl ModuleDef { module.visibility_of(db, self) } - pub fn name(self, db: &dyn HirDatabase) -> Option { + pub fn name(&self, db: &dyn HirDatabase) -> Option { match self { - ModuleDef::Adt(it) => Some(it.name(db)), - ModuleDef::Trait(it) => Some(it.name(db)), - ModuleDef::Function(it) => Some(it.name(db)), - ModuleDef::EnumVariant(it) => Some(it.name(db)), - ModuleDef::TypeAlias(it) => Some(it.name(db)), - - ModuleDef::Module(it) => it.name(db), - ModuleDef::Const(it) => it.name(db), - ModuleDef::Static(it) => it.name(db), - - ModuleDef::BuiltinType(it) => Some(it.as_name()), + ModuleDef::Module(m) => m.name(db), + ModuleDef::Function(m) => Some(m.name(db)), + ModuleDef::Adt(m) => Some(m.name(db)), + ModuleDef::EnumVariant(m) => Some(m.name(db)), + ModuleDef::Const(m) => {m.name(db)}, + ModuleDef::Static(m) => {m.name(db)}, + ModuleDef::Trait(m) => {Some(m.name(db))}, + ModuleDef::TypeAlias(m) => {Some(m.name(db))}, + ModuleDef::BuiltinType(m) => {Some(m.as_name())} } } + + pub fn resolver(&self, db: &D) -> Option { + Some(match self { + ModuleDef::Module(m) => Into::::into(m.clone()).resolver(db), + ModuleDef::Function(f) => Into::::into(f.clone()).resolver(db), + ModuleDef::Adt(adt) => Into::::into(adt.clone()).resolver(db), + ModuleDef::EnumVariant(ev) => Into::::into(Into::::into(ev.clone())).resolver(db), + ModuleDef::Const(c) => Into::::into(Into::::into(c.clone())).resolver(db), + ModuleDef::Static(s) => Into::::into(s.clone()).resolver(db), + ModuleDef::Trait(t) => Into::::into(t.clone()).resolver(db), + ModuleDef::TypeAlias(t) => Into::::into(t.module(db)).resolver(db), + // TODO: This should be a resolver relative to `std` + ModuleDef::BuiltinType(_t) => None? + }) + } } pub use hir_def::{ -- cgit v1.2.3