@@ -543,7 +543,7 @@ enum ModuleKind {
543543 /// The crate root will have `None` for the symbol.
544544 /// * A trait or an enum (it implicitly contains associated types, methods and variant
545545 /// constructors).
546- Def ( DefKind , DefId , Option < Symbol > ) ,
546+ Def ( DefKind , DefId , NodeId , Option < Symbol > ) ,
547547}
548548
549549impl ModuleKind {
@@ -557,7 +557,7 @@ impl ModuleKind {
557557
558558 fn opt_def_id ( & self ) -> Option < DefId > {
559559 match self {
560- ModuleKind :: Def ( _, def_id, _) => Some ( * def_id) ,
560+ ModuleKind :: Def ( _, def_id, _, _ ) => Some ( * def_id) ,
561561 _ => None ,
562562 }
563563 }
@@ -726,7 +726,7 @@ impl<'ra> ModuleData<'ra> {
726726 self_decl : Option < Decl < ' ra > > ,
727727 ) -> Self {
728728 let is_foreign = match kind {
729- ModuleKind :: Def ( _, def_id, _) => !def_id. is_local ( ) ,
729+ ModuleKind :: Def ( _, def_id, _, _ ) => !def_id. is_local ( ) ,
730730 ModuleKind :: Block => false ,
731731 } ;
732732 ModuleData {
@@ -756,7 +756,7 @@ impl<'ra> ModuleData<'ra> {
756756
757757 fn res ( & self ) -> Option < Res > {
758758 match self . kind {
759- ModuleKind :: Def ( kind, def_id, _) => Some ( Res :: Def ( kind, def_id) ) ,
759+ ModuleKind :: Def ( kind, def_id, _, _ ) => Some ( Res :: Def ( kind, def_id) ) ,
760760 _ => None ,
761761 }
762762 }
@@ -813,11 +813,11 @@ impl<'ra> Module<'ra> {
813813
814814 // `self` resolves to the first module ancestor that `is_normal`.
815815 fn is_normal ( self ) -> bool {
816- matches ! ( self . kind, ModuleKind :: Def ( DefKind :: Mod , _, _) )
816+ matches ! ( self . kind, ModuleKind :: Def ( DefKind :: Mod , _, _, _ ) )
817817 }
818818
819819 fn is_trait ( self ) -> bool {
820- matches ! ( self . kind, ModuleKind :: Def ( DefKind :: Trait , _, _) )
820+ matches ! ( self . kind, ModuleKind :: Def ( DefKind :: Trait , _, _, _ ) )
821821 }
822822
823823 fn nearest_item_scope ( self ) -> Module < ' ra > {
@@ -833,11 +833,20 @@ impl<'ra> Module<'ra> {
833833 /// This may be the crate root.
834834 fn nearest_parent_mod ( self ) -> DefId {
835835 match self . kind {
836- ModuleKind :: Def ( DefKind :: Mod , def_id, _) => def_id,
836+ ModuleKind :: Def ( DefKind :: Mod , def_id, _, _ ) => def_id,
837837 _ => self . parent . expect ( "non-root module without parent" ) . nearest_parent_mod ( ) ,
838838 }
839839 }
840840
841+ /// The [`NodeId`] of the nearest `mod` item ancestor (which may be this module).
842+ /// This may be the crate root.
843+ fn nearest_parent_mod_node_id ( self ) -> NodeId {
844+ match self . kind {
845+ ModuleKind :: Def ( DefKind :: Mod , _, node_id, _) => node_id,
846+ _ => self . parent . expect ( "non-root module without parent" ) . nearest_parent_mod_node_id ( ) ,
847+ }
848+ }
849+
841850 fn is_ancestor_of ( self , mut other : Self ) -> bool {
842851 while self != other {
843852 if let Some ( parent) = other. parent {
@@ -852,7 +861,7 @@ impl<'ra> Module<'ra> {
852861 #[ track_caller]
853862 fn expect_local ( self ) -> LocalModule < ' ra > {
854863 match self . kind {
855- ModuleKind :: Def ( _, def_id, _) if !def_id. is_local ( ) => {
864+ ModuleKind :: Def ( _, def_id, _, _ ) if !def_id. is_local ( ) => {
856865 panic ! ( "`Module::expect_local` is called on a non-local module: {self:?}" )
857866 }
858867 ModuleKind :: Def ( ..) | ModuleKind :: Block => LocalModule ( self . 0 ) ,
@@ -862,7 +871,7 @@ impl<'ra> Module<'ra> {
862871 #[ track_caller]
863872 fn expect_extern ( self ) -> ExternModule < ' ra > {
864873 match self . kind {
865- ModuleKind :: Def ( _, def_id, _) if !def_id. is_local ( ) => ExternModule ( self . 0 ) ,
874+ ModuleKind :: Def ( _, def_id, _, _ ) if !def_id. is_local ( ) => ExternModule ( self . 0 ) ,
866875 ModuleKind :: Def ( ..) | ModuleKind :: Block => {
867876 panic ! ( "`Module::expect_extern` is called on a local module: {self:?}" )
868877 }
@@ -992,8 +1001,8 @@ struct UseError<'a> {
9921001 err : Diag < ' a > ,
9931002 /// Candidates which user could `use` to access the missing type.
9941003 candidates : Vec < ImportSuggestion > ,
995- /// The `DefId ` of the module to place the use-statements in.
996- def_id : DefId ,
1004+ /// The `NodeId ` of the module to place the use-statements in.
1005+ node_id : NodeId ,
9971006 /// Whether the diagnostic should say "instead" (as in `consider importing ... instead`).
9981007 instead : bool ,
9991008 /// Extra free-form suggestion.
@@ -1551,7 +1560,7 @@ impl<'ra> ResolverArenas<'ra> {
15511560 no_implicit_prelude : bool ,
15521561 ) -> Module < ' ra > {
15531562 let self_decl = match kind {
1554- ModuleKind :: Def ( def_kind, def_id, _) => Some ( self . new_def_decl (
1563+ ModuleKind :: Def ( def_kind, def_id, _, _ ) => Some ( self . new_def_decl (
15551564 Res :: Def ( def_kind, def_id) ,
15561565 vis,
15571566 span,
@@ -1732,7 +1741,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
17321741 let root_def_id = CRATE_DEF_ID . to_def_id ( ) ;
17331742 let graph_root = arenas. new_module (
17341743 None ,
1735- ModuleKind :: Def ( DefKind :: Mod , root_def_id, None ) ,
1744+ ModuleKind :: Def ( DefKind :: Mod , root_def_id, CRATE_NODE_ID , None ) ,
17361745 Visibility :: Public ,
17371746 ExpnId :: root ( ) ,
17381747 crate_span,
@@ -1743,7 +1752,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
17431752 let local_module_map = FxIndexMap :: from_iter ( [ ( CRATE_DEF_ID , graph_root) ] ) ;
17441753 let empty_module = arenas. new_module (
17451754 None ,
1746- ModuleKind :: Def ( DefKind :: Mod , root_def_id, None ) ,
1755+ ModuleKind :: Def ( DefKind :: Mod , root_def_id, CRATE_NODE_ID , None ) ,
17471756 Visibility :: Public ,
17481757 ExpnId :: root ( ) ,
17491758 DUMMY_SP ,
0 commit comments