@@ -409,101 +409,6 @@ impl CodeMap {
409
409
hi. col. to_usize( ) + 1 ) ) . to_string ( )
410
410
}
411
411
412
- // Returns true if two spans have the same callee
413
- // (Assumes the same ExpnFormat implies same callee)
414
- fn match_callees ( & self , sp_a : & Span , sp_b : & Span ) -> bool {
415
- let fmt_a = self
416
- . with_expn_info ( sp_a. expn_id ,
417
- |ei| ei. map ( |ei| ei. callee . format . clone ( ) ) ) ;
418
-
419
- let fmt_b = self
420
- . with_expn_info ( sp_b. expn_id ,
421
- |ei| ei. map ( |ei| ei. callee . format . clone ( ) ) ) ;
422
- fmt_a == fmt_b
423
- }
424
-
425
- /// Returns a formatted string showing the expansion chain of a span
426
- ///
427
- /// Spans are printed in the following format:
428
- ///
429
- /// filename:start_line:col: end_line:col
430
- /// snippet
431
- /// Callee:
432
- /// Callee span
433
- /// Callsite:
434
- /// Callsite span
435
- ///
436
- /// Callees and callsites are printed recursively (if available, otherwise header
437
- /// and span is omitted), expanding into their own callee/callsite spans.
438
- /// Each layer of recursion has an increased indent, and snippets are truncated
439
- /// to at most 50 characters. Finally, recursive calls to the same macro are squashed,
440
- /// with '...' used to represent any number of recursive calls.
441
- pub fn span_to_expanded_string ( & self , sp : Span ) -> String {
442
- self . span_to_expanded_string_internal ( sp, "" )
443
- }
444
-
445
- fn span_to_expanded_string_internal ( & self , sp : Span , indent : & str ) -> String {
446
- let mut indent = indent. to_owned ( ) ;
447
- let mut output = "" . to_owned ( ) ;
448
- let span_str = self . span_to_string ( sp) ;
449
- let mut span_snip = self . span_to_snippet ( sp)
450
- . unwrap_or ( "Snippet unavailable" . to_owned ( ) ) ;
451
-
452
- // Truncate by code points - in worst case this will be more than 50 characters,
453
- // but ensures at least 50 characters and respects byte boundaries.
454
- let char_vec: Vec < ( usize , char ) > = span_snip. char_indices ( ) . collect ( ) ;
455
- if char_vec. len ( ) > 50 {
456
- span_snip. truncate ( char_vec[ 49 ] . 0 ) ;
457
- span_snip. push_str ( "..." ) ;
458
- }
459
-
460
- output. push_str ( & format ! ( "{}{}\n {}`{}`\n " , indent, span_str, indent, span_snip) ) ;
461
-
462
- if sp. expn_id == NO_EXPANSION || sp. expn_id == COMMAND_LINE_EXPN {
463
- return output;
464
- }
465
-
466
- let mut callee = self . with_expn_info ( sp. expn_id ,
467
- |ei| ei. and_then ( |ei| ei. callee . span . clone ( ) ) ) ;
468
- let mut callsite = self . with_expn_info ( sp. expn_id ,
469
- |ei| ei. map ( |ei| ei. call_site . clone ( ) ) ) ;
470
-
471
- indent. push_str ( " " ) ;
472
- let mut is_recursive = false ;
473
-
474
- while callee. is_some ( ) && self . match_callees ( & sp, & callee. unwrap ( ) ) {
475
- callee = self . with_expn_info ( callee. unwrap ( ) . expn_id ,
476
- |ei| ei. and_then ( |ei| ei. callee . span . clone ( ) ) ) ;
477
- is_recursive = true ;
478
- }
479
- if let Some ( span) = callee {
480
- output. push_str ( & indent) ;
481
- output. push_str ( "Callee:\n " ) ;
482
- if is_recursive {
483
- output. push_str ( & indent) ;
484
- output. push_str ( "...\n " ) ;
485
- }
486
- output. push_str ( & ( self . span_to_expanded_string_internal ( span, & indent) ) ) ;
487
- }
488
-
489
- is_recursive = false ;
490
- while callsite. is_some ( ) && self . match_callees ( & sp, & callsite. unwrap ( ) ) {
491
- callsite = self . with_expn_info ( callsite. unwrap ( ) . expn_id ,
492
- |ei| ei. map ( |ei| ei. call_site . clone ( ) ) ) ;
493
- is_recursive = true ;
494
- }
495
- if let Some ( span) = callsite {
496
- output. push_str ( & indent) ;
497
- output. push_str ( "Callsite:\n " ) ;
498
- if is_recursive {
499
- output. push_str ( & indent) ;
500
- output. push_str ( "...\n " ) ;
501
- }
502
- output. push_str ( & ( self . span_to_expanded_string_internal ( span, & indent) ) ) ;
503
- }
504
- output
505
- }
506
-
507
412
/// Return the source span - this is either the supplied span, or the span for
508
413
/// the macro callsite that expanded to it.
509
414
pub fn source_callsite ( & self , sp : Span ) -> Span {
@@ -1069,59 +974,6 @@ mod tests {
1069
974
assert_eq ! ( sstr, "blork.rs:2:1: 2:12" ) ;
1070
975
}
1071
976
1072
- #[ test]
1073
- fn t10 ( ) {
1074
- // Test span_to_expanded_string works in base case (no expansion)
1075
- let cm = init_code_map ( ) ;
1076
- let span = Span { lo : BytePos ( 0 ) , hi : BytePos ( 11 ) , expn_id : NO_EXPANSION } ;
1077
- let sstr = cm. span_to_expanded_string ( span) ;
1078
- assert_eq ! ( sstr, "blork.rs:1:1: 1:12\n `first line.`\n " ) ;
1079
-
1080
- let span = Span { lo : BytePos ( 12 ) , hi : BytePos ( 23 ) , expn_id : NO_EXPANSION } ;
1081
- let sstr = cm. span_to_expanded_string ( span) ;
1082
- assert_eq ! ( sstr, "blork.rs:2:1: 2:12\n `second line`\n " ) ;
1083
- }
1084
-
1085
- #[ test]
1086
- fn t11 ( ) {
1087
- // Test span_to_expanded_string works with expansion
1088
- let cm = init_code_map ( ) ;
1089
- let root = Span { lo : BytePos ( 0 ) , hi : BytePos ( 11 ) , expn_id : NO_EXPANSION } ;
1090
- let format = ExpnFormat :: MacroBang ( keywords:: Invalid . name ( ) ) ;
1091
- let callee = NameAndSpan { format : format,
1092
- allow_internal_unstable : false ,
1093
- span : None } ;
1094
-
1095
- let info = ExpnInfo { call_site : root, callee : callee } ;
1096
- let id = cm. record_expansion ( info) ;
1097
- let sp = Span { lo : BytePos ( 12 ) , hi : BytePos ( 23 ) , expn_id : id } ;
1098
-
1099
- let sstr = cm. span_to_expanded_string ( sp) ;
1100
- assert_eq ! ( sstr,
1101
- "blork.rs:2:1: 2:12\n `second line`\n Callsite:\n \
1102
- blork.rs:1:1: 1:12\n `first line.`\n ") ;
1103
- }
1104
-
1105
- /// Test merging two spans on the same line
1106
- #[ test]
1107
- fn span_merging ( ) {
1108
- let cm = CodeMap :: new ( ) ;
1109
- let inputtext = "bbbb BB bb CCC\n " ;
1110
- let selection1 = " ~~ \n " ;
1111
- let selection2 = " ~~~\n " ;
1112
- cm. new_filemap_and_lines ( "blork.rs" , None , inputtext) ;
1113
- let span1 = span_from_selection ( inputtext, selection1) ;
1114
- let span2 = span_from_selection ( inputtext, selection2) ;
1115
-
1116
- if let Some ( sp) = cm. merge_spans ( span1, span2) {
1117
- let sstr = cm. span_to_expanded_string ( sp) ;
1118
- assert_eq ! ( sstr, "blork.rs:1:6: 1:15\n `BB bb CCC`\n " ) ;
1119
- }
1120
- else {
1121
- assert ! ( false ) ;
1122
- }
1123
- }
1124
-
1125
977
/// Test failing to merge two spans on different lines
1126
978
#[ test]
1127
979
fn span_merging_fail ( ) {
@@ -1221,41 +1073,4 @@ mod tests {
1221
1073
let id_end = cm. record_expansion ( info_end) ;
1222
1074
Span { lo : BytePos ( 37 ) , hi : BytePos ( 48 ) , expn_id : id_end }
1223
1075
}
1224
-
1225
- #[ test]
1226
- fn t12 ( ) {
1227
- // Test span_to_expanded_string collapses recursive macros and handles
1228
- // recursive callsite and callee expansions
1229
- let cm = init_code_map ( ) ;
1230
- let end = init_expansion_chain ( & cm) ;
1231
- let sstr = cm. span_to_expanded_string ( end) ;
1232
- let res_str =
1233
- r"blork2.rs:2:1: 2:12
1234
- `second line`
1235
- Callsite:
1236
- ...
1237
- blork2.rs:1:1: 1:12
1238
- `first line.`
1239
- Callee:
1240
- blork.rs:2:1: 2:12
1241
- `second line`
1242
- Callee:
1243
- blork.rs:1:1: 1:12
1244
- `first line.`
1245
- Callsite:
1246
- blork.rs:1:1: 1:12
1247
- `first line.`
1248
- Callsite:
1249
- ...
1250
- blork.rs:2:1: 2:12
1251
- `second line`
1252
- Callee:
1253
- blork.rs:1:1: 1:12
1254
- `first line.`
1255
- Callsite:
1256
- blork.rs:1:1: 1:12
1257
- `first line.`
1258
- " ;
1259
- assert_eq ! ( sstr, res_str) ;
1260
- }
1261
1076
}
0 commit comments