@@ -413,7 +413,7 @@ impl ModuleOrUniformRoot<'_> {
413
413
fn same_def ( lhs : Self , rhs : Self ) -> bool {
414
414
match ( lhs, rhs) {
415
415
( ModuleOrUniformRoot :: Module ( lhs) , ModuleOrUniformRoot :: Module ( rhs) ) => {
416
- lhs . def_id ( ) == rhs. def_id ( )
416
+ ptr :: eq ( lhs , rhs)
417
417
}
418
418
(
419
419
ModuleOrUniformRoot :: CrateRootAndExternPrelude ,
@@ -602,7 +602,11 @@ impl<'a> ModuleData<'a> {
602
602
}
603
603
}
604
604
605
- fn def_id ( & self ) -> Option < DefId > {
605
+ fn def_id ( & self ) -> DefId {
606
+ self . opt_def_id ( ) . expect ( "`ModuleData::def_id` is called on a block module" )
607
+ }
608
+
609
+ fn opt_def_id ( & self ) -> Option < DefId > {
606
610
match self . kind {
607
611
ModuleKind :: Def ( _, def_id, _) => Some ( def_id) ,
608
612
_ => None ,
@@ -1075,7 +1079,7 @@ impl<'a> ResolverArenas<'a> {
1075
1079
) -> Module < ' a > {
1076
1080
let module =
1077
1081
self . modules . alloc ( ModuleData :: new ( parent, kind, expn_id, span, no_implicit_prelude) ) ;
1078
- let def_id = module. def_id ( ) ;
1082
+ let def_id = module. opt_def_id ( ) ;
1079
1083
if def_id. map_or ( true , |def_id| def_id. is_local ( ) ) {
1080
1084
self . local_modules . borrow_mut ( ) . push ( module) ;
1081
1085
}
@@ -1588,7 +1592,7 @@ impl<'a> Resolver<'a> {
1588
1592
1589
1593
if let Some ( module) = current_trait {
1590
1594
if self . trait_may_have_item ( Some ( module) , assoc_item) {
1591
- let def_id = module. def_id ( ) . unwrap ( ) ;
1595
+ let def_id = module. def_id ( ) ;
1592
1596
found_traits. push ( TraitCandidate { def_id, import_ids : smallvec ! [ ] } ) ;
1593
1597
}
1594
1598
}
@@ -2189,8 +2193,9 @@ impl<'a> Resolver<'a> {
2189
2193
return self . graph_root ;
2190
2194
}
2191
2195
} ;
2192
- let module = self
2193
- . expect_module ( module. def_id ( ) . map_or ( LOCAL_CRATE , |def_id| def_id. krate ) . as_def_id ( ) ) ;
2196
+ let module = self . expect_module (
2197
+ module. opt_def_id ( ) . map_or ( LOCAL_CRATE , |def_id| def_id. krate ) . as_def_id ( ) ,
2198
+ ) ;
2194
2199
debug ! (
2195
2200
"resolve_crate_root({:?}): got module {:?} ({:?}) (ident.span = {:?})" ,
2196
2201
ident,
@@ -3017,7 +3022,7 @@ impl<'a> Resolver<'a> {
3017
3022
}
3018
3023
3019
3024
let container = match parent. kind {
3020
- ModuleKind :: Def ( kind, _, _) => kind. descr ( parent. def_id ( ) . unwrap ( ) ) ,
3025
+ ModuleKind :: Def ( kind, _, _) => kind. descr ( parent. def_id ( ) ) ,
3021
3026
ModuleKind :: Block ( ..) => "block" ,
3022
3027
} ;
3023
3028
0 commit comments