aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_hir/src/semantics.rs38
-rw-r--r--crates/ra_ide/src/syntax_highlighting.rs11
2 files changed, 25 insertions, 24 deletions
diff --git a/crates/ra_hir/src/semantics.rs b/crates/ra_hir/src/semantics.rs
index f706a186e..9697c7082 100644
--- a/crates/ra_hir/src/semantics.rs
+++ b/crates/ra_hir/src/semantics.rs
@@ -281,26 +281,26 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
281 self.imp.assert_contains_node(node) 281 self.imp.assert_contains_node(node)
282 } 282 }
283 283
284 pub fn is_unsafe_method_call(&self, method_call_expr: ast::MethodCallExpr) -> Option<()> { 284 pub fn is_unsafe_method_call(&self, method_call_expr: ast::MethodCallExpr) -> bool {
285 let expr = method_call_expr.expr()?; 285 method_call_expr
286 let field_expr = 286 .expr()
287 if let ast::Expr::FieldExpr(field_expr) = expr { field_expr } else { return None }; 287 .and_then(|expr| {
288 let ty = self.type_of_expr(&field_expr.expr()?)?; 288 let field_expr = if let ast::Expr::FieldExpr(field_expr) = expr {
289 if !ty.is_packed(self.db) { 289 field_expr
290 return None; 290 } else {
291 } 291 return None;
292 };
293 let ty = self.type_of_expr(&field_expr.expr()?)?;
294 if !ty.is_packed(self.db) {
295 return None;
296 }
292 297
293 let func = self.resolve_method_call(&method_call_expr)?; 298 let func = self.resolve_method_call(&method_call_expr)?;
294 if func.has_self_param(self.db) { 299 let is_unsafe = func.has_self_param(self.db)
295 let params = func.params(self.db); 300 && matches!(func.params(self.db).first(), Some(TypeRef::Reference(..)));
296 if matches!(params.into_iter().next(), Some(TypeRef::Reference(..))) { 301 Some(is_unsafe)
297 Some(()) 302 })
298 } else { 303 .unwrap_or(false)
299 None
300 }
301 } else {
302 None
303 }
304 } 304 }
305 305
306 pub fn is_unsafe_ref_expr(&self, ref_expr: &ast::RefExpr) -> bool { 306 pub fn is_unsafe_ref_expr(&self, ref_expr: &ast::RefExpr) -> bool {
diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs
index e29f65a78..4527885e9 100644
--- a/crates/ra_ide/src/syntax_highlighting.rs
+++ b/crates/ra_ide/src/syntax_highlighting.rs
@@ -730,8 +730,9 @@ fn highlight_name(
730 let is_unsafe = name_ref 730 let is_unsafe = name_ref
731 .and_then(|name_ref| name_ref.syntax().parent()) 731 .and_then(|name_ref| name_ref.syntax().parent())
732 .and_then(ast::MethodCallExpr::cast) 732 .and_then(ast::MethodCallExpr::cast)
733 .and_then(|method_call_expr| sema.is_unsafe_method_call(method_call_expr)); 733 .map(|method_call_expr| sema.is_unsafe_method_call(method_call_expr))
734 if is_unsafe.is_some() { 734 .unwrap_or(false);
735 if is_unsafe {
735 h |= HighlightModifier::Unsafe; 736 h |= HighlightModifier::Unsafe;
736 } 737 }
737 } 738 }
@@ -809,9 +810,9 @@ fn highlight_name_ref_by_syntax(name: ast::NameRef, sema: &Semantics<RootDatabas
809 METHOD_CALL_EXPR => { 810 METHOD_CALL_EXPR => {
810 let mut h = Highlight::new(HighlightTag::Function); 811 let mut h = Highlight::new(HighlightTag::Function);
811 let is_unsafe = ast::MethodCallExpr::cast(parent) 812 let is_unsafe = ast::MethodCallExpr::cast(parent)
812 .and_then(|method_call_expr| sema.is_unsafe_method_call(method_call_expr)); 813 .map(|method_call_expr| sema.is_unsafe_method_call(method_call_expr))
813 814 .unwrap_or(false);
814 if is_unsafe.is_some() { 815 if is_unsafe {
815 h |= HighlightModifier::Unsafe; 816 h |= HighlightModifier::Unsafe;
816 } 817 }
817 818