]> git.lizzy.rs Git - rust.git/blobdiff - crates/ra_ide/src/syntax_highlighting.rs
Remove token tree from ReprKind::Other variant, expose ReprKind higher, remove debug...
[rust.git] / crates / ra_ide / src / syntax_highlighting.rs
index bfe6143ca500d99b07fb94cf9e4a0a703563b957..b82b51efda5b419215c631c0081771acdca58d29 100644 (file)
@@ -495,6 +495,7 @@ fn highlight_element(
             };
 
             match name_kind {
+                Some(NameClass::ExternCrate(_)) => HighlightTag::Module.into(),
                 Some(NameClass::Definition(def)) => {
                     highlight_name(db, def, false) | HighlightModifier::Definition
                 }
@@ -522,6 +523,7 @@ fn highlight_element(
             let possibly_unsafe = is_possibly_unsafe(&name_ref);
             match classify_name_ref(sema, &name_ref) {
                 Some(name_kind) => match name_kind {
+                    NameRefClass::ExternCrate(_) => HighlightTag::Module.into(),
                     NameRefClass::Definition(def) => {
                         if let Definition::Local(local) = &def {
                             if let Some(name) = local.name(db) {
@@ -563,6 +565,24 @@ fn highlight_element(
                 _ => h,
             }
         }
+        REF_EXPR => {
+            let ref_expr = element.into_node().and_then(ast::RefExpr::cast)?;
+            let expr = ref_expr.expr()?;
+            let field_expr = match expr {
+                ast::Expr::FieldExpr(fe) => fe,
+                _ => return None,
+            };
+
+            let expr = field_expr.expr()?;
+            let ty = sema.type_of_expr(&expr)?;
+            if !ty.is_packed(db) {
+                return None;
+            }
+
+            // FIXME account for alignment... somehow
+
+            Highlight::new(HighlightTag::Operator) | HighlightModifier::Unsafe
+        }
         p if p.is_punct() => match p {
             T![::] | T![->] | T![=>] | T![&] | T![..] | T![=] | T![@] => {
                 HighlightTag::Operator.into()
@@ -710,6 +730,7 @@ fn highlight_name(db: &RootDatabase, def: Definition, possibly_unsafe: bool) ->
                 let mut h = Highlight::new(HighlightTag::Static);
                 if s.is_mut(db) {
                     h |= HighlightModifier::Mutable;
+                    h |= HighlightModifier::Unsafe;
                 }
                 return h;
             }