@@ -60,6 +60,7 @@ use rustc_hir::{HirIdMap, Node};
60
60
use rustc_hir_analysis:: astconv:: AstConv ;
61
61
use rustc_hir_analysis:: check:: check_abi;
62
62
use rustc_infer:: infer:: type_variable:: { TypeVariableOrigin , TypeVariableOriginKind } ;
63
+ use rustc_infer:: traits:: ObligationInspector ;
63
64
use rustc_middle:: query:: Providers ;
64
65
use rustc_middle:: traits;
65
66
use rustc_middle:: ty:: { self , Ty , TyCtxt } ;
@@ -139,7 +140,7 @@ fn used_trait_imports(tcx: TyCtxt<'_>, def_id: LocalDefId) -> &UnordSet<LocalDef
139
140
140
141
fn typeck < ' tcx > ( tcx : TyCtxt < ' tcx > , def_id : LocalDefId ) -> & ty:: TypeckResults < ' tcx > {
141
142
let fallback = move || tcx. type_of ( def_id. to_def_id ( ) ) . instantiate_identity ( ) ;
142
- typeck_with_fallback ( tcx, def_id, fallback)
143
+ typeck_with_fallback ( tcx, def_id, fallback, None )
143
144
}
144
145
145
146
/// Used only to get `TypeckResults` for type inference during error recovery.
@@ -149,14 +150,28 @@ fn diagnostic_only_typeck<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> &ty::T
149
150
let span = tcx. hir ( ) . span ( tcx. local_def_id_to_hir_id ( def_id) ) ;
150
151
Ty :: new_error_with_message ( tcx, span, "diagnostic only typeck table used" )
151
152
} ;
152
- typeck_with_fallback ( tcx, def_id, fallback)
153
+ typeck_with_fallback ( tcx, def_id, fallback, None )
153
154
}
154
155
155
- #[ instrument( level = "debug" , skip( tcx, fallback) , ret) ]
156
+ /// Same as `typeck` but `inspect` is invoked on evaluation of each root obligation.
157
+ /// Inspecting obligations only works with the new trait solver.
158
+ /// This function is *only to be used* by external tools, it should not be
159
+ /// called from within rustc. Note, this is not a query, and thus is not cached.
160
+ pub fn inspect_typeck < ' tcx > (
161
+ tcx : TyCtxt < ' tcx > ,
162
+ def_id : LocalDefId ,
163
+ inspect : ObligationInspector < ' tcx > ,
164
+ ) -> & ' tcx ty:: TypeckResults < ' tcx > {
165
+ let fallback = move || tcx. type_of ( def_id. to_def_id ( ) ) . instantiate_identity ( ) ;
166
+ typeck_with_fallback ( tcx, def_id, fallback, Some ( inspect) )
167
+ }
168
+
169
+ #[ instrument( level = "debug" , skip( tcx, fallback, inspector) , ret) ]
156
170
fn typeck_with_fallback < ' tcx > (
157
171
tcx : TyCtxt < ' tcx > ,
158
172
def_id : LocalDefId ,
159
173
fallback : impl Fn ( ) -> Ty < ' tcx > + ' tcx ,
174
+ inspector : Option < ObligationInspector < ' tcx > > ,
160
175
) -> & ' tcx ty:: TypeckResults < ' tcx > {
161
176
// Closures' typeck results come from their outermost function,
162
177
// as they are part of the same "inference environment".
@@ -178,6 +193,9 @@ fn typeck_with_fallback<'tcx>(
178
193
let param_env = tcx. param_env ( def_id) ;
179
194
180
195
let inh = Inherited :: new ( tcx, def_id) ;
196
+ if let Some ( inspector) = inspector {
197
+ inh. infcx . attach_obligation_inspector ( inspector) ;
198
+ }
181
199
let mut fcx = FnCtxt :: new ( & inh, param_env, def_id) ;
182
200
183
201
if let Some ( hir:: FnSig { header, decl, .. } ) = fn_sig {
0 commit comments