Fix derive collection after unresolved attribute fallback
This commit is contained in:
parent
2d76b176c0
commit
274d813cff
@ -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.
|
||||
|
@ -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 } )*
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user