aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ide/src/syntax_highlighting.rs30
1 files changed, 11 insertions, 19 deletions
diff --git a/crates/ide/src/syntax_highlighting.rs b/crates/ide/src/syntax_highlighting.rs
index 5521fd2b1..ad49f8e17 100644
--- a/crates/ide/src/syntax_highlighting.rs
+++ b/crates/ide/src/syntax_highlighting.rs
@@ -454,18 +454,6 @@ fn macro_call_range(macro_call: &ast::MacroCall) -> Option<TextRange> {
454 Some(TextRange::new(range_start, range_end)) 454 Some(TextRange::new(range_start, range_end))
455} 455}
456 456
457fn 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
469fn highlight_element( 457fn highlight_element(
470 sema: &Semantics<RootDatabase>, 458 sema: &Semantics<RootDatabase>,
471 bindings_shadow_count: &mut FxHashMap<Name, u32>, 459 bindings_shadow_count: &mut FxHashMap<Name, u32>,
@@ -496,9 +484,9 @@ fn highlight_element(
496 match name_kind { 484 match name_kind {
497 Some(NameClass::ExternCrate(_)) => HighlightTag::Module.into(), 485 Some(NameClass::ExternCrate(_)) => HighlightTag::Module.into(),
498 Some(NameClass::Definition(def)) => { 486 Some(NameClass::Definition(def)) => {
499 highlight_name(sema, db, def, None, false) | HighlightModifier::Definition 487 highlight_def(sema, db, def, None, false) | HighlightModifier::Definition
500 } 488 }
501 Some(NameClass::ConstReference(def)) => highlight_name(sema, db, def, None, false), 489 Some(NameClass::ConstReference(def)) => highlight_def(sema, db, def, None, false),
502 Some(NameClass::FieldShorthand { field, .. }) => { 490 Some(NameClass::FieldShorthand { field, .. }) => {
503 let mut h = HighlightTag::Field.into(); 491 let mut h = HighlightTag::Field.into();
504 if let Definition::Field(field) = field { 492 if let Definition::Field(field) = field {
@@ -520,7 +508,6 @@ fn highlight_element(
520 NAME_REF => { 508 NAME_REF => {
521 let name_ref = element.into_node().and_then(ast::NameRef::cast).unwrap(); 509 let name_ref = element.into_node().and_then(ast::NameRef::cast).unwrap();
522 highlight_func_by_name_ref(sema, &name_ref).unwrap_or_else(|| { 510 highlight_func_by_name_ref(sema, &name_ref).unwrap_or_else(|| {
523 let possibly_unsafe = is_possibly_unsafe(&name_ref);
524 match classify_name_ref(sema, &name_ref) { 511 match classify_name_ref(sema, &name_ref) {
525 Some(name_kind) => match name_kind { 512 Some(name_kind) => match name_kind {
526 NameRefClass::ExternCrate(_) => HighlightTag::Module.into(), 513 NameRefClass::ExternCrate(_) => HighlightTag::Module.into(),
@@ -532,7 +519,13 @@ fn highlight_element(
532 binding_hash = Some(calc_binding_hash(&name, *shadow_count)) 519 binding_hash = Some(calc_binding_hash(&name, *shadow_count))
533 } 520 }
534 }; 521 };
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)
536 } 529 }
537 NameRefClass::FieldShorthand { .. } => HighlightTag::Field.into(), 530 NameRefClass::FieldShorthand { .. } => HighlightTag::Field.into(),
538 }, 531 },
@@ -706,8 +699,7 @@ fn highlight_func_by_name_ref(
706 sema: &Semantics<RootDatabase>, 699 sema: &Semantics<RootDatabase>,
707 name_ref: &ast::NameRef, 700 name_ref: &ast::NameRef,
708) -> Option<Highlight> { 701) -> Option<Highlight> {
709 let parent = name_ref.syntax().parent()?; 702 let method_call = name_ref.syntax().parent().and_then(ast::MethodCallExpr::cast)?;
710 let method_call = ast::MethodCallExpr::cast(parent)?;
711 highlight_method_call(sema, &method_call) 703 highlight_method_call(sema, &method_call)
712} 704}
713 705
@@ -737,7 +729,7 @@ fn highlight_method_call(
737 Some(h) 729 Some(h)
738} 730}
739 731
740fn highlight_name( 732fn highlight_def(
741 sema: &Semantics<RootDatabase>, 733 sema: &Semantics<RootDatabase>,
742 db: &RootDatabase, 734 db: &RootDatabase,
743 def: Definition, 735 def: Definition,