@@ -21,6 +21,7 @@ use util::nodemap::NodeSet;
2121
2222use rustc_data_structures:: indexed_vec:: IndexVec ;
2323use std:: cell:: { RefCell , RefMut } ;
24+ use std:: ops:: Deref ;
2425use std:: rc:: Rc ;
2526use syntax_pos:: { Span , DUMMY_SP } ;
2627
@@ -329,14 +330,6 @@ macro_rules! define_maps {
329330 Self :: try_get_with( tcx, span, key, Clone :: clone)
330331 }
331332
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-
340333 pub fn force( tcx: TyCtxt <' a, $tcx, ' lcx>, span: Span , key: $K) {
341334 // FIXME(eddyb) Move away from using `DepTrackingMap`
342335 // so we don't have to explicitly ignore a false edge:
@@ -351,10 +344,42 @@ macro_rules! define_maps {
351344 }
352345 } ) *
353346
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+
354360 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> {
355377 $( $( #[ $attr] ) *
356378 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+ } )
358383 } ) *
359384 }
360385
0 commit comments