about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLukas Wirth <lukastw97@gmail.com>2023-05-02 08:56:48 +0200
committerLukas Wirth <lukastw97@gmail.com>2023-05-02 09:05:28 +0200
commit5a97a326a910db4011fb5b060aeb555bfbd840d6 (patch)
treea59d76580b684d02b142d37a5b4d9bb5aa5287f7
parent89075335360068d782806bde7297732481f4d113 (diff)
downloadrust-5a97a326a910db4011fb5b060aeb555bfbd840d6.tar.gz
rust-5a97a326a910db4011fb5b060aeb555bfbd840d6.zip
Simplify
-rw-r--r--crates/hir-ty/src/infer/closure.rs2
-rw-r--r--crates/ide/src/highlight_related.rs19
2 files changed, 7 insertions, 14 deletions
diff --git a/crates/hir-ty/src/infer/closure.rs b/crates/hir-ty/src/infer/closure.rs
index 2c3e54bf191..df2ad7af343 100644
--- a/crates/hir-ty/src/infer/closure.rs
+++ b/crates/hir-ty/src/infer/closure.rs
@@ -115,7 +115,7 @@ impl InferenceContext<'_> {
 
 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
 pub(crate) struct HirPlace {
-    pub local: BindingId,
+    pub(crate) local: BindingId,
     pub(crate) projections: Vec<ProjectionElem<Infallible, Ty>>,
 }
 
diff --git a/crates/ide/src/highlight_related.rs b/crates/ide/src/highlight_related.rs
index b832e269307..3a519fe65a1 100644
--- a/crates/ide/src/highlight_related.rs
+++ b/crates/ide/src/highlight_related.rs
@@ -72,16 +72,8 @@ pub(crate) fn highlight_related(
         T![break] | T![loop] | T![while] | T![continue] if config.break_points => {
             highlight_break_points(token)
         }
-        T![|] if config.closure_captures => highlight_closure_captures(
-            sema,
-            token.parent_ancestors().nth(1).and_then(ast::ClosureExpr::cast)?,
-            file_id,
-        ),
-        T![move] if config.closure_captures => highlight_closure_captures(
-            sema,
-            token.parent().and_then(ast::ClosureExpr::cast)?,
-            file_id,
-        ),
+        T![|] if config.closure_captures => highlight_closure_captures(sema, token, file_id),
+        T![move] if config.closure_captures => highlight_closure_captures(sema, token, file_id),
         _ if config.references => highlight_references(sema, &syntax, token, file_id),
         _ => None,
     }
@@ -89,11 +81,12 @@ pub(crate) fn highlight_related(
 
 fn highlight_closure_captures(
     sema: &Semantics<'_, RootDatabase>,
-    node: ast::ClosureExpr,
+    token: SyntaxToken,
     file_id: FileId,
 ) -> Option<Vec<HighlightedRange>> {
-    let search_range = node.body()?.syntax().text_range();
-    let ty = &sema.type_of_expr(&node.into())?.original;
+    let closure = token.parent_ancestors().take(2).find_map(ast::ClosureExpr::cast)?;
+    let search_range = closure.body()?.syntax().text_range();
+    let ty = &sema.type_of_expr(&closure.into())?.original;
     let c = ty.as_closure()?;
     Some(
         c.captured_items(sema.db)