From 6ec982d54dcb28a56e5f13337d045e187949888b Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 12 Feb 2020 18:00:14 +0100 Subject: Simplify --- crates/ra_ide/src/goto_type_definition.rs | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) (limited to 'crates/ra_ide/src') diff --git a/crates/ra_ide/src/goto_type_definition.rs b/crates/ra_ide/src/goto_type_definition.rs index 11ad6d137..69940fc36 100644 --- a/crates/ra_ide/src/goto_type_definition.rs +++ b/crates/ra_ide/src/goto_type_definition.rs @@ -16,24 +16,16 @@ pub(crate) fn goto_type_definition( let token = pick_best(file.token_at_offset(position.offset))?; let token = descend_into_macros(db, position.file_id, token); - let node = token.value.ancestors().find_map(|token| { - token - .ancestors() - .find(|n| ast::Expr::cast(n.clone()).is_some() || ast::Pat::cast(n.clone()).is_some()) - })?; + let node = token + .value + .ancestors() + .find(|n| ast::Expr::cast(n.clone()).is_some() || ast::Pat::cast(n.clone()).is_some())?; let analyzer = hir::SourceAnalyzer::new(db, token.with_value(&node), None); - let ty: hir::Type = if let Some(ty) = - ast::Expr::cast(node.clone()).and_then(|e| analyzer.type_of(db, &e)) - { - ty - } else if let Some(ty) = ast::Pat::cast(node.clone()).and_then(|p| analyzer.type_of_pat(db, &p)) - { - ty - } else { - return None; - }; + let ty: hir::Type = ast::Expr::cast(node.clone()) + .and_then(|e| analyzer.type_of(db, &e)) + .or_else(|| ast::Pat::cast(node.clone()).and_then(|p| analyzer.type_of_pat(db, &p)))?; let adt_def = ty.autoderef(db).find_map(|ty| ty.as_adt())?; -- cgit v1.2.3