Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir/src/lib.rs')
-rw-r--r--crates/hir/src/lib.rs33
1 files changed, 29 insertions, 4 deletions
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs
index dc1d1efe60..cd46276747 100644
--- a/crates/hir/src/lib.rs
+++ b/crates/hir/src/lib.rs
@@ -20,12 +20,11 @@
#![cfg_attr(feature = "in-rust-tree", feature(rustc_private))]
#![recursion_limit = "512"]
-mod semantics;
-mod source_analyzer;
-
mod attrs;
mod from_id;
mod has_source;
+mod semantics;
+mod source_analyzer;
pub mod db;
pub mod diagnostics;
@@ -54,6 +53,7 @@ use hir_def::{
path::ImportAlias,
per_ns::PerNs,
resolver::{HasResolver, Resolver},
+ type_ref::TypesSourceMap,
AssocItemId, AssocItemLoc, AttrDefId, CallableDefId, ConstId, ConstParamId, CrateRootModuleId,
DefWithBodyId, EnumId, EnumVariantId, ExternCrateId, FunctionId, GenericDefId, GenericParamId,
HasModule, ImplId, InTypeConstId, ItemContainerId, LifetimeParamId, LocalFieldId, Lookup,
@@ -1802,6 +1802,25 @@ impl DefWithBody {
let krate = self.module(db).id.krate();
let (body, source_map) = db.body_with_source_map(self.into());
+ let item_tree_source_maps;
+ let outer_types_source_map = match self {
+ DefWithBody::Function(function) => {
+ let function = function.id.lookup(db.upcast()).id;
+ item_tree_source_maps = function.item_tree_with_source_map(db.upcast()).1;
+ item_tree_source_maps.function(function.value).item()
+ }
+ DefWithBody::Static(statik) => {
+ let statik = statik.id.lookup(db.upcast()).id;
+ item_tree_source_maps = statik.item_tree_with_source_map(db.upcast()).1;
+ item_tree_source_maps.statik(statik.value)
+ }
+ DefWithBody::Const(konst) => {
+ let konst = konst.id.lookup(db.upcast()).id;
+ item_tree_source_maps = konst.item_tree_with_source_map(db.upcast()).1;
+ item_tree_source_maps.konst(konst.value)
+ }
+ DefWithBody::Variant(_) | DefWithBody::InTypeConst(_) => &TypesSourceMap::EMPTY,
+ };
for (_, def_map) in body.blocks(db.upcast()) {
Module { id: def_map.module_id(DefMap::ROOT) }.diagnostics(db, acc, style_lints);
@@ -1861,7 +1880,13 @@ impl DefWithBody {
let infer = db.infer(self.into());
for d in &infer.diagnostics {
- acc.extend(AnyDiagnostic::inference_diagnostic(db, self.into(), d, &source_map));
+ acc.extend(AnyDiagnostic::inference_diagnostic(
+ db,
+ self.into(),
+ d,
+ outer_types_source_map,
+ &source_map,
+ ));
}
for (pat_or_expr, mismatch) in infer.type_mismatches() {