@@ -541,10 +541,6 @@ impl Span {
541541 self . data ( ) . with_hi ( hi)
542542 }
543543 #[ inline]
544- pub fn eq_ctxt ( self , other : Span ) -> bool {
545- self . data_untracked ( ) . ctxt == other. data_untracked ( ) . ctxt
546- }
547- #[ inline]
548544 pub fn with_ctxt ( self , ctxt : SyntaxContext ) -> Span {
549545 self . data_untracked ( ) . with_ctxt ( ctxt)
550546 }
@@ -565,7 +561,7 @@ impl Span {
565561 /// Returns `true` if this span comes from any kind of macro, desugaring or inlining.
566562 #[ inline]
567563 pub fn from_expansion ( self ) -> bool {
568- self . ctxt ( ) != SyntaxContext :: root ( )
564+ ! self . ctxt ( ) . is_root ( )
569565 }
570566
571567 /// Returns `true` if `span` originates in a macro's expansion where debuginfo should be
@@ -654,15 +650,15 @@ impl Span {
654650 /// Returns the source span -- this is either the supplied span, or the span for
655651 /// the macro callsite that expanded to it.
656652 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 }
659655 }
660656
661657 /// The `Span` for the tokens in the previous macro expansion from which `self` was generated,
662658 /// if any.
663659 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 )
666662 }
667663
668664 /// Walk down the expansion ancestors to find a span that's contained within `outer`.
@@ -747,15 +743,14 @@ impl Span {
747743 /// else returns the `ExpnData` for the macro definition
748744 /// corresponding to the source callsite.
749745 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
759754 }
760755
761756 /// Checks if a span is "internal" to a macro in which `#[unstable]`
@@ -796,11 +791,12 @@ impl Span {
796791 let mut prev_span = DUMMY_SP ;
797792 iter:: from_fn ( move || {
798793 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 ( ) {
801796 return None ;
802797 }
803798
799+ let expn_data = ctxt. outer_expn_data ( ) ;
804800 let is_recursive = expn_data. call_site . source_equal ( prev_span) ;
805801
806802 prev_span = self ;
0 commit comments