@@ -544,10 +544,6 @@ impl Span {
544544 self . data ( ) . with_hi ( hi)
545545 }
546546 #[ inline]
547- pub fn eq_ctxt ( self , other : Span ) -> bool {
548- self . data_untracked ( ) . ctxt == other. data_untracked ( ) . ctxt
549- }
550- #[ inline]
551547 pub fn with_ctxt ( self , ctxt : SyntaxContext ) -> Span {
552548 self . data_untracked ( ) . with_ctxt ( ctxt)
553549 }
@@ -568,7 +564,7 @@ impl Span {
568564 /// Returns `true` if this span comes from any kind of macro, desugaring or inlining.
569565 #[ inline]
570566 pub fn from_expansion ( self ) -> bool {
571- self . ctxt ( ) != SyntaxContext :: root ( )
567+ ! self . ctxt ( ) . is_root ( )
572568 }
573569
574570 /// Returns `true` if `span` originates in a macro's expansion where debuginfo should be
@@ -657,15 +653,15 @@ impl Span {
657653 /// Returns the source span -- this is either the supplied span, or the span for
658654 /// the macro callsite that expanded to it.
659655 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 }
662658 }
663659
664660 /// The `Span` for the tokens in the previous macro expansion from which `self` was generated,
665661 /// if any.
666662 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 )
669665 }
670666
671667 /// Walk down the expansion ancestors to find a span that's contained within `outer`.
@@ -750,15 +746,14 @@ impl Span {
750746 /// else returns the `ExpnData` for the macro definition
751747 /// corresponding to the source callsite.
752748 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
762757 }
763758
764759 /// Checks if a span is "internal" to a macro in which `#[unstable]`
@@ -799,11 +794,12 @@ impl Span {
799794 let mut prev_span = DUMMY_SP ;
800795 iter:: from_fn ( move || {
801796 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 ( ) {
804799 return None ;
805800 }
806801
802+ let expn_data = ctxt. outer_expn_data ( ) ;
807803 let is_recursive = expn_data. call_site . source_equal ( prev_span) ;
808804
809805 prev_span = self ;
0 commit comments