1
1
use rustc_span:: { ExpnKind , MacroKind , Span , Symbol } ;
2
2
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`.
7
13
///
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` ).
10
16
pub ( crate ) fn unexpand_into_body_span_with_visible_macro (
11
17
original_span : Span ,
12
18
body_span : Span ,
@@ -24,15 +30,15 @@ pub(crate) fn unexpand_into_body_span_with_visible_macro(
24
30
}
25
31
26
32
/// 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`.
28
34
/// The ancestor that was traversed just before the matching span (if any) is
29
35
/// also returned.
30
36
///
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:
32
38
/// - `ancestor == original_span.find_ancestor_inside_same_ctxt(body_span)`
33
- /// - `ancestor == prev.parent_callsite()`
39
+ /// - `prev.parent_callsite() == ancestor `
34
40
///
35
- /// [`SyntaxContext` ]: rustc_span::SyntaxContext
41
+ /// [syntax context ]: rustc_span::SyntaxContext
36
42
fn unexpand_into_body_span_with_prev (
37
43
original_span : Span ,
38
44
body_span : Span ,
@@ -45,7 +51,7 @@ fn unexpand_into_body_span_with_prev(
45
51
curr = curr. parent_callsite ( ) ?;
46
52
}
47
53
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) ) ;
49
55
if let Some ( prev) = prev {
50
56
debug_assert_eq ! ( Some ( curr) , prev. parent_callsite( ) ) ;
51
57
}
0 commit comments