From 1b1e3de988ed835b9469360d584963684d1c8ff6 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 12 Jun 2021 17:41:25 +0300 Subject: minor: reduce visibility --- crates/hir_ty/src/diagnostics/unsafe_check.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/crates/hir_ty/src/diagnostics/unsafe_check.rs b/crates/hir_ty/src/diagnostics/unsafe_check.rs index a4054cef9..777f347b8 100644 --- a/crates/hir_ty/src/diagnostics/unsafe_check.rs +++ b/crates/hir_ty/src/diagnostics/unsafe_check.rs @@ -13,7 +13,6 @@ use crate::{db::HirDatabase, InferenceResult, Interner, TyExt, TyKind}; pub fn missing_unsafe(db: &dyn HirDatabase, def: DefWithBodyId) -> Vec { let infer = db.infer(def); - // let unsafe_expressions = ; let is_unsafe = match def { DefWithBodyId::FunctionId(it) => db.function_data(it).is_unsafe(), DefWithBodyId::StaticId(_) | DefWithBodyId::ConstId(_) => false, @@ -29,12 +28,12 @@ pub fn missing_unsafe(db: &dyn HirDatabase, def: DefWithBodyId) -> Vec { .collect() } -pub(crate) struct UnsafeExpr { +struct UnsafeExpr { pub(crate) expr: ExprId, pub(crate) inside_unsafe_block: bool, } -pub(crate) fn unsafe_expressions( +fn unsafe_expressions( db: &dyn HirDatabase, infer: &InferenceResult, def: DefWithBodyId, -- cgit v1.2.3 From 6f0141a14026827edfe4ef046013001acd22d94d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 12 Jun 2021 17:49:41 +0300 Subject: minor: optimize We shouldn't be looking at the source map unless we actually have diagnostics. --- Cargo.lock | 1 + crates/hir/Cargo.toml | 1 + crates/hir/src/lib.rs | 7 ++++--- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e1d2a74f0..0ffc91548 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -482,6 +482,7 @@ dependencies = [ "hir_ty", "itertools", "log", + "once_cell", "profile", "rustc-hash", "smallvec", diff --git a/crates/hir/Cargo.toml b/crates/hir/Cargo.toml index 560b15238..7c148fd40 100644 --- a/crates/hir/Cargo.toml +++ b/crates/hir/Cargo.toml @@ -16,6 +16,7 @@ either = "1.5.3" arrayvec = "0.7" itertools = "0.10.0" smallvec = "1.4.0" +once_cell = "1" stdx = { path = "../stdx", version = "0.0.0" } syntax = { path = "../syntax", version = "0.0.0" } diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index a21a9da21..8804e63c5 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -73,6 +73,7 @@ use hir_ty::{ }; use itertools::Itertools; use nameres::diagnostics::DefDiagnosticKind; +use once_cell::unsync::Lazy; use rustc_hash::FxHashSet; use stdx::{format_to, impl_from}; use syntax::{ @@ -1044,7 +1045,7 @@ impl Function { } let infer = db.infer(self.id.into()); - let (_, source_map) = db.body_with_source_map(self.id.into()); + let source_map = Lazy::new(|| db.body_with_source_map(self.id.into()).1); for d in &infer.diagnostics { match d { hir_ty::InferenceDiagnostic::NoSuchField { expr } => { @@ -1061,13 +1062,13 @@ impl Function { } for expr in hir_ty::diagnostics::missing_unsafe(db, self.id.into()) { - match source_map.as_ref().expr_syntax(expr) { + match source_map.expr_syntax(expr) { Ok(in_file) => { sink.push(MissingUnsafe { file: in_file.file_id, expr: in_file.value }) } Err(SyntheticSyntax) => { // FIXME: The `expr` was desugared, report or assert that - // this dosen't happen. + // this doesn't happen. } } } -- cgit v1.2.3