From bf9b4578bbe038501ef7c337e22b448de477f61c Mon Sep 17 00:00:00 2001 From: Paul Daniel Faria Date: Sun, 9 Aug 2020 18:52:19 -0400 Subject: Remove Option<...> from result of Crate::root_module There doesn't seem to be any need for it, and removing it simplies several paths of code that depend on it. --- crates/ra_ide_db/src/defs.rs | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'crates/ra_ide_db/src') diff --git a/crates/ra_ide_db/src/defs.rs b/crates/ra_ide_db/src/defs.rs index e2a4f2983..9bb95277d 100644 --- a/crates/ra_ide_db/src/defs.rs +++ b/crates/ra_ide_db/src/defs.rs @@ -93,19 +93,19 @@ pub enum NameClass { impl NameClass { pub fn into_definition(self, db: &dyn HirDatabase) -> Option { Some(match self { - NameClass::ExternCrate(krate) => Definition::ModuleDef(krate.root_module(db)?.into()), + NameClass::ExternCrate(krate) => Definition::ModuleDef(krate.root_module(db).into()), NameClass::Definition(it) => it, NameClass::ConstReference(_) => return None, NameClass::FieldShorthand { local, field: _ } => Definition::Local(local), }) } - pub fn definition(self, db: &dyn HirDatabase) -> Option { - Some(match self { - NameClass::ExternCrate(krate) => Definition::ModuleDef(krate.root_module(db)?.into()), + pub fn definition(self, db: &dyn HirDatabase) -> Definition { + match self { + NameClass::ExternCrate(krate) => Definition::ModuleDef(krate.root_module(db).into()), NameClass::Definition(it) | NameClass::ConstReference(it) => it, NameClass::FieldShorthand { local: _, field } => field, - }) + } } } @@ -148,7 +148,7 @@ pub fn classify_name(sema: &Semantics, name: &ast::Name) -> Option }) .and_then(|name_ref| classify_name_ref(sema, &name_ref))?; - Some(NameClass::Definition(name_ref_class.definition(sema.db)?)) + Some(NameClass::Definition(name_ref_class.definition(sema.db))) } else { let extern_crate = it.syntax().parent().and_then(ast::ExternCrate::cast)?; let resolved = sema.resolve_extern_crate(&extern_crate)?; @@ -234,14 +234,12 @@ pub enum NameRefClass { } impl NameRefClass { - pub fn definition(self, db: &dyn HirDatabase) -> Option { - Some(match self { - NameRefClass::ExternCrate(krate) => { - Definition::ModuleDef(krate.root_module(db)?.into()) - } + pub fn definition(self, db: &dyn HirDatabase) -> Definition { + match self { + NameRefClass::ExternCrate(krate) => Definition::ModuleDef(krate.root_module(db).into()), NameRefClass::Definition(def) => def, NameRefClass::FieldShorthand { local, field: _ } => Definition::Local(local), - }) + } } } -- cgit v1.2.3