@@ -21,6 +21,7 @@ use util::nodemap::NodeSet;
21
21
22
22
use rustc_data_structures:: indexed_vec:: IndexVec ;
23
23
use std:: cell:: { RefCell , RefMut } ;
24
+ use std:: ops:: Deref ;
24
25
use std:: rc:: Rc ;
25
26
use syntax_pos:: { Span , DUMMY_SP } ;
26
27
@@ -329,14 +330,6 @@ macro_rules! define_maps {
329
330
Self :: try_get_with( tcx, span, key, Clone :: clone)
330
331
}
331
332
332
- $( #[ $attr] ) *
333
- pub fn get( tcx: TyCtxt <' a, $tcx, ' lcx>, span: Span , key: $K) -> $V {
334
- Self :: try_get( tcx, span, key) . unwrap_or_else( |e| {
335
- tcx. report_cycle( e) ;
336
- Value :: from_cycle_error( tcx. global_tcx( ) )
337
- } )
338
- }
339
-
340
333
pub fn force( tcx: TyCtxt <' a, $tcx, ' lcx>, span: Span , key: $K) {
341
334
// FIXME(eddyb) Move away from using `DepTrackingMap`
342
335
// so we don't have to explicitly ignore a false edge:
@@ -351,10 +344,42 @@ macro_rules! define_maps {
351
344
}
352
345
} ) *
353
346
347
+ #[ derive( Copy , Clone ) ]
348
+ pub struct TyCtxtAt <' a, ' gcx: ' a+' tcx, ' tcx: ' a> {
349
+ pub tcx: TyCtxt <' a, ' gcx, ' tcx>,
350
+ pub span: Span ,
351
+ }
352
+
353
+ impl <' a, ' gcx, ' tcx> Deref for TyCtxtAt <' a, ' gcx, ' tcx> {
354
+ type Target = TyCtxt <' a, ' gcx, ' tcx>;
355
+ fn deref( & self ) -> & Self :: Target {
356
+ & self . tcx
357
+ }
358
+ }
359
+
354
360
impl <' a, $tcx, ' lcx> TyCtxt <' a, $tcx, ' lcx> {
361
+ /// Return a transparent wrapper for `TyCtxt` which uses
362
+ /// `span` as the location of queries performed through it.
363
+ pub fn at( self , span: Span ) -> TyCtxtAt <' a, $tcx, ' lcx> {
364
+ TyCtxtAt {
365
+ tcx: self ,
366
+ span
367
+ }
368
+ }
369
+
370
+ $( $( #[ $attr] ) *
371
+ pub fn $name( self , key: $K) -> $V {
372
+ self . at( DUMMY_SP ) . $name( key)
373
+ } ) *
374
+ }
375
+
376
+ impl <' a, $tcx, ' lcx> TyCtxtAt <' a, $tcx, ' lcx> {
355
377
$( $( #[ $attr] ) *
356
378
pub fn $name( self , key: $K) -> $V {
357
- queries:: $name:: get( self , DUMMY_SP , key)
379
+ queries:: $name:: try_get( self . tcx, self . span, key) . unwrap_or_else( |e| {
380
+ self . report_cycle( e) ;
381
+ Value :: from_cycle_error( self . global_tcx( ) )
382
+ } )
358
383
} ) *
359
384
}
360
385
0 commit comments