From 4a84c3fb21e3357fb3b82179edd924ceeb84379a Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Wed, 19 May 2021 22:08:34 +0200 Subject: Fix unresolved attribute fallback again --- crates/hir_def/src/nameres/collector.rs | 8 ++++---- crates/hir_def/src/nameres/tests/macros.rs | 29 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 4 deletions(-) (limited to 'crates') diff --git a/crates/hir_def/src/nameres/collector.rs b/crates/hir_def/src/nameres/collector.rs index be645a25d..02ceb8d50 100644 --- a/crates/hir_def/src/nameres/collector.rs +++ b/crates/hir_def/src/nameres/collector.rs @@ -246,7 +246,7 @@ struct DefCollector<'a> { proc_macros: Vec<(Name, ProcMacroExpander)>, exports_proc_macros: bool, from_glob_import: PerNsGlobImports, - ignore_attrs_on: FxHashSet, + ignore_attrs_on: FxHashSet>, } impl DefCollector<'_> { @@ -372,9 +372,9 @@ impl DefCollector<'_> { let mut added_items = false; let unexpanded_macros = std::mem::replace(&mut self.unexpanded_macros, Vec::new()); for directive in &unexpanded_macros { - if let MacroDirectiveKind::Attr { mod_item, .. } = &directive.kind { + if let MacroDirectiveKind::Attr { ast_id, mod_item, .. } = &directive.kind { // Make sure to only add such items once. - if !self.ignore_attrs_on.insert(*mod_item) { + if !self.ignore_attrs_on.insert(ast_id.ast_id.with_value(*mod_item)) { continue; } @@ -1463,7 +1463,7 @@ impl ModCollector<'_, '_> { // We failed to resolve an attribute on this item earlier, and are falling back to treating // the item as-is. - if self.def_collector.ignore_attrs_on.contains(&mod_item) { + if self.def_collector.ignore_attrs_on.contains(&InFile::new(self.file_id, mod_item)) { return Ok(()); } diff --git a/crates/hir_def/src/nameres/tests/macros.rs b/crates/hir_def/src/nameres/tests/macros.rs index b34ba885d..6eb5f97be 100644 --- a/crates/hir_def/src/nameres/tests/macros.rs +++ b/crates/hir_def/src/nameres/tests/macros.rs @@ -706,6 +706,35 @@ fn builtin_derive_with_unresolved_attributes_fall_back() { assert_eq!(map.modules[map.root].scope.impls().len(), 1); } +#[test] +fn unresolved_attributes_fall_back_track_per_file_moditems() { + // Tests that we track per-file ModItems when ignoring an unresolved attribute. + // Just tracking the `ModItem` leads to `Foo` getting ignored. + + check( + r#" + //- /main.rs crate:main + + mod submod; + + #[unresolved] + struct Foo; + + //- /submod.rs + #[unresolved] + struct Bar; + "#, + expect![[r#" + crate + Foo: t v + submod: t + + crate::submod + Bar: t v + "#]], + ); +} + #[test] fn macro_expansion_overflow() { cov_mark::check!(macro_expansion_overflow); -- cgit v1.2.3