@@ -23,7 +23,7 @@ use rustc_ast::ast::{self, FloatTy, IntTy, NodeId, UintTy};
23
23
use rustc_ast:: ast:: { Crate , CRATE_NODE_ID } ;
24
24
use rustc_ast:: ast:: { ItemKind , Path } ;
25
25
use rustc_ast:: attr;
26
- use rustc_ast:: node_id:: { NodeMap , NodeSet } ;
26
+ use rustc_ast:: node_id:: NodeMap ;
27
27
use rustc_ast:: unwrap_or;
28
28
use rustc_ast:: visit:: { self , Visitor } ;
29
29
use rustc_ast_pretty:: pprust;
@@ -253,21 +253,31 @@ impl<'a> From<&'a ast::PathSegment> for Segment {
253
253
}
254
254
}
255
255
256
- struct UsePlacementFinder {
257
- target_module : NodeId ,
256
+ struct UsePlacementFinder < ' d > {
257
+ definitions : & ' d Definitions ,
258
+ target_module : LocalDefId ,
258
259
span : Option < Span > ,
259
260
found_use : bool ,
260
261
}
261
262
262
- impl UsePlacementFinder {
263
- fn check ( krate : & Crate , target_module : NodeId ) -> ( Option < Span > , bool ) {
264
- let mut finder = UsePlacementFinder { target_module, span : None , found_use : false } ;
265
- visit:: walk_crate ( & mut finder, krate) ;
266
- ( finder. span , finder. found_use )
263
+ impl < ' d > UsePlacementFinder < ' d > {
264
+ fn check (
265
+ definitions : & ' d Definitions ,
266
+ krate : & Crate ,
267
+ target_module : DefId ,
268
+ ) -> ( Option < Span > , bool ) {
269
+ if let Some ( target_module) = target_module. as_local ( ) {
270
+ let mut finder =
271
+ UsePlacementFinder { definitions, target_module, span : None , found_use : false } ;
272
+ visit:: walk_crate ( & mut finder, krate) ;
273
+ ( finder. span , finder. found_use )
274
+ } else {
275
+ ( None , false )
276
+ }
267
277
}
268
278
}
269
279
270
- impl < ' tcx > Visitor < ' tcx > for UsePlacementFinder {
280
+ impl < ' tcx , ' d > Visitor < ' tcx > for UsePlacementFinder < ' d > {
271
281
fn visit_mod (
272
282
& mut self ,
273
283
module : & ' tcx ast:: Mod ,
@@ -278,7 +288,7 @@ impl<'tcx> Visitor<'tcx> for UsePlacementFinder {
278
288
if self . span . is_some ( ) {
279
289
return ;
280
290
}
281
- if node_id != self . target_module {
291
+ if self . definitions . local_def_id ( node_id) != self . target_module {
282
292
visit:: walk_mod ( self , module) ;
283
293
return ;
284
294
}
@@ -611,7 +621,7 @@ struct UseError<'a> {
611
621
/// Attach `use` statements for these candidates.
612
622
candidates : Vec < ImportSuggestion > ,
613
623
/// The `NodeId` of the module to place the use-statements in.
614
- node_id : NodeId ,
624
+ def_id : DefId ,
615
625
/// Whether the diagnostic should state that it's "better".
616
626
better : bool ,
617
627
/// Extra free form suggestion. Currently used to suggest new type parameter.
@@ -926,8 +936,8 @@ pub struct Resolver<'a> {
926
936
non_macro_attrs : [ Lrc < SyntaxExtension > ; 2 ] ,
927
937
local_macro_def_scopes : FxHashMap < LocalDefId , Module < ' a > > ,
928
938
ast_transform_scopes : FxHashMap < ExpnId , Module < ' a > > ,
929
- unused_macros : NodeMap < Span > ,
930
- proc_macro_stubs : NodeSet ,
939
+ unused_macros : FxHashMap < LocalDefId , ( NodeId , Span ) > ,
940
+ proc_macro_stubs : FxHashSet < LocalDefId > ,
931
941
/// Traces collected during macro resolution and validated when it's complete.
932
942
single_segment_macro_resolutions :
933
943
Vec < ( Ident , MacroKind , ParentScope < ' a > , Option < & ' a NameBinding < ' a > > ) > ,
@@ -2567,10 +2577,10 @@ impl<'a> Resolver<'a> {
2567
2577
}
2568
2578
2569
2579
fn report_with_use_injections ( & mut self , krate : & Crate ) {
2570
- for UseError { mut err, candidates, node_id , better, suggestion } in
2580
+ for UseError { mut err, candidates, def_id , better, suggestion } in
2571
2581
self . use_injections . drain ( ..)
2572
2582
{
2573
- let ( span, found_use) = UsePlacementFinder :: check ( krate, node_id ) ;
2583
+ let ( span, found_use) = UsePlacementFinder :: check ( & self . definitions , krate, def_id ) ;
2574
2584
if !candidates. is_empty ( ) {
2575
2585
diagnostics:: show_candidates ( & mut err, span, & candidates, better, found_use) ;
2576
2586
} else if let Some ( ( span, msg, sugg, appl) ) = suggestion {
0 commit comments