@@ -23,7 +23,7 @@ use rustc_ast::ast::{self, FloatTy, IntTy, NodeId, UintTy};
2323use rustc_ast:: ast:: { Crate , CRATE_NODE_ID } ;
2424use rustc_ast:: ast:: { ItemKind , Path } ;
2525use rustc_ast:: attr;
26- use rustc_ast:: node_id:: { NodeMap , NodeSet } ;
26+ use rustc_ast:: node_id:: NodeMap ;
2727use rustc_ast:: unwrap_or;
2828use rustc_ast:: visit:: { self , Visitor } ;
2929use rustc_ast_pretty:: pprust;
@@ -253,21 +253,31 @@ impl<'a> From<&'a ast::PathSegment> for Segment {
253253 }
254254}
255255
256- struct UsePlacementFinder {
257- target_module : NodeId ,
256+ struct UsePlacementFinder < ' d > {
257+ definitions : & ' d Definitions ,
258+ target_module : LocalDefId ,
258259 span : Option < Span > ,
259260 found_use : bool ,
260261}
261262
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+ }
267277 }
268278}
269279
270- impl < ' tcx > Visitor < ' tcx > for UsePlacementFinder {
280+ impl < ' tcx , ' d > Visitor < ' tcx > for UsePlacementFinder < ' d > {
271281 fn visit_mod (
272282 & mut self ,
273283 module : & ' tcx ast:: Mod ,
@@ -278,7 +288,7 @@ impl<'tcx> Visitor<'tcx> for UsePlacementFinder {
278288 if self . span . is_some ( ) {
279289 return ;
280290 }
281- if node_id != self . target_module {
291+ if self . definitions . local_def_id ( node_id) != self . target_module {
282292 visit:: walk_mod ( self , module) ;
283293 return ;
284294 }
@@ -611,7 +621,7 @@ struct UseError<'a> {
611621 /// Attach `use` statements for these candidates.
612622 candidates : Vec < ImportSuggestion > ,
613623 /// The `NodeId` of the module to place the use-statements in.
614- node_id : NodeId ,
624+ def_id : DefId ,
615625 /// Whether the diagnostic should state that it's "better".
616626 better : bool ,
617627 /// Extra free form suggestion. Currently used to suggest new type parameter.
@@ -926,8 +936,8 @@ pub struct Resolver<'a> {
926936 non_macro_attrs : [ Lrc < SyntaxExtension > ; 2 ] ,
927937 local_macro_def_scopes : FxHashMap < LocalDefId , Module < ' a > > ,
928938 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 > ,
931941 /// Traces collected during macro resolution and validated when it's complete.
932942 single_segment_macro_resolutions :
933943 Vec < ( Ident , MacroKind , ParentScope < ' a > , Option < & ' a NameBinding < ' a > > ) > ,
@@ -2567,10 +2577,10 @@ impl<'a> Resolver<'a> {
25672577 }
25682578
25692579 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
25712581 self . use_injections . drain ( ..)
25722582 {
2573- let ( span, found_use) = UsePlacementFinder :: check ( krate, node_id ) ;
2583+ let ( span, found_use) = UsePlacementFinder :: check ( & self . definitions , krate, def_id ) ;
25742584 if !candidates. is_empty ( ) {
25752585 diagnostics:: show_candidates ( & mut err, span, & candidates, better, found_use) ;
25762586 } else if let Some ( ( span, msg, sugg, appl) ) = suggestion {
0 commit comments