9
9
10
10
use rustc_errors:: struct_span_err;
11
11
use rustc_hir as hir;
12
- use rustc_hir:: def_id:: { CrateNum , DefId , LocalDefId , LOCAL_CRATE } ;
12
+ use rustc_hir:: def_id:: { DefId , LocalDefId } ;
13
13
use rustc_hir:: itemlikevisit:: ItemLikeVisitor ;
14
14
use rustc_middle:: ty:: { self , CrateInherentImpls , TyCtxt } ;
15
15
16
16
use rustc_span:: Span ;
17
17
18
18
/// On-demand query: yields a map containing all types mapped to their inherent impls.
19
- pub fn crate_inherent_impls ( tcx : TyCtxt < ' _ > , crate_num : CrateNum ) -> CrateInherentImpls {
20
- assert_eq ! ( crate_num, LOCAL_CRATE ) ;
21
-
19
+ pub fn crate_inherent_impls ( tcx : TyCtxt < ' _ > , ( ) : ( ) ) -> CrateInherentImpls {
22
20
let krate = tcx. hir ( ) . krate ( ) ;
23
21
let mut collect = InherentCollect { tcx, impls_map : Default :: default ( ) } ;
24
22
krate. visit_all_item_likes ( & mut collect) ;
@@ -27,9 +25,9 @@ pub fn crate_inherent_impls(tcx: TyCtxt<'_>, crate_num: CrateNum) -> CrateInhere
27
25
28
26
/// On-demand query: yields a vector of the inherent impls for a specific type.
29
27
pub fn inherent_impls ( tcx : TyCtxt < ' _ > , ty_def_id : DefId ) -> & [ DefId ] {
30
- assert ! ( ty_def_id. is_local ( ) ) ;
28
+ let ty_def_id = ty_def_id . expect_local ( ) ;
31
29
32
- let crate_map = tcx. crate_inherent_impls ( ty_def_id . krate ) ;
30
+ let crate_map = tcx. crate_inherent_impls ( ( ) ) ;
33
31
match crate_map. inherent_impls . get ( & ty_def_id) {
34
32
Some ( v) => & v[ ..] ,
35
33
None => & [ ] ,
@@ -364,7 +362,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
364
362
365
363
impl InherentCollect < ' tcx > {
366
364
fn check_def_id ( & mut self , item : & hir:: Item < ' _ > , def_id : DefId ) {
367
- if def_id. is_local ( ) {
365
+ if let Some ( def_id) = def_id . as_local ( ) {
368
366
// Add the implementation to the mapping from implementation to base
369
367
// type def ID, if there is a base type for this implementation and
370
368
// the implementation does not have any associated traits.
0 commit comments