Skip to content

Commit

Permalink
Auto merge of rust-lang#16369 - Veykril:simplify, r=Veykril
Browse files Browse the repository at this point in the history
minor: Simplify
  • Loading branch information
bors committed Jan 16, 2024
2 parents 0a8c784 + 6584e63 commit e7a8d21
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 23 deletions.
9 changes: 4 additions & 5 deletions crates/ide/src/highlight_related.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
}
}
Expand Down Expand Up @@ -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>> {
Expand Down Expand Up @@ -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 }
});
Expand Down
19 changes: 1 addition & 18 deletions crates/ide/src/references.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*,
Expand Down Expand Up @@ -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,
}
});
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit e7a8d21

Please sign in to comment.