diff options
author | Paul Daniel Faria <[email protected]> | 2020-07-23 23:31:28 +0100 |
---|---|---|
committer | Paul Daniel Faria <[email protected]> | 2020-08-10 13:46:34 +0100 |
commit | 39fdd41df4052cef5da4876067ae28615012476b (patch) | |
tree | c6b004f63d75ad1cdd53543d0f818bf0386631b6 | |
parent | a6af0272f7bf129a3063cdd7096f685fc58438e6 (diff) |
Return bool from is_unsafe_method_call and cleanup usages
-rw-r--r-- | crates/ra_hir/src/semantics.rs | 38 | ||||
-rw-r--r-- | crates/ra_ide/src/syntax_highlighting.rs | 11 |
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 | ||