File tree Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -306,8 +306,21 @@ impl Span {
306306 /// Returns `true` if this span comes from any kind of macro, desugaring or inlining.
307307 #[ inline]
308308 pub fn from_expansion ( self ) -> bool {
309- // If the span is fully inferred then ctxt > MAX_CTXT
310- self . inline_ctxt ( ) . map_or ( true , |ctxt| !ctxt. is_root ( ) )
309+ let ctxt = match_span_kind ! {
310+ self ,
311+ // All branches here, except `InlineParent`, actually return `span.ctxt_or_parent_or_marker`.
312+ // Since `Interned` is selected if the field contains `CTXT_INTERNED_MARKER` returning that value
313+ // as the context allows the compiler to optimize out the branch that selects between either
314+ // `Interned` and `PartiallyInterned`.
315+ //
316+ // Interned contexts can never be the root context and `CTXT_INTERNED_MARKER` has a different value
317+ // than the root context so this works for checking is this is an expansion.
318+ InlineCtxt ( span) => SyntaxContext :: from_u16( span. ctxt) ,
319+ InlineParent ( _span) => SyntaxContext :: root( ) ,
320+ PartiallyInterned ( span) => SyntaxContext :: from_u16( span. ctxt) ,
321+ Interned ( _span) => SyntaxContext :: from_u16( CTXT_INTERNED_MARKER ) ,
322+ } ;
323+ !ctxt. is_root ( )
311324 }
312325
313326 /// Returns `true` if this is a dummy span with any hygienic context.
You can’t perform that action at this time.
0 commit comments