1
Fork 0

rustc_lint: Stop creating a fake ast::Crate for running early lints

Add a trait generalizing over the crate root and freshly loaded modules instead
This also makes node IDs used for pre-expansion linting more precise
This commit is contained in:
Vadim Petrochenkov 2021-12-07 18:28:12 +08:00
parent 9c70b6d11b
commit 05cd75504b
5 changed files with 85 additions and 26 deletions

View file

@ -959,8 +959,9 @@ pub struct ExpansionData {
pub is_trailing_mac: bool,
}
type OnExternModLoaded<'a> =
Option<&'a dyn Fn(Ident, Vec<Attribute>, Vec<P<Item>>, Span) -> (Vec<Attribute>, Vec<P<Item>>)>;
type OnExternModLoaded<'a> = Option<
&'a dyn Fn(NodeId, Vec<Attribute>, Vec<P<Item>>, Symbol) -> (Vec<Attribute>, Vec<P<Item>>),
>;
/// One of these is made during expansion and incrementally updated as we go;
/// when a macro expansion occurs, the resulting nodes have the `backtrace()

View file

@ -1108,7 +1108,12 @@ impl InvocationCollectorNode for P<ast::Item> {
);
if let Some(extern_mod_loaded) = ecx.extern_mod_loaded {
(attrs, items) = extern_mod_loaded(ident, attrs, items, inner_span);
(attrs, items) = extern_mod_loaded(
ecx.current_expansion.lint_node_id,
attrs,
items,
ident.name,
);
}
*mod_kind = ModKind::Loaded(items, Inline::No, inner_span);