@@ -23,7 +23,7 @@ use rustc_middle::mir::{
2323use rustc_middle:: ty:: TyCtxt ;
2424use rustc_span:: def_id:: LocalDefId ;
2525use rustc_span:: source_map:: SourceMap ;
26- use rustc_span:: { ExpnKind , Span , Symbol } ;
26+ use rustc_span:: { Span , Symbol } ;
2727
2828/// Inserts `StatementKind::Coverage` statements that either instrument the binary with injected
2929/// counters, via intrinsic `llvm.instrprof.increment`, and/or inject metadata used during codegen
@@ -346,21 +346,10 @@ fn get_body_span<'tcx>(
346346 let mut body_span = hir_body. value . span ;
347347
348348 if tcx. is_closure ( def_id. to_def_id ( ) ) {
349- // If the MIR function is a closure, and if the closure body span
350- // starts from a macro, but it's content is not in that macro, try
351- // to find a non-macro callsite, and instrument the spans there
352- // instead.
353- loop {
354- let expn_data = body_span. ctxt ( ) . outer_expn_data ( ) ;
355- if expn_data. is_root ( ) {
356- break ;
357- }
358- if let ExpnKind :: Macro { .. } = expn_data. kind {
359- body_span = expn_data. call_site ;
360- } else {
361- break ;
362- }
363- }
349+ // If the current function is a closure, and its "body" span was created
350+ // by macro expansion or compiler desugaring, try to walk backwards to
351+ // the pre-expansion call site or body.
352+ body_span = body_span. source_callsite ( ) ;
364353 }
365354
366355 body_span
0 commit comments