@@ -305,6 +305,13 @@ impl Span {
305
305
}
306
306
}
307
307
308
+ /// Returns `true` if this span comes from any kind of macro, desugaring or inlining.
309
+ #[ inline]
310
+ pub fn from_expansion ( self ) -> bool {
311
+ // If the span is fully inferred then ctxt > MAX_CTXT
312
+ self . inline_ctxt ( ) . map_or ( true , |ctxt| !ctxt. is_root ( ) )
313
+ }
314
+
308
315
/// Returns `true` if this is a dummy span with any hygienic context.
309
316
#[ inline]
310
317
pub fn is_dummy ( self ) -> bool {
@@ -372,9 +379,10 @@ impl Span {
372
379
pub fn eq_ctxt ( self , other : Span ) -> bool {
373
380
match ( self . inline_ctxt ( ) , other. inline_ctxt ( ) ) {
374
381
( Ok ( ctxt1) , Ok ( ctxt2) ) => ctxt1 == ctxt2,
375
- ( Ok ( ctxt) , Err ( index) ) | ( Err ( index) , Ok ( ctxt) ) => {
376
- with_span_interner ( |interner| ctxt == interner. spans [ index] . ctxt )
377
- }
382
+ // If `inline_ctxt` returns `Ok` the context is <= MAX_CTXT.
383
+ // If it returns `Err` the span is fully interned and the context is > MAX_CTXT.
384
+ // As these do not overlap an `Ok` and `Err` result cannot have an equal context.
385
+ ( Ok ( _) , Err ( _) ) | ( Err ( _) , Ok ( _) ) => false ,
378
386
( Err ( index1) , Err ( index2) ) => with_span_interner ( |interner| {
379
387
interner. spans [ index1] . ctxt == interner. spans [ index2] . ctxt
380
388
} ) ,
0 commit comments