@@ -3,24 +3,24 @@ use crate::proc_macro_decls;
3
3
use crate :: util;
4
4
5
5
use rustc_ast:: mut_visit:: MutVisitor ;
6
- use rustc_ast:: { self as ast, visit, DUMMY_NODE_ID } ;
6
+ use rustc_ast:: { self as ast, visit} ;
7
7
use rustc_borrowck as mir_borrowck;
8
8
use rustc_codegen_ssa:: back:: link:: emit_metadata;
9
9
use rustc_codegen_ssa:: traits:: CodegenBackend ;
10
10
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 ;
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
- use rustc_lint:: LintStore ;
17
+ use rustc_lint:: { EarlyCheckNode , LintStore } ;
18
18
use rustc_metadata:: creader:: CStore ;
19
19
use rustc_metadata:: { encode_metadata, EncodedMetadata } ;
20
20
use rustc_middle:: arena:: Arena ;
21
21
use rustc_middle:: dep_graph:: DepGraph ;
22
22
use 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 } ;
24
24
use rustc_mir_build as mir_build;
25
25
use rustc_parse:: { parse_crate_from_file, parse_crate_from_source_str, validate_attr} ;
26
26
use rustc_passes:: { self , hir_stats, layout_test} ;
@@ -34,7 +34,7 @@ use rustc_session::lint;
34
34
use rustc_session:: output:: { filename_for_input, filename_for_metadata} ;
35
35
use rustc_session:: search_paths:: PathKind ;
36
36
use rustc_session:: { Limit , Session } ;
37
- use rustc_span:: symbol:: { sym, Ident , Symbol } ;
37
+ use rustc_span:: symbol:: { sym, Symbol } ;
38
38
use rustc_span:: { FileName , MultiSpan } ;
39
39
use rustc_trait_selection:: traits;
40
40
use rustc_typeck as typeck;
@@ -233,26 +233,43 @@ pub fn register_plugins<'a>(
233
233
Ok ( ( krate, lint_store) )
234
234
}
235
235
236
- fn pre_expansion_lint (
236
+ fn pre_expansion_lint < ' a > (
237
237
sess : & Session ,
238
238
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 ,
242
242
) {
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 (
245
245
sess,
246
- lint_store,
247
- krate,
248
- crate_attrs,
249
246
true ,
247
+ lint_store,
248
+ registered_tools,
250
249
None ,
251
250
rustc_lint:: BuiltinCombinedPreExpansionLintPass :: new ( ) ,
251
+ check_node,
252
252
) ;
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
@@ -265,7 +282,7 @@ pub fn configure_and_expand(
265
282
resolver : & mut Resolver < ' _ > ,
266
283
) -> Result < ast:: Crate > {
267
284
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) ;
269
286
rustc_builtin_macros:: register_builtin_macros ( resolver) ;
270
287
271
288
krate = sess. time ( "crate_injection" , || {
@@ -321,13 +338,8 @@ pub fn configure_and_expand(
321
338
..rustc_expand:: expand:: ExpansionConfig :: default ( crate_name. to_string ( ) )
322
339
} ;
323
340
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) ) ;
331
343
332
344
// Expand macros now!
333
345
let krate = sess. time ( "expand_crate" , || ecx. monotonic_expander ( ) . expand_crate ( krate) ) ;
@@ -499,14 +511,15 @@ pub fn lower_to_hir<'res, 'tcx>(
499
511
) ;
500
512
501
513
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 (
503
516
sess,
504
- lint_store,
505
- & krate,
506
- & krate. attrs ,
507
517
false ,
508
- Some ( std:: mem:: take ( resolver. lint_buffer ( ) ) ) ,
518
+ lint_store,
519
+ resolver. registered_tools ( ) ,
520
+ lint_buffer,
509
521
rustc_lint:: BuiltinCombinedEarlyLintPass :: new ( ) ,
522
+ & * krate,
510
523
)
511
524
} ) ;
512
525
0 commit comments