aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/hir_def/src/nameres/collector.rs8
-rw-r--r--crates/hir_def/src/nameres/tests/macros.rs29
2 files changed, 33 insertions, 4 deletions
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> {
246 proc_macros: Vec<(Name, ProcMacroExpander)>, 246 proc_macros: Vec<(Name, ProcMacroExpander)>,
247 exports_proc_macros: bool, 247 exports_proc_macros: bool,
248 from_glob_import: PerNsGlobImports, 248 from_glob_import: PerNsGlobImports,
249 ignore_attrs_on: FxHashSet<ModItem>, 249 ignore_attrs_on: FxHashSet<InFile<ModItem>>,
250} 250}
251 251
252impl DefCollector<'_> { 252impl DefCollector<'_> {
@@ -372,9 +372,9 @@ impl DefCollector<'_> {
372 let mut added_items = false; 372 let mut added_items = false;
373 let unexpanded_macros = std::mem::replace(&mut self.unexpanded_macros, Vec::new()); 373 let unexpanded_macros = std::mem::replace(&mut self.unexpanded_macros, Vec::new());
374 for directive in &unexpanded_macros { 374 for directive in &unexpanded_macros {
375 if let MacroDirectiveKind::Attr { mod_item, .. } = &directive.kind { 375 if let MacroDirectiveKind::Attr { ast_id, mod_item, .. } = &directive.kind {
376 // Make sure to only add such items once. 376 // Make sure to only add such items once.
377 if !self.ignore_attrs_on.insert(*mod_item) { 377 if !self.ignore_attrs_on.insert(ast_id.ast_id.with_value(*mod_item)) {
378 continue; 378 continue;
379 } 379 }
380 380
@@ -1463,7 +1463,7 @@ impl ModCollector<'_, '_> {
1463 1463
1464 // We failed to resolve an attribute on this item earlier, and are falling back to treating 1464 // We failed to resolve an attribute on this item earlier, and are falling back to treating
1465 // the item as-is. 1465 // the item as-is.
1466 if self.def_collector.ignore_attrs_on.contains(&mod_item) { 1466 if self.def_collector.ignore_attrs_on.contains(&InFile::new(self.file_id, mod_item)) {
1467 return Ok(()); 1467 return Ok(());
1468 } 1468 }
1469 1469
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
@@ -707,6 +707,35 @@ fn builtin_derive_with_unresolved_attributes_fall_back() {
707} 707}
708 708
709#[test] 709#[test]
710fn unresolved_attributes_fall_back_track_per_file_moditems() {
711 // Tests that we track per-file ModItems when ignoring an unresolved attribute.
712 // Just tracking the `ModItem` leads to `Foo` getting ignored.
713
714 check(
715 r#"
716 //- /main.rs crate:main
717
718 mod submod;
719
720 #[unresolved]
721 struct Foo;
722
723 //- /submod.rs
724 #[unresolved]
725 struct Bar;
726 "#,
727 expect![[r#"
728 crate
729 Foo: t v
730 submod: t
731
732 crate::submod
733 Bar: t v
734 "#]],
735 );
736}
737
738#[test]
710fn macro_expansion_overflow() { 739fn macro_expansion_overflow() {
711 cov_mark::check!(macro_expansion_overflow); 740 cov_mark::check!(macro_expansion_overflow);
712 check( 741 check(