@@ -33,7 +33,7 @@ use visit::Visitor;
33
33
use std_inject;
34
34
35
35
use std:: collections:: HashSet ;
36
-
36
+ use std :: env ;
37
37
38
38
pub fn expand_expr ( e : P < ast:: Expr > , fld : & mut MacroExpander ) -> P < ast:: Expr > {
39
39
let expr_span = e. span ;
@@ -1275,11 +1275,41 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
1275
1275
}
1276
1276
1277
1277
fn new_span ( cx : & ExtCtxt , sp : Span ) -> Span {
1278
- /* this discards information in the case of macro-defining macros */
1279
- Span {
1280
- lo : sp. lo ,
1281
- hi : sp. hi ,
1282
- expn_id : cx. backtrace ( ) ,
1278
+ debug ! ( "new_span(sp={:?})" , sp) ;
1279
+
1280
+ if cx. codemap ( ) . more_specific_trace ( sp. expn_id , cx. backtrace ( ) ) {
1281
+ // If the span we are looking at has a backtrace that has more
1282
+ // detail than our current backtrace, then we keep that
1283
+ // backtrace. Honestly, I have no idea if this makes sense,
1284
+ // because I have no idea why we are stripping the backtrace
1285
+ // below. But the reason I made this change is because, in
1286
+ // deriving, we were generating attributes with a specific
1287
+ // backtrace, which was essential for `#[structural_match]` to
1288
+ // be properly supported, but these backtraces were being
1289
+ // stripped and replaced with a null backtrace. Sort of
1290
+ // unclear why this is the case. --nmatsakis
1291
+ debug ! ( "new_span: keeping trace from {:?} because it is more specific" ,
1292
+ sp. expn_id) ;
1293
+ sp
1294
+ } else {
1295
+ // This discards information in the case of macro-defining macros.
1296
+ //
1297
+ // The comment above was originally added in
1298
+ // b7ec2488ff2f29681fe28691d20fd2c260a9e454 in Feb 2012. I
1299
+ // *THINK* the reason we are doing this is because we want to
1300
+ // replace the backtrace of the macro contents with the
1301
+ // backtrace that contains the macro use. But it's pretty
1302
+ // unclear to me. --nmatsakis
1303
+ let sp1 = Span {
1304
+ lo : sp. lo ,
1305
+ hi : sp. hi ,
1306
+ expn_id : cx. backtrace ( ) ,
1307
+ } ;
1308
+ debug ! ( "new_span({:?}) = {:?}" , sp, sp1) ;
1309
+ if sp. expn_id . into_u32 ( ) == 0 && env:: var_os ( "NDM" ) . is_some ( ) {
1310
+ panic ! ( "NDM" ) ;
1311
+ }
1312
+ sp1
1283
1313
}
1284
1314
}
1285
1315
0 commit comments