@@ -11,7 +11,7 @@ use 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 , ResolverExpand } ;
14+ use rustc_expand:: base:: { ExtCtxt , LintStoreExpand , ResolverExpand } ;
1515use rustc_hir:: def_id:: { StableCrateId , LOCAL_CRATE } ;
1616use rustc_hir:: Crate ;
1717use rustc_lint:: { EarlyCheckNode , LintStore } ;
@@ -253,6 +253,23 @@ fn pre_expansion_lint<'a>(
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
@@ -321,18 +338,8 @@ pub fn configure_and_expand(
321338 ..rustc_expand:: expand:: ExpansionConfig :: default ( crate_name. to_string ( ) )
322339 } ;
323340
324- let registered_tools = resolver. registered_tools ( ) . clone ( ) ;
325- let extern_mod_loaded = |node_id, attrs : Vec < _ > , items : Vec < _ > , name : Symbol | {
326- pre_expansion_lint (
327- sess,
328- lint_store,
329- & registered_tools,
330- ( node_id, & * attrs, & * items) ,
331- name. as_str ( ) ,
332- ) ;
333- ( attrs, items)
334- } ;
335- 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) ) ;
336343
337344 // Expand macros now!
338345 let krate = sess. time ( "expand_crate" , || ecx. monotonic_expander ( ) . expand_crate ( krate) ) ;
0 commit comments