8
8
// option. This file may not be copied, modified, or distributed
9
9
// except according to those terms.
10
10
11
- use hir:: map as hir_map;
12
11
use rustc:: hir;
13
- use rustc:: hir:: def_id:: { CrateNum , DefId , LocalDefId , LOCAL_CRATE } ;
12
+ use rustc:: hir:: def_id:: { CrateNum , DefId } ;
14
13
use rustc:: hir:: itemlikevisit:: ItemLikeVisitor ;
15
- use rustc:: ty:: maps:: Providers ;
16
- use rustc:: ty:: { self , CratePredicatesMap , TyCtxt } ;
17
- use rustc_data_structures:: sync:: Lrc ;
14
+ use rustc:: ty:: { self , TyCtxt } ;
18
15
use util:: nodemap:: FxHashMap ;
19
16
17
+ use super :: utils:: * ;
18
+
20
19
pub fn explicit_predicates < ' tcx > (
21
20
tcx : TyCtxt < ' _ , ' tcx , ' tcx > ,
22
21
crate_num : CrateNum ,
23
- ) -> FxHashMap < DefId , Lrc < Vec < ty:: Predicate < ' tcx > > > > {
24
- assert_eq ! ( crate_num, LOCAL_CRATE ) ;
25
- let mut predicates: FxHashMap < DefId , Lrc < Vec < ty:: Predicate < ' tcx > > > > = FxHashMap ( ) ;
22
+ ) -> FxHashMap < DefId , RequiredPredicates < ' tcx > > {
23
+ let mut predicates = FxHashMap :: default ( ) ;
26
24
27
25
// iterate over the entire crate
28
26
tcx. hir . krate ( ) . visit_all_item_likes ( & mut ExplicitVisitor {
@@ -36,7 +34,7 @@ pub fn explicit_predicates<'tcx>(
36
34
37
35
pub struct ExplicitVisitor < ' cx , ' tcx : ' cx > {
38
36
tcx : TyCtxt < ' cx , ' tcx , ' tcx > ,
39
- explicit_predicates : & ' cx mut FxHashMap < DefId , Lrc < Vec < ty :: Predicate < ' tcx > > > > ,
37
+ explicit_predicates : & ' cx mut FxHashMap < DefId , RequiredPredicates < ' tcx > > ,
40
38
crate_num : CrateNum ,
41
39
}
42
40
@@ -47,36 +45,40 @@ impl<'cx, 'tcx> ItemLikeVisitor<'tcx> for ExplicitVisitor<'cx, 'tcx> {
47
45
index : item. hir_id . owner ,
48
46
} ;
49
47
50
- let local_explicit_predicate = self . tcx . explicit_predicates_of ( def_id) ;
48
+ let mut required_predicates = RequiredPredicates :: default ( ) ;
49
+ let local_explicit_predicate = self . tcx . explicit_predicates_of ( def_id) . predicates ;
50
+
51
+ for pred in local_explicit_predicate. into_iter ( ) {
52
+ match pred {
53
+ ty:: Predicate :: TypeOutlives ( predicate) => {
54
+ let ty:: OutlivesPredicate ( ref ty, ref reg) = predicate. skip_binder ( ) ;
55
+ insert_outlives_predicate ( self . tcx , ( * ty) . into ( ) , reg, & mut required_predicates)
56
+ }
51
57
52
- let filtered_predicates = local_explicit_predicate
53
- . predicates
54
- . into_iter ( )
55
- . filter ( |pred| match pred {
56
- ty:: Predicate :: TypeOutlives ( ..) | ty:: Predicate :: RegionOutlives ( ..) => true ,
58
+ ty:: Predicate :: RegionOutlives ( predicate) => {
59
+ let ty:: OutlivesPredicate ( ref reg1, ref reg2) = predicate. skip_binder ( ) ;
60
+ insert_outlives_predicate (
61
+ self . tcx ,
62
+ ( * reg1) . into ( ) ,
63
+ reg2,
64
+ & mut required_predicates,
65
+ )
66
+ }
57
67
58
68
ty:: Predicate :: Trait ( ..)
59
69
| ty:: Predicate :: Projection ( ..)
60
70
| ty:: Predicate :: WellFormed ( ..)
61
71
| ty:: Predicate :: ObjectSafe ( ..)
62
72
| ty:: Predicate :: ClosureKind ( ..)
63
73
| ty:: Predicate :: Subtype ( ..)
64
- | ty:: Predicate :: ConstEvaluatable ( ..) => false ,
65
- } )
66
- . collect ( ) ;
67
-
68
- match item. node {
69
- hir:: ItemStruct ( ..) | hir:: ItemEnum ( ..) => {
70
- self . tcx . adt_def ( def_id) ;
74
+ | ty:: Predicate :: ConstEvaluatable ( ..) => ( ) ,
71
75
}
72
- _ => { }
73
76
}
74
77
75
- self . explicit_predicates
76
- . insert ( def_id, Lrc :: new ( filtered_predicates) ) ;
78
+ self . explicit_predicates . insert ( def_id, required_predicates) ;
77
79
}
78
80
79
- fn visit_trait_item ( & mut self , trait_item : & ' tcx hir:: TraitItem ) { }
81
+ fn visit_trait_item ( & mut self , _trait_item : & ' tcx hir:: TraitItem ) { }
80
82
81
- fn visit_impl_item ( & mut self , impl_item : & ' tcx hir:: ImplItem ) { }
83
+ fn visit_impl_item ( & mut self , _impl_item : & ' tcx hir:: ImplItem ) { }
82
84
}
0 commit comments