11use  rustc_span:: { ExpnKind ,  MacroKind ,  Span ,  Symbol } ; 
22
3- /// Returns an extrapolated span (pre-expansion[^1]) corresponding to a range 
4- /// within the function's body source. This span is guaranteed to be contained 
5- /// within, or equal to, the `body_span`. If the extrapolated span is not 
6- /// contained within the `body_span`, `None` is returned. 
3+ /// Walks through the expansion ancestors of `original_span` to find a span that 
4+ /// is contained in `body_span` and has the same [syntax context] as `body_span`. 
5+ pub ( crate )  fn  unexpand_into_body_span ( original_span :  Span ,  body_span :  Span )  -> Option < Span >  { 
6+     // Because we don't need to return any extra ancestor information, 
7+     // we can just delegate directly to `find_ancestor_inside_same_ctxt`. 
8+     original_span. find_ancestor_inside_same_ctxt ( body_span) 
9+ } 
10+ 
11+ /// Walks through the expansion ancestors of `original_span` to find a span that 
12+ /// is contained in `body_span` and has the same [syntax context] as `body_span`. 
713/// 
8- /// [^1]Expansions result from Rust syntax including macros, syntactic sugar , 
9- /// etc. ). 
14+ /// If the returned span represents a bang-macro invocation (e.g. `foo!(..)`) , 
15+ /// the returned symbol will be the name of that macro (e.g. `foo` ). 
1016pub ( crate )  fn  unexpand_into_body_span_with_visible_macro ( 
1117    original_span :  Span , 
1218    body_span :  Span , 
@@ -24,15 +30,15 @@ pub(crate) fn unexpand_into_body_span_with_visible_macro(
2430} 
2531
2632/// Walks through the expansion ancestors of `original_span` to find a span that 
27- /// is contained in `body_span` and has the same [`SyntaxContext` ] as `body_span`. 
33+ /// is contained in `body_span` and has the same [syntax context ] as `body_span`. 
2834/// The ancestor that was traversed just before the matching span (if any) is 
2935/// also returned. 
3036/// 
31- /// For example, a return value of `Some((ancestor, Some(prev))` means that: 
37+ /// For example, a return value of `Some((ancestor, Some(prev))) ` means that: 
3238/// - `ancestor == original_span.find_ancestor_inside_same_ctxt(body_span)` 
33- /// - `ancestor ==  prev.parent_callsite()` 
39+ /// - `prev.parent_callsite() == ancestor ` 
3440/// 
35- /// [`SyntaxContext` ]: rustc_span::SyntaxContext 
41+ /// [syntax context ]: rustc_span::SyntaxContext 
3642fn  unexpand_into_body_span_with_prev ( 
3743    original_span :  Span , 
3844    body_span :  Span , 
@@ -45,7 +51,7 @@ fn unexpand_into_body_span_with_prev(
4551        curr = curr. parent_callsite ( ) ?; 
4652    } 
4753
48-     debug_assert_eq ! ( Some ( curr) ,  original_span. find_ancestor_in_same_ctxt ( body_span) ) ; 
54+     debug_assert_eq ! ( Some ( curr) ,  original_span. find_ancestor_inside_same_ctxt ( body_span) ) ; 
4955    if  let  Some ( prev)  = prev { 
5056        debug_assert_eq ! ( Some ( curr) ,  prev. parent_callsite( ) ) ; 
5157    } 
0 commit comments