@@ -27,7 +27,7 @@ macro_rules! lint_callback { ($cx:expr, $f:ident, $($args:expr),*) => ({
2727
2828/// Implements the AST traversal for early lint passes. `T` provides the
2929/// `check_*` methods.
30- pub struct EarlyContextAndPass < ' ecx , T : EarlyLintPass > {
30+ struct EarlyContextAndPass < ' ecx , T : EarlyLintPass > {
3131 context : EarlyContext < ' ecx > ,
3232 pass : T ,
3333}
@@ -276,36 +276,36 @@ crate::early_lint_methods!(impl_early_lint_pass, []);
276276
277277/// Early lints work on different nodes - either on the crate root, or on freshly loaded modules.
278278/// This trait generalizes over those nodes.
279- pub trait EarlyCheckNode < ' a > : Copy {
280- fn id ( self ) -> ast:: NodeId ;
281- fn attrs ( self ) -> & ' a [ ast:: Attribute ] ;
282- fn check < ' ecx , T : EarlyLintPass > ( self , cx : & mut EarlyContextAndPass < ' ecx , T > ) ;
279+ pub enum EarlyCheckNode < ' a > {
280+ CrateRoot ( & ' a ast:: Crate , & ' a [ ast:: Attribute ] ) ,
281+ LoadedMod ( ast:: NodeId , & ' a [ ast:: Attribute ] , & ' a [ Box < ast:: Item > ] ) ,
283282}
284283
285- impl < ' a > EarlyCheckNode < ' a > for ( & ' a ast:: Crate , & ' a [ ast:: Attribute ] ) {
286- fn id ( self ) -> ast:: NodeId {
287- ast:: CRATE_NODE_ID
288- }
289- fn attrs ( self ) -> & ' a [ ast:: Attribute ] {
290- self . 1
291- }
292- fn check < ' ecx , T : EarlyLintPass > ( self , cx : & mut EarlyContextAndPass < ' ecx , T > ) {
293- lint_callback ! ( cx, check_crate, self . 0 ) ;
294- ast_visit:: walk_crate ( cx, self . 0 ) ;
295- lint_callback ! ( cx, check_crate_post, self . 0 ) ;
296- }
297- }
298-
299- impl < ' a > EarlyCheckNode < ' a > for ( ast:: NodeId , & ' a [ ast:: Attribute ] , & ' a [ Box < ast:: Item > ] ) {
300- fn id ( self ) -> ast:: NodeId {
301- self . 0
284+ impl < ' a > EarlyCheckNode < ' a > {
285+ fn id ( & self ) -> ast:: NodeId {
286+ match self {
287+ EarlyCheckNode :: CrateRoot ( _crate, _attrs) => ast:: CRATE_NODE_ID ,
288+ EarlyCheckNode :: LoadedMod ( id, _attrs, _items) => * id,
289+ }
302290 }
303- fn attrs ( self ) -> & ' a [ ast:: Attribute ] {
304- self . 1
291+ fn attrs ( & self ) -> & ' a [ ast:: Attribute ] {
292+ match self {
293+ EarlyCheckNode :: CrateRoot ( _crate, attrs) => attrs,
294+ EarlyCheckNode :: LoadedMod ( _id, attrs, _items) => attrs,
295+ }
305296 }
306- fn check < ' ecx , T : EarlyLintPass > ( self , cx : & mut EarlyContextAndPass < ' ecx , T > ) {
307- walk_list ! ( cx, visit_attribute, self . 1 ) ;
308- walk_list ! ( cx, visit_item, self . 2 ) ;
297+ fn check < ' ecx , T : EarlyLintPass > ( & self , cx : & mut EarlyContextAndPass < ' ecx , T > ) {
298+ match self {
299+ EarlyCheckNode :: CrateRoot ( crate_, _attrs) => {
300+ lint_callback ! ( cx, check_crate, crate_) ;
301+ ast_visit:: walk_crate ( cx, crate_) ;
302+ lint_callback ! ( cx, check_crate_post, crate_) ;
303+ }
304+ EarlyCheckNode :: LoadedMod ( _id, attrs, items) => {
305+ walk_list ! ( cx, visit_attribute, * attrs) ;
306+ walk_list ! ( cx, visit_item, * items) ;
307+ }
308+ }
309309 }
310310}
311311
@@ -317,7 +317,7 @@ pub fn check_ast_node<'a>(
317317 registered_tools : & RegisteredTools ,
318318 lint_buffer : Option < LintBuffer > ,
319319 builtin_lints : impl EarlyLintPass + ' static ,
320- check_node : impl EarlyCheckNode < ' a > ,
320+ check_node : EarlyCheckNode < ' a > ,
321321) {
322322 let context = EarlyContext :: new (
323323 sess,
@@ -345,7 +345,7 @@ pub fn check_ast_node<'a>(
345345
346346fn check_ast_node_inner < ' a , T : EarlyLintPass > (
347347 sess : & Session ,
348- check_node : impl EarlyCheckNode < ' a > ,
348+ check_node : EarlyCheckNode < ' a > ,
349349 context : EarlyContext < ' _ > ,
350350 pass : T ,
351351) {
0 commit comments