@@ -541,10 +541,6 @@ impl Span {
541
541
self . data ( ) . with_hi ( hi)
542
542
}
543
543
#[ inline]
544
- pub fn eq_ctxt ( self , other : Span ) -> bool {
545
- self . data_untracked ( ) . ctxt == other. data_untracked ( ) . ctxt
546
- }
547
- #[ inline]
548
544
pub fn with_ctxt ( self , ctxt : SyntaxContext ) -> Span {
549
545
self . data_untracked ( ) . with_ctxt ( ctxt)
550
546
}
@@ -565,7 +561,7 @@ impl Span {
565
561
/// Returns `true` if this span comes from any kind of macro, desugaring or inlining.
566
562
#[ inline]
567
563
pub fn from_expansion ( self ) -> bool {
568
- self . ctxt ( ) != SyntaxContext :: root ( )
564
+ ! self . ctxt ( ) . is_root ( )
569
565
}
570
566
571
567
/// Returns `true` if `span` originates in a macro's expansion where debuginfo should be
@@ -654,15 +650,15 @@ impl Span {
654
650
/// Returns the source span -- this is either the supplied span, or the span for
655
651
/// the macro callsite that expanded to it.
656
652
pub fn source_callsite ( self ) -> Span {
657
- let expn_data = self . ctxt ( ) . outer_expn_data ( ) ;
658
- if !expn_data . is_root ( ) { expn_data . call_site . source_callsite ( ) } else { self }
653
+ let ctxt = self . ctxt ( ) ;
654
+ if !ctxt . is_root ( ) { ctxt . outer_expn_data ( ) . call_site . source_callsite ( ) } else { self }
659
655
}
660
656
661
657
/// The `Span` for the tokens in the previous macro expansion from which `self` was generated,
662
658
/// if any.
663
659
pub fn parent_callsite ( self ) -> Option < Span > {
664
- let expn_data = self . ctxt ( ) . outer_expn_data ( ) ;
665
- if !expn_data . is_root ( ) { Some ( expn_data . call_site ) } else { None }
660
+ let ctxt = self . ctxt ( ) ;
661
+ ( !ctxt . is_root ( ) ) . then ( || ctxt . outer_expn_data ( ) . call_site )
666
662
}
667
663
668
664
/// Walk down the expansion ancestors to find a span that's contained within `outer`.
@@ -747,15 +743,14 @@ impl Span {
747
743
/// else returns the `ExpnData` for the macro definition
748
744
/// corresponding to the source callsite.
749
745
pub fn source_callee ( self ) -> Option < ExpnData > {
750
- let expn_data = self . ctxt ( ) . outer_expn_data ( ) ;
751
-
752
- // Create an iterator of call site expansions
753
- iter:: successors ( Some ( expn_data) , |expn_data| {
754
- Some ( expn_data. call_site . ctxt ( ) . outer_expn_data ( ) )
755
- } )
756
- // Find the last expansion which is not root
757
- . take_while ( |expn_data| !expn_data. is_root ( ) )
758
- . last ( )
746
+ let mut ctxt = self . ctxt ( ) ;
747
+ let mut opt_expn_data = None ;
748
+ while !ctxt. is_root ( ) {
749
+ let expn_data = ctxt. outer_expn_data ( ) ;
750
+ ctxt = expn_data. call_site . ctxt ( ) ;
751
+ opt_expn_data = Some ( expn_data) ;
752
+ }
753
+ opt_expn_data
759
754
}
760
755
761
756
/// Checks if a span is "internal" to a macro in which `#[unstable]`
@@ -796,11 +791,12 @@ impl Span {
796
791
let mut prev_span = DUMMY_SP ;
797
792
iter:: from_fn ( move || {
798
793
loop {
799
- let expn_data = self . ctxt ( ) . outer_expn_data ( ) ;
800
- if expn_data . is_root ( ) {
794
+ let ctxt = self . ctxt ( ) ;
795
+ if ctxt . is_root ( ) {
801
796
return None ;
802
797
}
803
798
799
+ let expn_data = ctxt. outer_expn_data ( ) ;
804
800
let is_recursive = expn_data. call_site . source_equal ( prev_span) ;
805
801
806
802
prev_span = self ;
0 commit comments