Skip to content

Commit 6b950d2

Browse files
author
Anatol Liu
committed
Add static semantic token modifier for associated functions with no &self
refactor logic into code_model.rs address comments
1 parent 90031a2 commit 6b950d2

File tree

2 files changed

+3
-16
lines changed

2 files changed

+3
-16
lines changed

crates/hir/src/code_model.rs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ use rustc_hash::FxHashSet;
4141
use stdx::impl_from;
4242
use syntax::{
4343
ast::{self, AttrsOwner, NameOwner},
44-
AstNode, SmolStr, SyntaxKind,
44+
AstNode, SmolStr,
4545
};
4646
use tt::{Ident, Leaf, Literal, TokenTree};
4747

@@ -787,19 +787,6 @@ impl Function {
787787
pub fn has_body(self, db: &dyn HirDatabase) -> bool {
788788
db.function_data(self.id).has_body
789789
}
790-
791-
/// whether this function is associated with some trait/impl
792-
pub fn is_assoc_item(self, db: &dyn HirDatabase) -> bool {
793-
let fn_parent_kind = self
794-
.source(db)
795-
.value
796-
.syntax()
797-
.parent()
798-
.and_then(|s| s.parent())
799-
.and_then(|s| Some(s.kind()));
800-
801-
matches!(fn_parent_kind, Some(SyntaxKind::IMPL) | Some(SyntaxKind::TRAIT))
802-
}
803790
}
804791

805792
// Note: logically, this belongs to `hir_ty`, but we are not using it there yet.

crates/ide/src/syntax_highlighting.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pub(crate) mod tags;
66
#[cfg(test)]
77
mod tests;
88

9-
use hir::{Local, Name, Semantics, VariantDef};
9+
use hir::{AsAssocItem, Local, Name, Semantics, VariantDef};
1010
use ide_db::{
1111
defs::{Definition, NameClass, NameRefClass},
1212
RootDatabase,
@@ -746,7 +746,7 @@ fn highlight_def(db: &RootDatabase, def: Definition) -> Highlight {
746746
if func.is_unsafe(db) {
747747
h |= HighlightModifier::Unsafe;
748748
}
749-
if func.is_assoc_item(db) && func.self_param(db).is_none() {
749+
if func.as_assoc_item(db).is_some() && func.self_param(db).is_none() {
750750
h |= HighlightModifier::Static;
751751
}
752752
return h;

0 commit comments

Comments
 (0)