diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 3b479356f8..500b34c170 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs @@ -7,7 +7,6 @@ use hir_def::{ builtin_type::BuiltinType, docs::Documentation, expr::{BindingAnnotation, Pat, PatId}, - nameres::ModuleSource, per_ns::PerNs, resolver::HasResolver, type_ref::{Mutability, TypeRef}, @@ -193,13 +192,14 @@ impl Module { pub fn diagnostics(self, db: &impl HirDatabase, sink: &mut DiagnosticSink) { let _p = profile("Module::diagnostics"); - db.crate_def_map(self.id.krate).add_diagnostics(db, self.id.local_id, sink); + let crate_def_map = db.crate_def_map(self.id.krate); + crate_def_map.add_diagnostics(db, self.id.local_id, sink); for decl in self.declarations(db) { match decl { crate::ModuleDef::Function(f) => f.diagnostics(db, sink), crate::ModuleDef::Module(m) => { // Only add diagnostics from inline modules - if let ModuleSource::Module(_) = m.definition_source(db).value { + if crate_def_map[m.id.local_id].origin.is_inline() { m.diagnostics(db, sink) } } diff --git a/crates/ra_hir_def/src/nameres.rs b/crates/ra_hir_def/src/nameres.rs index 4d210eab12..e1a6a46df2 100644 --- a/crates/ra_hir_def/src/nameres.rs +++ b/crates/ra_hir_def/src/nameres.rs @@ -145,6 +145,13 @@ impl ModuleOrigin { } } + pub fn is_inline(&self) -> bool { + match self { + ModuleOrigin::Inline { .. } => true, + ModuleOrigin::CrateRoot { .. } | ModuleOrigin::File { .. } => false, + } + } + /// Returns a node which defines this module. /// That is, a file or a `mod foo {}` with items. fn definition_source(&self, db: &impl DefDatabase) -> InFile {