Skip to content

Commit 10ca6b2

Browse files
bors[bot]matklad
andauthored
9231: minor: optimize r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2 parents f9e67d6 + 6f0141a commit 10ca6b2

File tree

4 files changed

+8
-6
lines changed

4 files changed

+8
-6
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/hir/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ either = "1.5.3"
1616
arrayvec = "0.7"
1717
itertools = "0.10.0"
1818
smallvec = "1.4.0"
19+
once_cell = "1"
1920

2021
stdx = { path = "../stdx", version = "0.0.0" }
2122
syntax = { path = "../syntax", version = "0.0.0" }

crates/hir/src/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ use hir_ty::{
7373
};
7474
use itertools::Itertools;
7575
use nameres::diagnostics::DefDiagnosticKind;
76+
use once_cell::unsync::Lazy;
7677
use rustc_hash::FxHashSet;
7778
use stdx::{format_to, impl_from};
7879
use syntax::{
@@ -1044,7 +1045,7 @@ impl Function {
10441045
}
10451046

10461047
let infer = db.infer(self.id.into());
1047-
let (_, source_map) = db.body_with_source_map(self.id.into());
1048+
let source_map = Lazy::new(|| db.body_with_source_map(self.id.into()).1);
10481049
for d in &infer.diagnostics {
10491050
match d {
10501051
hir_ty::InferenceDiagnostic::NoSuchField { expr } => {
@@ -1061,13 +1062,13 @@ impl Function {
10611062
}
10621063

10631064
for expr in hir_ty::diagnostics::missing_unsafe(db, self.id.into()) {
1064-
match source_map.as_ref().expr_syntax(expr) {
1065+
match source_map.expr_syntax(expr) {
10651066
Ok(in_file) => {
10661067
sink.push(MissingUnsafe { file: in_file.file_id, expr: in_file.value })
10671068
}
10681069
Err(SyntheticSyntax) => {
10691070
// FIXME: The `expr` was desugared, report or assert that
1070-
// this dosen't happen.
1071+
// this doesn't happen.
10711072
}
10721073
}
10731074
}

crates/hir_ty/src/diagnostics/unsafe_check.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use crate::{db::HirDatabase, InferenceResult, Interner, TyExt, TyKind};
1313
pub fn missing_unsafe(db: &dyn HirDatabase, def: DefWithBodyId) -> Vec<ExprId> {
1414
let infer = db.infer(def);
1515

16-
// let unsafe_expressions = ;
1716
let is_unsafe = match def {
1817
DefWithBodyId::FunctionId(it) => db.function_data(it).is_unsafe(),
1918
DefWithBodyId::StaticId(_) | DefWithBodyId::ConstId(_) => false,
@@ -29,12 +28,12 @@ pub fn missing_unsafe(db: &dyn HirDatabase, def: DefWithBodyId) -> Vec<ExprId> {
2928
.collect()
3029
}
3130

32-
pub(crate) struct UnsafeExpr {
31+
struct UnsafeExpr {
3332
pub(crate) expr: ExprId,
3433
pub(crate) inside_unsafe_block: bool,
3534
}
3635

37-
pub(crate) fn unsafe_expressions(
36+
fn unsafe_expressions(
3837
db: &dyn HirDatabase,
3938
infer: &InferenceResult,
4039
def: DefWithBodyId,

0 commit comments

Comments
 (0)