about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--crates/ide/src/highlight_related.rs9
-rw-r--r--crates/ide/src/references.rs19
2 files changed, 5 insertions, 23 deletions
diff --git a/crates/ide/src/highlight_related.rs b/crates/ide/src/highlight_related.rs
index 3aed007f3ea..3c34778efb5 100644
--- a/crates/ide/src/highlight_related.rs
+++ b/crates/ide/src/highlight_related.rs
@@ -15,10 +15,10 @@ use syntax::{
     ast::{self, HasLoopBody},
     match_ast, AstNode,
     SyntaxKind::{self, IDENT, INT_NUMBER},
-    SyntaxNode, SyntaxToken, TextRange, T,
+    SyntaxToken, TextRange, T,
 };
 
-use crate::{navigation_target::ToNav, references, NavigationTarget, TryToNav};
+use crate::{navigation_target::ToNav, NavigationTarget, TryToNav};
 
 #[derive(PartialEq, Eq, Hash)]
 pub struct HighlightedRange {
@@ -81,7 +81,7 @@ pub(crate) fn highlight_related(
         }
         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, pos),
+        _ if config.references => highlight_references(sema, token, pos),
         _ => None,
     }
 }
@@ -129,7 +129,6 @@ fn highlight_closure_captures(
 
 fn highlight_references(
     sema: &Semantics<'_, RootDatabase>,
-    node: &SyntaxNode,
     token: SyntaxToken,
     FilePosition { file_id, offset }: FilePosition,
 ) -> Option<Vec<HighlightedRange>> {
@@ -239,7 +238,7 @@ fn highlight_references(
                         continue;
                     }
                     let hl_range = nav.focus_range.map(|range| {
-                        let category = references::decl_mutability(&def, node, range)
+                        let category = matches!(def, Definition::Local(l) if l.is_mut(sema.db))
                             .then_some(ReferenceCategory::Write);
                         HighlightedRange { range, category }
                     });
diff --git a/crates/ide/src/references.rs b/crates/ide/src/references.rs
index 6c0fb0baf2e..78fe84f70d3 100644
--- a/crates/ide/src/references.rs
+++ b/crates/ide/src/references.rs
@@ -21,7 +21,6 @@ use ide_db::{
 use itertools::Itertools;
 use nohash_hasher::IntMap;
 use syntax::{
-    algo::find_node_at_offset,
     ast::{self, HasName},
     match_ast, AstNode,
     SyntaxKind::*,
@@ -98,9 +97,8 @@ pub(crate) fn find_all_refs(
                         .or_default()
                         .push((extra_ref.focus_or_full_range(), None));
                 }
-                let decl_range = nav.focus_or_full_range();
                 Declaration {
-                    is_mut: decl_mutability(&def, sema.parse(nav.file_id).syntax(), decl_range),
+                    is_mut: matches!(def, Definition::Local(l) if l.is_mut(sema.db)),
                     nav,
                 }
             });
@@ -189,21 +187,6 @@ pub(crate) fn find_defs<'a>(
     )
 }
 
-pub(crate) fn decl_mutability(def: &Definition, syntax: &SyntaxNode, range: TextRange) -> bool {
-    match def {
-        Definition::Local(_) | Definition::Field(_) => {}
-        _ => return false,
-    };
-
-    match find_node_at_offset::<ast::LetStmt>(syntax, range.start()) {
-        Some(stmt) if stmt.initializer().is_some() => match stmt.pat() {
-            Some(ast::Pat::IdentPat(it)) => it.mut_token().is_some(),
-            _ => false,
-        },
-        _ => false,
-    }
-}
-
 /// Filter out all non-literal usages for adt-defs
 fn retain_adt_literal_usages(
     usages: &mut UsageSearchResult,