mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-17 01:13:11 +00:00
minor: optimize
We shouldn't be looking at the source map unless we actually have diagnostics.
This commit is contained in:
parent
1b1e3de988
commit
6f0141a140
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -482,6 +482,7 @@ dependencies = [
|
|||||||
"hir_ty",
|
"hir_ty",
|
||||||
"itertools",
|
"itertools",
|
||||||
"log",
|
"log",
|
||||||
|
"once_cell",
|
||||||
"profile",
|
"profile",
|
||||||
"rustc-hash",
|
"rustc-hash",
|
||||||
"smallvec",
|
"smallvec",
|
||||||
|
@ -16,6 +16,7 @@ either = "1.5.3"
|
|||||||
arrayvec = "0.7"
|
arrayvec = "0.7"
|
||||||
itertools = "0.10.0"
|
itertools = "0.10.0"
|
||||||
smallvec = "1.4.0"
|
smallvec = "1.4.0"
|
||||||
|
once_cell = "1"
|
||||||
|
|
||||||
stdx = { path = "../stdx", version = "0.0.0" }
|
stdx = { path = "../stdx", version = "0.0.0" }
|
||||||
syntax = { path = "../syntax", version = "0.0.0" }
|
syntax = { path = "../syntax", version = "0.0.0" }
|
||||||
|
@ -73,6 +73,7 @@ use hir_ty::{
|
|||||||
};
|
};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use nameres::diagnostics::DefDiagnosticKind;
|
use nameres::diagnostics::DefDiagnosticKind;
|
||||||
|
use once_cell::unsync::Lazy;
|
||||||
use rustc_hash::FxHashSet;
|
use rustc_hash::FxHashSet;
|
||||||
use stdx::{format_to, impl_from};
|
use stdx::{format_to, impl_from};
|
||||||
use syntax::{
|
use syntax::{
|
||||||
@ -1044,7 +1045,7 @@ impl Function {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let infer = db.infer(self.id.into());
|
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 {
|
for d in &infer.diagnostics {
|
||||||
match d {
|
match d {
|
||||||
hir_ty::InferenceDiagnostic::NoSuchField { expr } => {
|
hir_ty::InferenceDiagnostic::NoSuchField { expr } => {
|
||||||
@ -1061,13 +1062,13 @@ impl Function {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for expr in hir_ty::diagnostics::missing_unsafe(db, self.id.into()) {
|
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) => {
|
Ok(in_file) => {
|
||||||
sink.push(MissingUnsafe { file: in_file.file_id, expr: in_file.value })
|
sink.push(MissingUnsafe { file: in_file.file_id, expr: in_file.value })
|
||||||
}
|
}
|
||||||
Err(SyntheticSyntax) => {
|
Err(SyntheticSyntax) => {
|
||||||
// FIXME: The `expr` was desugared, report or assert that
|
// FIXME: The `expr` was desugared, report or assert that
|
||||||
// this dosen't happen.
|
// this doesn't happen.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user