Skip to content

Commit 6f0141a

Browse files
committed
minor: optimize
We shouldn't be looking at the source map unless we actually have diagnostics.
1 parent 1b1e3de commit 6f0141a

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
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
}

0 commit comments

Comments
 (0)