aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir
diff options
context:
space:
mode:
authorPaul Daniel Faria <[email protected]>2020-07-23 23:31:28 +0100
committerPaul Daniel Faria <[email protected]>2020-08-10 13:46:34 +0100
commit39fdd41df4052cef5da4876067ae28615012476b (patch)
treec6b004f63d75ad1cdd53543d0f818bf0386631b6 /crates/ra_hir
parenta6af0272f7bf129a3063cdd7096f685fc58438e6 (diff)
Return bool from is_unsafe_method_call and cleanup usages
Diffstat (limited to 'crates/ra_hir')
-rw-r--r--crates/ra_hir/src/semantics.rs38
1 files changed, 19 insertions, 19 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 {