From ea8555b1552f6c08043f84885e47a196320da376 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Wed, 19 May 2021 20:19:08 +0200 Subject: Simplify eager macro representation --- crates/hir_def/src/nameres/collector.rs | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'crates/hir_def/src/nameres') diff --git a/crates/hir_def/src/nameres/collector.rs b/crates/hir_def/src/nameres/collector.rs index 221a5a556..0e741194b 100644 --- a/crates/hir_def/src/nameres/collector.rs +++ b/crates/hir_def/src/nameres/collector.rs @@ -948,20 +948,17 @@ impl DefCollector<'_> { // incrementality). let err = self.db.macro_expand_error(macro_call_id); if let Some(err) = err { - if let MacroCallId::LazyMacro(id) = macro_call_id { - let loc: MacroCallLoc = self.db.lookup_intern_macro(id); + let loc: MacroCallLoc = self.db.lookup_intern_macro(macro_call_id); - let diag = match err { - hir_expand::ExpandError::UnresolvedProcMacro => { - // Missing proc macros are non-fatal, so they are handled specially. - DefDiagnostic::unresolved_proc_macro(module_id, loc.kind) - } - _ => DefDiagnostic::macro_error(module_id, loc.kind, err.to_string()), - }; + let diag = match err { + hir_expand::ExpandError::UnresolvedProcMacro => { + // Missing proc macros are non-fatal, so they are handled specially. + DefDiagnostic::unresolved_proc_macro(module_id, loc.kind) + } + _ => DefDiagnostic::macro_error(module_id, loc.kind, err.to_string()), + }; - self.def_map.diagnostics.push(diag); - } - // FIXME: Handle eager macros. + self.def_map.diagnostics.push(diag); } // Then, fetch and process the item tree. This will reuse the expansion result from above. -- cgit v1.2.3 From 274d813cff34576d3fe9d343e73669385214d3c3 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Wed, 19 May 2021 21:05:58 +0200 Subject: Fix derive collection after unresolved attribute fallback --- crates/hir_def/src/nameres/collector.rs | 6 +++++- crates/hir_def/src/nameres/tests/macros.rs | 22 +++++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) (limited to 'crates/hir_def/src/nameres') diff --git a/crates/hir_def/src/nameres/collector.rs b/crates/hir_def/src/nameres/collector.rs index 221a5a556..54e9c8d20 100644 --- a/crates/hir_def/src/nameres/collector.rs +++ b/crates/hir_def/src/nameres/collector.rs @@ -367,6 +367,8 @@ impl DefCollector<'_> { /// This improves UX when proc macros are turned off or don't work, and replicates the behavior /// before we supported proc. attribute macros. fn reseed_with_unresolved_attributes(&mut self) -> ReachedFixedPoint { + cov_mark::hit!(unresolved_attribute_fallback); + let mut added_items = false; let unexpanded_macros = std::mem::replace(&mut self.unexpanded_macros, Vec::new()); for directive in &unexpanded_macros { @@ -391,7 +393,9 @@ impl DefCollector<'_> { added_items = true; } } - self.unexpanded_macros = unexpanded_macros; + + // The collection above might add new unresolved macros (eg. derives), so merge the lists. + self.unexpanded_macros.extend(unexpanded_macros); if added_items { // Continue name resolution with the new data. 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 @@ -685,6 +685,27 @@ pub trait Clone {} ); } +#[test] +fn builtin_derive_with_unresolved_attributes_fall_back() { + // Tests that we still resolve derives after ignoring an unresolved attribute. + cov_mark::check!(unresolved_attribute_fallback); + let map = compute_crate_def_map( + r#" + //- /main.rs crate:main deps:core + use core::Clone; + + #[derive(Clone)] + #[unresolved] + struct Foo; + + //- /core.rs crate:core + #[rustc_builtin_macro] + pub macro Clone {} + "#, + ); + assert_eq!(map.modules[map.root].scope.impls().len(), 1); +} + #[test] fn macro_expansion_overflow() { cov_mark::check!(macro_expansion_overflow); @@ -842,7 +863,6 @@ fn collects_derive_helpers() { fn resolve_macro_def() { check( r#" -//- /lib.rs pub macro structs($($i:ident),*) { $(struct $i { field: u32 } )* } -- cgit v1.2.3