Skip to content

Commit 45c24ae

Browse files
bors[bot]matklad
andauthored
Merge #5818
5818: Some trivial local simiplifications r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
2 parents a4b7ce9 + 11a1bb1 commit 45c24ae

File tree

1 file changed

+11
-19
lines changed

1 file changed

+11
-19
lines changed

crates/ide/src/syntax_highlighting.rs

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -454,18 +454,6 @@ fn macro_call_range(macro_call: &ast::MacroCall) -> Option<TextRange> {
454454
Some(TextRange::new(range_start, range_end))
455455
}
456456

457-
fn is_possibly_unsafe(name_ref: &ast::NameRef) -> bool {
458-
name_ref
459-
.syntax()
460-
.parent()
461-
.and_then(|parent| {
462-
ast::FieldExpr::cast(parent.clone())
463-
.map(|_| true)
464-
.or_else(|| ast::RecordPatField::cast(parent).map(|_| true))
465-
})
466-
.unwrap_or(false)
467-
}
468-
469457
fn highlight_element(
470458
sema: &Semantics<RootDatabase>,
471459
bindings_shadow_count: &mut FxHashMap<Name, u32>,
@@ -496,9 +484,9 @@ fn highlight_element(
496484
match name_kind {
497485
Some(NameClass::ExternCrate(_)) => HighlightTag::Module.into(),
498486
Some(NameClass::Definition(def)) => {
499-
highlight_name(sema, db, def, None, false) | HighlightModifier::Definition
487+
highlight_def(sema, db, def, None, false) | HighlightModifier::Definition
500488
}
501-
Some(NameClass::ConstReference(def)) => highlight_name(sema, db, def, None, false),
489+
Some(NameClass::ConstReference(def)) => highlight_def(sema, db, def, None, false),
502490
Some(NameClass::FieldShorthand { field, .. }) => {
503491
let mut h = HighlightTag::Field.into();
504492
if let Definition::Field(field) = field {
@@ -520,7 +508,6 @@ fn highlight_element(
520508
NAME_REF => {
521509
let name_ref = element.into_node().and_then(ast::NameRef::cast).unwrap();
522510
highlight_func_by_name_ref(sema, &name_ref).unwrap_or_else(|| {
523-
let possibly_unsafe = is_possibly_unsafe(&name_ref);
524511
match classify_name_ref(sema, &name_ref) {
525512
Some(name_kind) => match name_kind {
526513
NameRefClass::ExternCrate(_) => HighlightTag::Module.into(),
@@ -532,7 +519,13 @@ fn highlight_element(
532519
binding_hash = Some(calc_binding_hash(&name, *shadow_count))
533520
}
534521
};
535-
highlight_name(sema, db, def, Some(name_ref), possibly_unsafe)
522+
let possibly_unsafe = match name_ref.syntax().parent() {
523+
Some(parent) => {
524+
matches!(parent.kind(), FIELD_EXPR | RECORD_PAT_FIELD)
525+
}
526+
None => false,
527+
};
528+
highlight_def(sema, db, def, Some(name_ref), possibly_unsafe)
536529
}
537530
NameRefClass::FieldShorthand { .. } => HighlightTag::Field.into(),
538531
},
@@ -706,8 +699,7 @@ fn highlight_func_by_name_ref(
706699
sema: &Semantics<RootDatabase>,
707700
name_ref: &ast::NameRef,
708701
) -> Option<Highlight> {
709-
let parent = name_ref.syntax().parent()?;
710-
let method_call = ast::MethodCallExpr::cast(parent)?;
702+
let method_call = name_ref.syntax().parent().and_then(ast::MethodCallExpr::cast)?;
711703
highlight_method_call(sema, &method_call)
712704
}
713705

@@ -737,7 +729,7 @@ fn highlight_method_call(
737729
Some(h)
738730
}
739731

740-
fn highlight_name(
732+
fn highlight_def(
741733
sema: &Semantics<RootDatabase>,
742734
db: &RootDatabase,
743735
def: Definition,

0 commit comments

Comments
 (0)