Fix derive collection after unresolved attribute fallback

This commit is contained in:
Jonas Schievink 2021-05-19 21:05:58 +02:00
parent 2d76b176c0
commit 274d813cff
2 changed files with 26 additions and 2 deletions

View File

@ -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.

View File

@ -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 } )*
}