@@ -65,11 +65,11 @@ use rustc_data_structures::sync::{Lock, Lrc};
65
65
66
66
use std:: borrow:: Cow ;
67
67
use std:: cmp:: { self , Ordering } ;
68
- use std:: fmt;
69
68
use std:: hash:: Hash ;
70
69
use std:: ops:: { Add , Range , Sub } ;
71
70
use std:: path:: { Path , PathBuf } ;
72
71
use std:: str:: FromStr ;
72
+ use std:: { fmt, iter} ;
73
73
74
74
use md5:: Digest ;
75
75
use md5:: Md5 ;
@@ -733,12 +733,15 @@ impl Span {
733
733
/// else returns the `ExpnData` for the macro definition
734
734
/// corresponding to the source callsite.
735
735
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
- }
740
736
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 ( )
742
745
}
743
746
744
747
/// Checks if a span is "internal" to a macro in which `#[unstable]`
@@ -777,7 +780,7 @@ impl Span {
777
780
778
781
pub fn macro_backtrace ( mut self ) -> impl Iterator < Item = ExpnData > {
779
782
let mut prev_span = DUMMY_SP ;
780
- std :: iter:: from_fn ( move || {
783
+ iter:: from_fn ( move || {
781
784
loop {
782
785
let expn_data = self . ctxt ( ) . outer_expn_data ( ) ;
783
786
if expn_data. is_root ( ) {
0 commit comments