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