1
Fork 0

rustc_interface: Add a new query pre_configure

It partially expands crate attributes before the main expansion pass (without modifying the crate), and the produced preliminary crate attribute list is used for querying a few attributes that are required very early.

Crate-level cfg attributes are then expanded normally during the main expansion pass, like attributes on any other nodes.
This commit is contained in:
Vadim Petrochenkov 2023-03-14 16:53:04 +04:00
parent f26da39e04
commit aca1b1e0b3
12 changed files with 108 additions and 84 deletions

View file

@ -341,7 +341,7 @@ pub trait EarlyCheckNode<'a>: Copy {
'a: 'b;
}
impl<'a> EarlyCheckNode<'a> for &'a ast::Crate {
impl<'a> EarlyCheckNode<'a> for (&'a ast::Crate, &'a [ast::Attribute]) {
fn id(self) -> ast::NodeId {
ast::CRATE_NODE_ID
}
@ -349,15 +349,15 @@ impl<'a> EarlyCheckNode<'a> for &'a ast::Crate {
where
'a: 'b,
{
&self.attrs
&self.1
}
fn check<'b, T: EarlyLintPass>(self, cx: &mut EarlyContextAndPass<'b, T>)
where
'a: 'b,
{
lint_callback!(cx, check_crate, self);
ast_visit::walk_crate(cx, self);
lint_callback!(cx, check_crate_post, self);
lint_callback!(cx, check_crate, self.0);
ast_visit::walk_crate(cx, self.0);
lint_callback!(cx, check_crate_post, self.0);
}
}