@@ -11,7 +11,7 @@ use rustc_data_structures::parallel;
11
11
use rustc_data_structures:: sync:: { Lrc , OnceCell , WorkerLocal } ;
12
12
use rustc_data_structures:: temp_dir:: MaybeTempDir ;
13
13
use rustc_errors:: { Applicability , ErrorReported , PResult } ;
14
- use rustc_expand:: base:: { ExtCtxt , ResolverExpand } ;
14
+ use rustc_expand:: base:: { ExtCtxt , LintStoreExpand , ResolverExpand } ;
15
15
use rustc_hir:: def_id:: { StableCrateId , LOCAL_CRATE } ;
16
16
use rustc_hir:: Crate ;
17
17
use rustc_lint:: { EarlyCheckNode , LintStore } ;
@@ -253,6 +253,23 @@ fn pre_expansion_lint<'a>(
253
253
} ) ;
254
254
}
255
255
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
+
256
273
/// Runs the "early phases" of the compiler: initial `cfg` processing, loading compiler plugins,
257
274
/// syntax expansion, secondary `cfg` expansion, synthesis of a test
258
275
/// harness if one is to be provided, injection of a dependency on the
@@ -321,18 +338,8 @@ pub fn configure_and_expand(
321
338
..rustc_expand:: expand:: ExpansionConfig :: default ( crate_name. to_string ( ) )
322
339
} ;
323
340
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) ) ;
336
343
337
344
// Expand macros now!
338
345
let krate = sess. time ( "expand_crate" , || ecx. monotonic_expander ( ) . expand_crate ( krate) ) ;
0 commit comments