@@ -65,11 +65,11 @@ use rustc_data_structures::sync::{Lock, Lrc};
6565
6666use std:: borrow:: Cow ;
6767use std:: cmp:: { self , Ordering } ;
68- use std:: fmt;
6968use std:: hash:: Hash ;
7069use std:: ops:: { Add , Range , Sub } ;
7170use std:: path:: { Path , PathBuf } ;
7271use std:: str:: FromStr ;
72+ use std:: { fmt, iter} ;
7373
7474use md5:: Digest ;
7575use md5:: Md5 ;
@@ -733,12 +733,15 @@ impl Span {
733733 /// else returns the `ExpnData` for the macro definition
734734 /// corresponding to the source callsite.
735735 pub fn source_callee ( self ) -> Option < ExpnData > {
736- fn source_callee ( expn_data : ExpnData ) -> ExpnData {
737- let next_expn_data = expn_data. call_site . ctxt ( ) . outer_expn_data ( ) ;
738- if !next_expn_data. is_root ( ) { source_callee ( next_expn_data) } else { expn_data }
739- }
740736 let expn_data = self . ctxt ( ) . outer_expn_data ( ) ;
741- if !expn_data. is_root ( ) { Some ( source_callee ( expn_data) ) } else { None }
737+
738+ // Create an iterator of call site expansions
739+ iter:: successors ( Some ( expn_data) , |expn_data| {
740+ Some ( expn_data. call_site . ctxt ( ) . outer_expn_data ( ) )
741+ } )
742+ // Find the last expansion which is not root
743+ . take_while ( |expn_data| !expn_data. is_root ( ) )
744+ . last ( )
742745 }
743746
744747 /// Checks if a span is "internal" to a macro in which `#[unstable]`
@@ -777,7 +780,7 @@ impl Span {
777780
778781 pub fn macro_backtrace ( mut self ) -> impl Iterator < Item = ExpnData > {
779782 let mut prev_span = DUMMY_SP ;
780- std :: iter:: from_fn ( move || {
783+ iter:: from_fn ( move || {
781784 loop {
782785 let expn_data = self . ctxt ( ) . outer_expn_data ( ) ;
783786 if expn_data. is_root ( ) {
0 commit comments