aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty/src/expr.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_ty/src/expr.rs')
-rw-r--r--crates/ra_hir_ty/src/expr.rs24
1 files changed, 23 insertions, 1 deletions
diff --git a/crates/ra_hir_ty/src/expr.rs b/crates/ra_hir_ty/src/expr.rs
index 7db928dde..795f1762c 100644
--- a/crates/ra_hir_ty/src/expr.rs
+++ b/crates/ra_hir_ty/src/expr.rs
@@ -2,7 +2,7 @@
2 2
3use std::sync::Arc; 3use std::sync::Arc;
4 4
5use hir_def::{path::path, resolver::HasResolver, AdtId, FunctionId}; 5use hir_def::{path::path, resolver::HasResolver, AdtId, DefWithBodyId, FunctionId};
6use hir_expand::diagnostics::DiagnosticSink; 6use hir_expand::diagnostics::DiagnosticSink;
7use ra_syntax::{ast, AstPtr}; 7use ra_syntax::{ast, AstPtr};
8use rustc_hash::FxHashSet; 8use rustc_hash::FxHashSet;
@@ -312,3 +312,25 @@ pub fn record_pattern_missing_fields(
312 } 312 }
313 Some((variant_def, missed_fields, exhaustive)) 313 Some((variant_def, missed_fields, exhaustive))
314} 314}
315
316pub fn unsafe_expressions(
317 db: &dyn HirDatabase,
318 infer: &InferenceResult,
319 def: DefWithBodyId,
320) -> Vec<ExprId> {
321 let mut unsafe_expr_ids = vec![];
322 let body = db.body(def);
323 for (id, expr) in body.exprs.iter() {
324 if let Expr::Call { callee, .. } = expr {
325 if infer
326 .method_resolution(*callee)
327 .map(|func| db.function_data(func).is_unsafe)
328 .unwrap_or(false)
329 {
330 unsafe_expr_ids.push(id);
331 }
332 }
333 }
334
335 unsafe_expr_ids
336}