@@ -3,24 +3,24 @@ use crate::proc_macro_decls;
33use crate :: util;
44
55use rustc_ast:: mut_visit:: MutVisitor ;
6- use rustc_ast:: { self as ast, visit, DUMMY_NODE_ID } ;
6+ use rustc_ast:: { self as ast, visit} ;
77use rustc_borrowck as mir_borrowck;
88use rustc_codegen_ssa:: back:: link:: emit_metadata;
99use rustc_codegen_ssa:: traits:: CodegenBackend ;
1010use rustc_data_structures:: parallel;
1111use rustc_data_structures:: sync:: { Lrc , OnceCell , WorkerLocal } ;
1212use rustc_data_structures:: temp_dir:: MaybeTempDir ;
1313use rustc_errors:: { Applicability , ErrorReported , PResult } ;
14- use rustc_expand:: base:: ExtCtxt ;
14+ use rustc_expand:: base:: { ExtCtxt , LintStoreExpand , ResolverExpand } ;
1515use rustc_hir:: def_id:: { StableCrateId , LOCAL_CRATE } ;
1616use rustc_hir:: Crate ;
17- use rustc_lint:: LintStore ;
17+ use rustc_lint:: { EarlyCheckNode , LintStore } ;
1818use rustc_metadata:: creader:: CStore ;
1919use rustc_metadata:: { encode_metadata, EncodedMetadata } ;
2020use rustc_middle:: arena:: Arena ;
2121use rustc_middle:: dep_graph:: DepGraph ;
2222use rustc_middle:: ty:: query:: { ExternProviders , Providers } ;
23- use rustc_middle:: ty:: { self , GlobalCtxt , ResolverOutputs , TyCtxt } ;
23+ use rustc_middle:: ty:: { self , GlobalCtxt , RegisteredTools , ResolverOutputs , TyCtxt } ;
2424use rustc_mir_build as mir_build;
2525use rustc_parse:: { parse_crate_from_file, parse_crate_from_source_str, validate_attr} ;
2626use rustc_passes:: { self , hir_stats, layout_test} ;
@@ -34,7 +34,7 @@ use rustc_session::lint;
3434use rustc_session:: output:: { filename_for_input, filename_for_metadata} ;
3535use rustc_session:: search_paths:: PathKind ;
3636use rustc_session:: { Limit , Session } ;
37- use rustc_span:: symbol:: { sym, Ident , Symbol } ;
37+ use rustc_span:: symbol:: { sym, Symbol } ;
3838use rustc_span:: { FileName , MultiSpan } ;
3939use rustc_trait_selection:: traits;
4040use rustc_typeck as typeck;
@@ -233,26 +233,43 @@ pub fn register_plugins<'a>(
233233 Ok ( ( krate, lint_store) )
234234}
235235
236- fn pre_expansion_lint (
236+ fn pre_expansion_lint < ' a > (
237237 sess : & Session ,
238238 lint_store : & LintStore ,
239- krate : & ast :: Crate ,
240- crate_attrs : & [ ast :: Attribute ] ,
241- crate_name : & str ,
239+ registered_tools : & RegisteredTools ,
240+ check_node : impl EarlyCheckNode < ' a > ,
241+ node_name : & str ,
242242) {
243- sess. prof . generic_activity_with_arg ( "pre_AST_expansion_lint_checks" , crate_name ) . run ( || {
244- rustc_lint:: check_ast_crate (
243+ sess. prof . generic_activity_with_arg ( "pre_AST_expansion_lint_checks" , node_name ) . run ( || {
244+ rustc_lint:: check_ast_node (
245245 sess,
246- lint_store,
247- krate,
248- crate_attrs,
249246 true ,
247+ lint_store,
248+ registered_tools,
250249 None ,
251250 rustc_lint:: BuiltinCombinedPreExpansionLintPass :: new ( ) ,
251+ check_node,
252252 ) ;
253253 } ) ;
254254}
255255
256+ // Cannot implement directly for `LintStore` due to trait coherence.
257+ struct LintStoreExpandImpl < ' a > ( & ' a LintStore ) ;
258+
259+ impl LintStoreExpand for LintStoreExpandImpl < ' _ > {
260+ fn pre_expansion_lint (
261+ & self ,
262+ sess : & Session ,
263+ registered_tools : & RegisteredTools ,
264+ node_id : ast:: NodeId ,
265+ attrs : & [ ast:: Attribute ] ,
266+ items : & [ rustc_ast:: ptr:: P < ast:: Item > ] ,
267+ name : & str ,
268+ ) {
269+ pre_expansion_lint ( sess, self . 0 , registered_tools, ( node_id, attrs, items) , name) ;
270+ }
271+ }
272+
256273/// Runs the "early phases" of the compiler: initial `cfg` processing, loading compiler plugins,
257274/// syntax expansion, secondary `cfg` expansion, synthesis of a test
258275/// harness if one is to be provided, injection of a dependency on the
@@ -265,7 +282,7 @@ pub fn configure_and_expand(
265282 resolver : & mut Resolver < ' _ > ,
266283) -> Result < ast:: Crate > {
267284 tracing:: trace!( "configure_and_expand" ) ;
268- pre_expansion_lint ( sess, lint_store, & krate , & krate. attrs , crate_name) ;
285+ pre_expansion_lint ( sess, lint_store, resolver . registered_tools ( ) , & krate, crate_name) ;
269286 rustc_builtin_macros:: register_builtin_macros ( resolver) ;
270287
271288 krate = sess. time ( "crate_injection" , || {
@@ -321,13 +338,8 @@ pub fn configure_and_expand(
321338 ..rustc_expand:: expand:: ExpansionConfig :: default ( crate_name. to_string ( ) )
322339 } ;
323340
324- let crate_attrs = krate. attrs . clone ( ) ;
325- let extern_mod_loaded = |ident : Ident , attrs, items, span| {
326- let krate = ast:: Crate { attrs, items, span, id : DUMMY_NODE_ID , is_placeholder : false } ;
327- pre_expansion_lint ( sess, lint_store, & krate, & crate_attrs, ident. name . as_str ( ) ) ;
328- ( krate. attrs , krate. items )
329- } ;
330- let mut ecx = ExtCtxt :: new ( sess, cfg, resolver, Some ( & extern_mod_loaded) ) ;
341+ let lint_store = LintStoreExpandImpl ( lint_store) ;
342+ let mut ecx = ExtCtxt :: new ( sess, cfg, resolver, Some ( & lint_store) ) ;
331343
332344 // Expand macros now!
333345 let krate = sess. time ( "expand_crate" , || ecx. monotonic_expander ( ) . expand_crate ( krate) ) ;
@@ -499,14 +511,15 @@ pub fn lower_to_hir<'res, 'tcx>(
499511 ) ;
500512
501513 sess. time ( "early_lint_checks" , || {
502- rustc_lint:: check_ast_crate (
514+ let lint_buffer = Some ( std:: mem:: take ( resolver. lint_buffer ( ) ) ) ;
515+ rustc_lint:: check_ast_node (
503516 sess,
504- lint_store,
505- & krate,
506- & krate. attrs ,
507517 false ,
508- Some ( std:: mem:: take ( resolver. lint_buffer ( ) ) ) ,
518+ lint_store,
519+ resolver. registered_tools ( ) ,
520+ lint_buffer,
509521 rustc_lint:: BuiltinCombinedEarlyLintPass :: new ( ) ,
522+ & * krate,
510523 )
511524 } ) ;
512525
0 commit comments