9231: minor: optimize r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
bors[bot] 2021-06-12 14:50:37 +00:00 committed by GitHub
commit 10ca6b286c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 8 additions and 6 deletions

1
Cargo.lock generated
View File

@ -482,6 +482,7 @@ dependencies = [
"hir_ty",
"itertools",
"log",
"once_cell",
"profile",
"rustc-hash",
"smallvec",

View File

@ -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" }

View File

@ -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.
}
}
}

View File

@ -13,7 +13,6 @@ use crate::{db::HirDatabase, InferenceResult, Interner, TyExt, TyKind};
pub fn missing_unsafe(db: &dyn HirDatabase, def: DefWithBodyId) -> Vec<ExprId> {
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<ExprId> {
.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,