@@ -5,7 +5,8 @@ use std::ops::ControlFlow;
55use itertools:: Itertools as _;
66use rustc_ast:: visit:: { self , Visitor } ;
77use rustc_ast:: {
8- self as ast, CRATE_NODE_ID , Crate , ItemKind , ModKind , NodeId , Path , join_path_idents,
8+ self as ast, CRATE_NODE_ID , Crate , DUMMY_NODE_ID , ItemKind , ModKind , NodeId , Path ,
9+ join_path_idents,
910} ;
1011use rustc_ast_pretty:: pprust;
1112use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
@@ -192,11 +193,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
192193 }
193194
194195 fn report_with_use_injections ( & mut self , krate : & Crate ) {
195- for UseError { mut err, candidates, def_id , instead, suggestion, path, is_call } in
196+ for UseError { mut err, candidates, node_id , instead, suggestion, path, is_call } in
196197 mem:: take ( & mut self . use_injections )
197198 {
198- let ( span, found_use) = if let Some ( def_id ) = def_id . as_local ( ) {
199- UsePlacementFinder :: check ( krate, self . def_id_to_node_id ( def_id ) )
199+ let ( span, found_use) = if node_id != DUMMY_NODE_ID {
200+ UsePlacementFinder :: check ( krate, node_id )
200201 } else {
201202 ( None , FoundUse :: No )
202203 } ;
@@ -242,7 +243,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
242243 let container = match old_binding. parent_module . unwrap ( ) . kind {
243244 // Avoid using TyCtxt::def_kind_descr in the resolver, because it
244245 // indirectly *calls* the resolver, and would cause a query cycle.
245- ModuleKind :: Def ( kind, def_id, _) => kind. descr ( def_id) ,
246+ ModuleKind :: Def ( kind, def_id, _, _ ) => kind. descr ( def_id) ,
246247 ModuleKind :: Block => "block" ,
247248 } ;
248249
@@ -1705,9 +1706,9 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
17051706
17061707 let import_suggestions =
17071708 self . lookup_import_candidates ( ident, Namespace :: MacroNS , parent_scope, is_expected) ;
1708- let ( span, found_use) = match parent_scope. module . nearest_parent_mod ( ) . as_local ( ) {
1709- Some ( def_id ) => UsePlacementFinder :: check ( krate , self . def_id_to_node_id ( def_id ) ) ,
1710- None => ( None , FoundUse :: No ) ,
1709+ let ( span, found_use) = match parent_scope. module . nearest_parent_mod_node_id ( ) {
1710+ DUMMY_NODE_ID => ( None , FoundUse :: No ) ,
1711+ node_id => UsePlacementFinder :: check ( krate , node_id ) ,
17111712 } ;
17121713 show_candidates (
17131714 self . tcx ,
@@ -1764,7 +1765,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
17641765 }
17651766
17661767 if ident. name == kw:: Default
1767- && let ModuleKind :: Def ( DefKind :: Enum , def_id, _) = parent_scope. module . kind
1768+ && let ModuleKind :: Def ( DefKind :: Enum , def_id, _, _ ) = parent_scope. module . kind
17681769 {
17691770 let span = self . def_span ( def_id) ;
17701771 let source_map = self . tcx . sess . source_map ( ) ;
@@ -1892,19 +1893,19 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
18921893 missing a `derive` attribute",
18931894 ident. name,
18941895 ) ;
1895- let sugg_span = if let ModuleKind :: Def ( DefKind :: Enum , id, _) = parent_scope. module . kind
1896- {
1897- let span = self . def_span ( id) ;
1898- if span. from_expansion ( ) {
1899- None
1896+ let sugg_span =
1897+ if let ModuleKind :: Def ( DefKind :: Enum , id, _, _) = parent_scope. module . kind {
1898+ let span = self . def_span ( id) ;
1899+ if span. from_expansion ( ) {
1900+ None
1901+ } else {
1902+ // For enum variants sugg_span is empty but we can get the enum's Span.
1903+ Some ( span. shrink_to_lo ( ) )
1904+ }
19001905 } else {
1901- // For enum variants sugg_span is empty but we can get the enum's Span.
1902- Some ( span. shrink_to_lo ( ) )
1903- }
1904- } else {
1905- // For items this `Span` will be populated, everything else it'll be None.
1906- sugg_span
1907- } ;
1906+ // For items this `Span` will be populated, everything else it'll be None.
1907+ sugg_span
1908+ } ;
19081909 match sugg_span {
19091910 Some ( span) => {
19101911 err. span_suggestion_verbose (
0 commit comments