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 @@ -293,6 +293,28 @@ pub fn snippet_with_context(
293293/// inside a macro expansion, or the original span if it is not. Note this will return `None` in the
294294/// case of the span being in a macro expansion, but the target context is from expanding a macro
295295/// argument.
296+ ///
297+ /// Given the following
298+ ///
299+ /// ```rust,ignore
300+ /// macro_rules! m { ($e:expr) => { f($e) }; }
301+ /// g(m!(0))
302+ /// ```
303+ ///
304+ /// If called with a span of the call to `f` and a context of the call to `g` this will return a
305+ /// span containing `m!(0)`. However, if called with a span of the literal `0` this will give a span
306+ /// containing `0` as the context is the same as the outer context.
307+ ///
308+ /// This will traverse through multiple macro calls. Given the following:
309+ ///
310+ /// ```rust,ignore
311+ /// macro_rules! m { ($e:expr) => { n!($e, 0) }; }
312+ /// macro_rules! n { ($e:expr, $f:expr) => { f($e, $f) }; }
313+ /// g(m!(0))
314+ /// ```
315+ ///
316+ /// If called with a span of the call to `f` and a context of the call to `g` this will return a
317+ /// span containing `m!(0)`.
296318pub fn walk_span_to_context ( span : Span , outer : SyntaxContext ) -> Option < Span > {
297319 let outer_span = hygiene:: walk_chain ( span, outer) ;
298320 ( outer_span. ctxt ( ) == outer) . then ( || outer_span)
You can’t perform that action at this time.
0 commit comments