@@ -60,10 +60,10 @@ fn method_might_be_inlined(
60
60
}
61
61
62
62
// Information needed while computing reachability.
63
- struct ReachableContext < ' a , ' tcx > {
63
+ struct ReachableContext < ' tcx > {
64
64
// The type context.
65
65
tcx : TyCtxt < ' tcx > ,
66
- tables : & ' a ty:: TypeckTables < ' tcx > ,
66
+ maybe_typeck_tables : Option < & ' tcx ty:: TypeckTables < ' tcx > > ,
67
67
// The set of items which must be exported in the linkage sense.
68
68
reachable_symbols : HirIdSet ,
69
69
// A worklist of item IDs. Each item ID in this worklist will be inlined
@@ -73,26 +73,25 @@ struct ReachableContext<'a, 'tcx> {
73
73
any_library : bool ,
74
74
}
75
75
76
- impl < ' a , ' tcx > Visitor < ' tcx > for ReachableContext < ' a , ' tcx > {
76
+ impl < ' tcx > Visitor < ' tcx > for ReachableContext < ' tcx > {
77
77
type Map = intravisit:: ErasedMap < ' tcx > ;
78
78
79
79
fn nested_visit_map ( & mut self ) -> NestedVisitorMap < Self :: Map > {
80
80
NestedVisitorMap :: None
81
81
}
82
82
83
83
fn visit_nested_body ( & mut self , body : hir:: BodyId ) {
84
- let old_tables = self . tables ;
85
- self . tables = self . tcx . body_tables ( body) ;
84
+ let old_maybe_typeck_tables = self . maybe_typeck_tables . replace ( self . tcx . body_tables ( body) ) ;
86
85
let body = self . tcx . hir ( ) . body ( body) ;
87
86
self . visit_body ( body) ;
88
- self . tables = old_tables ;
87
+ self . maybe_typeck_tables = old_maybe_typeck_tables ;
89
88
}
90
89
91
90
fn visit_expr ( & mut self , expr : & ' tcx hir:: Expr < ' tcx > ) {
92
91
let res = match expr. kind {
93
- hir:: ExprKind :: Path ( ref qpath) => Some ( self . tables . qpath_res ( qpath, expr. hir_id ) ) ,
92
+ hir:: ExprKind :: Path ( ref qpath) => Some ( self . tables ( ) . qpath_res ( qpath, expr. hir_id ) ) ,
94
93
hir:: ExprKind :: MethodCall ( ..) => self
95
- . tables
94
+ . tables ( )
96
95
. type_dependent_def ( expr. hir_id )
97
96
. map ( |( kind, def_id) | Res :: Def ( kind, def_id) ) ,
98
97
_ => None ,
@@ -133,7 +132,15 @@ impl<'a, 'tcx> Visitor<'tcx> for ReachableContext<'a, 'tcx> {
133
132
}
134
133
}
135
134
136
- impl < ' a , ' tcx > ReachableContext < ' a , ' tcx > {
135
+ impl < ' tcx > ReachableContext < ' tcx > {
136
+ /// Gets the type-checking side-tables for the current body.
137
+ /// As this will ICE if called outside bodies, only call when working with
138
+ /// `Expr` or `Pat` nodes (they are guaranteed to be found only in bodies).
139
+ #[ track_caller]
140
+ fn tables ( & self ) -> & ' tcx ty:: TypeckTables < ' tcx > {
141
+ self . maybe_typeck_tables . expect ( "`ReachableContext::tables` called outside of body" )
142
+ }
143
+
137
144
// Returns true if the given def ID represents a local item that is
138
145
// eligible for inlining and false otherwise.
139
146
fn def_id_represents_local_inlined_item ( & self , def_id : DefId ) -> bool {
@@ -381,7 +388,7 @@ fn reachable_set<'tcx>(tcx: TyCtxt<'tcx>, crate_num: CrateNum) -> &'tcx HirIdSet
381
388
} ) ;
382
389
let mut reachable_context = ReachableContext {
383
390
tcx,
384
- tables : & ty :: TypeckTables :: empty ( None ) ,
391
+ maybe_typeck_tables : None ,
385
392
reachable_symbols : Default :: default ( ) ,
386
393
worklist : Vec :: new ( ) ,
387
394
any_library,
0 commit comments