aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_def/src/nameres
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_def/src/nameres')
-rw-r--r--crates/hir_def/src/nameres/collector.rs27
-rw-r--r--crates/hir_def/src/nameres/tests/macros.rs22
2 files changed, 35 insertions, 14 deletions
diff --git a/crates/hir_def/src/nameres/collector.rs b/crates/hir_def/src/nameres/collector.rs
index 221a5a556..be645a25d 100644
--- a/crates/hir_def/src/nameres/collector.rs
+++ b/crates/hir_def/src/nameres/collector.rs
@@ -367,6 +367,8 @@ impl DefCollector<'_> {
367 /// This improves UX when proc macros are turned off or don't work, and replicates the behavior 367 /// This improves UX when proc macros are turned off or don't work, and replicates the behavior
368 /// before we supported proc. attribute macros. 368 /// before we supported proc. attribute macros.
369 fn reseed_with_unresolved_attributes(&mut self) -> ReachedFixedPoint { 369 fn reseed_with_unresolved_attributes(&mut self) -> ReachedFixedPoint {
370 cov_mark::hit!(unresolved_attribute_fallback);
371
370 let mut added_items = false; 372 let mut added_items = false;
371 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());
372 for directive in &unexpanded_macros { 374 for directive in &unexpanded_macros {
@@ -391,7 +393,9 @@ impl DefCollector<'_> {
391 added_items = true; 393 added_items = true;
392 } 394 }
393 } 395 }
394 self.unexpanded_macros = unexpanded_macros; 396
397 // The collection above might add new unresolved macros (eg. derives), so merge the lists.
398 self.unexpanded_macros.extend(unexpanded_macros);
395 399
396 if added_items { 400 if added_items {
397 // Continue name resolution with the new data. 401 // Continue name resolution with the new data.
@@ -948,20 +952,17 @@ impl DefCollector<'_> {
948 // incrementality). 952 // incrementality).
949 let err = self.db.macro_expand_error(macro_call_id); 953 let err = self.db.macro_expand_error(macro_call_id);
950 if let Some(err) = err { 954 if let Some(err) = err {
951 if let MacroCallId::LazyMacro(id) = macro_call_id { 955 let loc: MacroCallLoc = self.db.lookup_intern_macro(macro_call_id);
952 let loc: MacroCallLoc = self.db.lookup_intern_macro(id);
953 956
954 let diag = match err { 957 let diag = match err {
955 hir_expand::ExpandError::UnresolvedProcMacro => { 958 hir_expand::ExpandError::UnresolvedProcMacro => {
956 // Missing proc macros are non-fatal, so they are handled specially. 959 // Missing proc macros are non-fatal, so they are handled specially.
957 DefDiagnostic::unresolved_proc_macro(module_id, loc.kind) 960 DefDiagnostic::unresolved_proc_macro(module_id, loc.kind)
958 } 961 }
959 _ => DefDiagnostic::macro_error(module_id, loc.kind, err.to_string()), 962 _ => DefDiagnostic::macro_error(module_id, loc.kind, err.to_string()),
960 }; 963 };
961 964
962 self.def_map.diagnostics.push(diag); 965 self.def_map.diagnostics.push(diag);
963 }
964 // FIXME: Handle eager macros.
965 } 966 }
966 967
967 // Then, fetch and process the item tree. This will reuse the expansion result from above. 968 // Then, fetch and process the item tree. This will reuse the expansion result from above.
diff --git a/crates/hir_def/src/nameres/tests/macros.rs b/crates/hir_def/src/nameres/tests/macros.rs
index c37f915ab..b34ba885d 100644
--- a/crates/hir_def/src/nameres/tests/macros.rs
+++ b/crates/hir_def/src/nameres/tests/macros.rs
@@ -686,6 +686,27 @@ pub trait Clone {}
686} 686}
687 687
688#[test] 688#[test]
689fn builtin_derive_with_unresolved_attributes_fall_back() {
690 // Tests that we still resolve derives after ignoring an unresolved attribute.
691 cov_mark::check!(unresolved_attribute_fallback);
692 let map = compute_crate_def_map(
693 r#"
694 //- /main.rs crate:main deps:core
695 use core::Clone;
696
697 #[derive(Clone)]
698 #[unresolved]
699 struct Foo;
700
701 //- /core.rs crate:core
702 #[rustc_builtin_macro]
703 pub macro Clone {}
704 "#,
705 );
706 assert_eq!(map.modules[map.root].scope.impls().len(), 1);
707}
708
709#[test]
689fn macro_expansion_overflow() { 710fn macro_expansion_overflow() {
690 cov_mark::check!(macro_expansion_overflow); 711 cov_mark::check!(macro_expansion_overflow);
691 check( 712 check(
@@ -842,7 +863,6 @@ fn collects_derive_helpers() {
842fn resolve_macro_def() { 863fn resolve_macro_def() {
843 check( 864 check(
844 r#" 865 r#"
845//- /lib.rs
846pub macro structs($($i:ident),*) { 866pub macro structs($($i:ident),*) {
847 $(struct $i { field: u32 } )* 867 $(struct $i { field: u32 } )*
848} 868}