1
Fork 0

Introduce DeriveResolution.

Making this a proper struct, and giving its fields names, makes things
easier to understand.
This commit is contained in:
Nicholas Nethercote 2024-04-25 15:13:53 +10:00
parent 11e95d43ae
commit e2d2b1c698
5 changed files with 32 additions and 20 deletions

View file

@ -3,7 +3,9 @@ use crate::errors;
use rustc_ast as ast;
use rustc_ast::{GenericParamKind, ItemKind, MetaItemKind, NestedMetaItem, StmtKind};
use rustc_expand::base::{Annotatable, ExpandResult, ExtCtxt, Indeterminate, MultiItemModifier};
use rustc_expand::base::{
Annotatable, DeriveResolution, ExpandResult, ExtCtxt, Indeterminate, MultiItemModifier,
};
use rustc_feature::AttributeTemplate;
use rustc_parse::validate_attr;
use rustc_session::Session;
@ -60,7 +62,12 @@ impl MultiItemModifier for Expander {
report_path_args(sess, meta);
meta.path.clone()
})
.map(|path| (path, dummy_annotatable(), None, self.is_const))
.map(|path| DeriveResolution {
path,
item: dummy_annotatable(),
exts: None,
is_const: self.is_const,
})
.collect()
}
_ => vec![],
@ -69,15 +76,15 @@ impl MultiItemModifier for Expander {
// Do not configure or clone items unless necessary.
match &mut resolutions[..] {
[] => {}
[(_, first_item, ..), others @ ..] => {
*first_item = cfg_eval(
[first, others @ ..] => {
first.item = cfg_eval(
sess,
features,
item.clone(),
ecx.current_expansion.lint_node_id,
);
for (_, item, _, _) in others {
*item = first_item.clone();
for other in others {
other.item = first.item.clone();
}
}
}