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/src/goto_definition.rs | 5 +++-- crates/ra_ide/src/hover.rs | 4 ++-- crates/ra_ide/src/references.rs | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/goto_definition.rs b/crates/ra_ide/src/goto_definition.rs index b44b6fe22..45389fd23 100644 --- a/crates/ra_ide/src/goto_definition.rs +++ b/crates/ra_ide/src/goto_definition.rs @@ -40,7 +40,7 @@ pub(crate) fn goto_definition( reference_definition(&sema, &name_ref).to_vec() }, ast::Name(name) => { - let def = classify_name(&sema, &name)?.definition(sema.db)?; + let def = classify_name(&sema, &name)?.definition(sema.db); let nav = def.try_to_nav(sema.db)?; vec![nav] }, @@ -82,7 +82,8 @@ pub(crate) fn reference_definition( name_ref: &ast::NameRef, ) -> ReferenceResult { let name_kind = classify_name_ref(sema, name_ref); - if let Some(def) = name_kind.and_then(|def| def.definition(sema.db)) { + if let Some(def) = name_kind { + let def = def.definition(sema.db); return match def.try_to_nav(sema.db) { Some(nav) => ReferenceResult::Exact(nav), None => ReferenceResult::Approximate(Vec::new()), diff --git a/crates/ra_ide/src/hover.rs b/crates/ra_ide/src/hover.rs index a632ea6a2..f6e493817 100644 --- a/crates/ra_ide/src/hover.rs +++ b/crates/ra_ide/src/hover.rs @@ -85,8 +85,8 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option classify_name_ref(&sema, &name_ref).and_then(|d| d.definition(sema.db)), - ast::Name(name) => classify_name(&sema, &name).and_then(|d| d.definition(sema.db)), + ast::NameRef(name_ref) => classify_name_ref(&sema, &name_ref).map(|d| d.definition(sema.db)), + ast::Name(name) => classify_name(&sema, &name).map(|d| d.definition(sema.db)), _ => None, } }; diff --git a/crates/ra_ide/src/references.rs b/crates/ra_ide/src/references.rs index 9dd228b9c..453985de3 100644 --- a/crates/ra_ide/src/references.rs +++ b/crates/ra_ide/src/references.rs @@ -130,13 +130,13 @@ fn find_name( opt_name: Option, ) -> Option> { if let Some(name) = opt_name { - let def = classify_name(sema, &name)?.definition(sema.db)?; + let def = classify_name(sema, &name)?.definition(sema.db); let range = name.syntax().text_range(); return Some(RangeInfo::new(range, def)); } let name_ref = sema.find_node_at_offset_with_descend::(&syntax, position.offset)?; - let def = classify_name_ref(sema, &name_ref)?.definition(sema.db)?; + let def = classify_name_ref(sema, &name_ref)?.definition(sema.db); let range = name_ref.syntax().text_range(); Some(RangeInfo::new(range, def)) } -- cgit v1.2.3