File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -302,6 +302,28 @@ pub fn snippet_with_context(
302
302
/// inside a macro expansion, or the original span if it is not. Note this will return `None` in the
303
303
/// case of the span being in a macro expansion, but the target context is from expanding a macro
304
304
/// argument.
305
+ ///
306
+ /// Given the following
307
+ ///
308
+ /// ```rust,ignore
309
+ /// macro_rules! m { ($e:expr) => { f($e) }; }
310
+ /// g(m!(0))
311
+ /// ```
312
+ ///
313
+ /// If called with a span of the call to `f` and a context of the call to `g` this will return a
314
+ /// span containing `m!(0)`. However, if called with a span of the literal `0` this will give a span
315
+ /// containing `0` as the context is the same as the outer context.
316
+ ///
317
+ /// This will traverse through multiple macro calls. Given the following:
318
+ ///
319
+ /// ```rust,ignore
320
+ /// macro_rules! m { ($e:expr) => { n!($e, 0) }; }
321
+ /// macro_rules! n { ($e:expr, $f:expr) => { f($e, $f) }; }
322
+ /// g(m!(0))
323
+ /// ```
324
+ ///
325
+ /// If called with a span of the call to `f` and a context of the call to `g` this will return a
326
+ /// span containing `m!(0)`.
305
327
pub fn walk_span_to_context ( span : Span , outer : SyntaxContext ) -> Option < Span > {
306
328
let outer_span = hygiene:: walk_chain ( span, outer) ;
307
329
( outer_span. ctxt ( ) == outer) . then ( || outer_span)
You can’t perform that action at this time.
0 commit comments