@@ -244,25 +244,29 @@ impl<'a> ConstantExpr<'a> {
244
244
// An option identifying a branch (either a literal, an enum variant or a range)
245
245
#[ derive( Debug ) ]
246
246
enum Opt < ' a , ' tcx > {
247
- ConstantValue ( ConstantExpr < ' a > ) ,
248
- ConstantRange ( ConstantExpr < ' a > , ConstantExpr < ' a > ) ,
249
- Variant ( ty:: Disr , Rc < adt:: Repr < ' tcx > > , ast:: DefId ) ,
250
- SliceLengthEqual ( uint ) ,
251
- SliceLengthGreaterOrEqual ( /* prefix length */ uint , /* suffix length */ uint ) ,
247
+ ConstantValue ( ConstantExpr < ' a > , DebugLoc ) ,
248
+ ConstantRange ( ConstantExpr < ' a > , ConstantExpr < ' a > , DebugLoc ) ,
249
+ Variant ( ty:: Disr , Rc < adt:: Repr < ' tcx > > , ast:: DefId , DebugLoc ) ,
250
+ SliceLengthEqual ( uint , DebugLoc ) ,
251
+ SliceLengthGreaterOrEqual ( /* prefix length */ uint ,
252
+ /* suffix length */ uint ,
253
+ DebugLoc ) ,
252
254
}
253
255
254
256
impl < ' a , ' tcx > Opt < ' a , ' tcx > {
255
257
fn eq ( & self , other : & Opt < ' a , ' tcx > , tcx : & ty:: ctxt < ' tcx > ) -> bool {
256
258
match ( self , other) {
257
- ( & ConstantValue ( a) , & ConstantValue ( b) ) => a. eq ( b, tcx) ,
258
- ( & ConstantRange ( a1, a2) , & ConstantRange ( b1, b2) ) => {
259
+ ( & ConstantValue ( a, _ ) , & ConstantValue ( b, _ ) ) => a. eq ( b, tcx) ,
260
+ ( & ConstantRange ( a1, a2, _ ) , & ConstantRange ( b1, b2, _ ) ) => {
259
261
a1. eq ( b1, tcx) && a2. eq ( b2, tcx)
260
262
}
261
- ( & Variant ( a_disr, ref a_repr, a_def) , & Variant ( b_disr, ref b_repr, b_def) ) => {
263
+ ( & Variant ( a_disr, ref a_repr, a_def, _) ,
264
+ & Variant ( b_disr, ref b_repr, b_def, _) ) => {
262
265
a_disr == b_disr && * a_repr == * b_repr && a_def == b_def
263
266
}
264
- ( & SliceLengthEqual ( a) , & SliceLengthEqual ( b) ) => a == b,
265
- ( & SliceLengthGreaterOrEqual ( a1, a2) , & SliceLengthGreaterOrEqual ( b1, b2) ) => {
267
+ ( & SliceLengthEqual ( a, _) , & SliceLengthEqual ( b, _) ) => a == b,
268
+ ( & SliceLengthGreaterOrEqual ( a1, a2, _) ,
269
+ & SliceLengthGreaterOrEqual ( b1, b2, _) ) => {
266
270
a1 == b1 && a2 == b2
267
271
}
268
272
_ => false
@@ -273,29 +277,39 @@ impl<'a, 'tcx> Opt<'a, 'tcx> {
273
277
let _icx = push_ctxt ( "match::trans_opt" ) ;
274
278
let ccx = bcx. ccx ( ) ;
275
279
match * self {
276
- ConstantValue ( ConstantExpr ( lit_expr) ) => {
280
+ ConstantValue ( ConstantExpr ( lit_expr) , _ ) => {
277
281
let lit_ty = ty:: node_id_to_type ( bcx. tcx ( ) , lit_expr. id ) ;
278
282
let ( llval, _) = consts:: const_expr ( ccx, & * lit_expr) ;
279
283
let lit_datum = immediate_rvalue ( llval, lit_ty) ;
280
284
let lit_datum = unpack_datum ! ( bcx, lit_datum. to_appropriate_datum( bcx) ) ;
281
285
SingleResult ( Result :: new ( bcx, lit_datum. val ) )
282
286
}
283
- ConstantRange ( ConstantExpr ( ref l1) , ConstantExpr ( ref l2) ) => {
287
+ ConstantRange ( ConstantExpr ( ref l1) , ConstantExpr ( ref l2) , _ ) => {
284
288
let ( l1, _) = consts:: const_expr ( ccx, & * * l1) ;
285
289
let ( l2, _) = consts:: const_expr ( ccx, & * * l2) ;
286
290
RangeResult ( Result :: new ( bcx, l1) , Result :: new ( bcx, l2) )
287
291
}
288
- Variant ( disr_val, ref repr, _) => {
292
+ Variant ( disr_val, ref repr, _, _ ) => {
289
293
adt:: trans_case ( bcx, & * * repr, disr_val)
290
294
}
291
- SliceLengthEqual ( length) => {
295
+ SliceLengthEqual ( length, _ ) => {
292
296
SingleResult ( Result :: new ( bcx, C_uint ( ccx, length) ) )
293
297
}
294
- SliceLengthGreaterOrEqual ( prefix, suffix) => {
298
+ SliceLengthGreaterOrEqual ( prefix, suffix, _ ) => {
295
299
LowerBound ( Result :: new ( bcx, C_uint ( ccx, prefix + suffix) ) )
296
300
}
297
301
}
298
302
}
303
+
304
+ fn debug_loc ( & self ) -> DebugLoc {
305
+ match * self {
306
+ ConstantValue ( _, debug_loc) |
307
+ ConstantRange ( _, _, debug_loc) |
308
+ Variant ( _, _, _, debug_loc) |
309
+ SliceLengthEqual ( _, debug_loc) |
310
+ SliceLengthGreaterOrEqual ( _, _, debug_loc) => debug_loc
311
+ }
312
+ }
299
313
}
300
314
301
315
#[ derive( Copy , PartialEq ) ]
@@ -527,18 +541,18 @@ fn enter_opt<'a, 'p, 'blk, 'tcx>(
527
541
let _indenter = indenter ( ) ;
528
542
529
543
let ctor = match opt {
530
- & ConstantValue ( ConstantExpr ( expr) ) => check_match:: ConstantValue (
544
+ & ConstantValue ( ConstantExpr ( expr) , _ ) => check_match:: ConstantValue (
531
545
const_eval:: eval_const_expr ( bcx. tcx ( ) , & * expr)
532
546
) ,
533
- & ConstantRange ( ConstantExpr ( lo) , ConstantExpr ( hi) ) => check_match:: ConstantRange (
547
+ & ConstantRange ( ConstantExpr ( lo) , ConstantExpr ( hi) , _ ) => check_match:: ConstantRange (
534
548
const_eval:: eval_const_expr ( bcx. tcx ( ) , & * lo) ,
535
549
const_eval:: eval_const_expr ( bcx. tcx ( ) , & * hi)
536
550
) ,
537
- & SliceLengthEqual ( n) =>
551
+ & SliceLengthEqual ( n, _ ) =>
538
552
check_match:: Slice ( n) ,
539
- & SliceLengthGreaterOrEqual ( before, after) =>
553
+ & SliceLengthGreaterOrEqual ( before, after, _ ) =>
540
554
check_match:: SliceWithSubslice ( before, after) ,
541
- & Variant ( _, _, def_id) =>
555
+ & Variant ( _, _, def_id, _ ) =>
542
556
check_match:: Constructor :: Variant ( def_id)
543
557
} ;
544
558
@@ -563,27 +577,34 @@ fn get_branches<'a, 'p, 'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
563
577
let mut found: Vec < Opt > = vec ! [ ] ;
564
578
for br in m {
565
579
let cur = br. pats [ col] ;
580
+ let debug_loc = DebugLoc :: At ( cur. id , cur. span ) ;
581
+
566
582
let opt = match cur. node {
567
- ast:: PatLit ( ref l) => ConstantValue ( ConstantExpr ( & * * l) ) ,
583
+ ast:: PatLit ( ref l) => {
584
+ ConstantValue ( ConstantExpr ( & * * l) , debug_loc)
585
+ }
568
586
ast:: PatIdent ( ..) | ast:: PatEnum ( ..) | ast:: PatStruct ( ..) => {
569
587
// This is either an enum variant or a variable binding.
570
588
let opt_def = tcx. def_map . borrow ( ) . get ( & cur. id ) . cloned ( ) ;
571
589
match opt_def {
572
590
Some ( def:: DefVariant ( enum_id, var_id, _) ) => {
573
591
let variant = ty:: enum_variant_with_id ( tcx, enum_id, var_id) ;
574
- Variant ( variant. disr_val , adt:: represent_node ( bcx, cur. id ) , var_id)
592
+ Variant ( variant. disr_val ,
593
+ adt:: represent_node ( bcx, cur. id ) ,
594
+ var_id,
595
+ debug_loc)
575
596
}
576
597
_ => continue
577
598
}
578
599
}
579
600
ast:: PatRange ( ref l1, ref l2) => {
580
- ConstantRange ( ConstantExpr ( & * * l1) , ConstantExpr ( & * * l2) )
601
+ ConstantRange ( ConstantExpr ( & * * l1) , ConstantExpr ( & * * l2) , debug_loc )
581
602
}
582
603
ast:: PatVec ( ref before, None , ref after) => {
583
- SliceLengthEqual ( before. len ( ) + after. len ( ) )
604
+ SliceLengthEqual ( before. len ( ) + after. len ( ) , debug_loc )
584
605
}
585
606
ast:: PatVec ( ref before, Some ( _) , ref after) => {
586
- SliceLengthGreaterOrEqual ( before. len ( ) , after. len ( ) )
607
+ SliceLengthGreaterOrEqual ( before. len ( ) , after. len ( ) , debug_loc )
587
608
}
588
609
_ => continue
589
610
} ;
@@ -779,19 +800,21 @@ fn pick_column_to_specialize(def_map: &DefMap, m: &[Match]) -> Option<uint> {
779
800
fn compare_values < ' blk , ' tcx > ( cx : Block < ' blk , ' tcx > ,
780
801
lhs : ValueRef ,
781
802
rhs : ValueRef ,
782
- rhs_t : Ty < ' tcx > )
803
+ rhs_t : Ty < ' tcx > ,
804
+ debug_loc : DebugLoc )
783
805
-> Result < ' blk , ' tcx > {
784
806
fn compare_str < ' blk , ' tcx > ( cx : Block < ' blk , ' tcx > ,
785
807
lhs : ValueRef ,
786
808
rhs : ValueRef ,
787
- rhs_t : Ty < ' tcx > )
809
+ rhs_t : Ty < ' tcx > ,
810
+ debug_loc : DebugLoc )
788
811
-> Result < ' blk , ' tcx > {
789
812
let did = langcall ( cx,
790
813
None ,
791
814
& format ! ( "comparison of `{}`" ,
792
815
cx. ty_to_string( rhs_t) ) [ ] ,
793
816
StrEqFnLangItem ) ;
794
- callee:: trans_lang_call ( cx, did, & [ lhs, rhs] , None )
817
+ callee:: trans_lang_call ( cx, did, & [ lhs, rhs] , None , debug_loc )
795
818
}
796
819
797
820
let _icx = push_ctxt ( "compare_values" ) ;
@@ -802,7 +825,7 @@ fn compare_values<'blk, 'tcx>(cx: Block<'blk, 'tcx>,
802
825
803
826
match rhs_t. sty {
804
827
ty:: ty_rptr( _, mt) => match mt. ty . sty {
805
- ty:: ty_str => compare_str ( cx, lhs, rhs, rhs_t) ,
828
+ ty:: ty_str => compare_str ( cx, lhs, rhs, rhs_t, debug_loc ) ,
806
829
ty:: ty_vec( ty, _) => match ty. sty {
807
830
ty:: ty_uint( ast:: TyU8 ) => {
808
831
// NOTE: cast &[u8] to &str and abuse the str_eq lang item,
@@ -812,7 +835,7 @@ fn compare_values<'blk, 'tcx>(cx: Block<'blk, 'tcx>,
812
835
ast:: MutImmutable ) ;
813
836
let lhs = BitCast ( cx, lhs, type_of:: type_of ( cx. ccx ( ) , t) . ptr_to ( ) ) ;
814
837
let rhs = BitCast ( cx, rhs, type_of:: type_of ( cx. ccx ( ) , t) . ptr_to ( ) ) ;
815
- compare_str ( cx, lhs, rhs, rhs_t)
838
+ compare_str ( cx, lhs, rhs, rhs_t, debug_loc )
816
839
} ,
817
840
_ => cx. sess ( ) . bug ( "only byte strings supported in compare_values" ) ,
818
841
} ,
@@ -1044,20 +1067,20 @@ fn compile_submatch_continue<'a, 'p, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
1044
1067
debug ! ( "test_val={}" , bcx. val_to_string( test_val) ) ;
1045
1068
if opts. len ( ) > 0 {
1046
1069
match opts[ 0 ] {
1047
- ConstantValue ( _ ) | ConstantRange ( _ , _ ) => {
1070
+ ConstantValue ( .. ) | ConstantRange ( .. ) => {
1048
1071
test_val = load_if_immediate ( bcx, val, left_ty) ;
1049
1072
kind = if ty:: type_is_integral ( left_ty) {
1050
1073
Switch
1051
1074
} else {
1052
1075
Compare
1053
1076
} ;
1054
1077
}
1055
- Variant ( _, ref repr, _) => {
1078
+ Variant ( _, ref repr, _, _ ) => {
1056
1079
let ( the_kind, val_opt) = adt:: trans_switch ( bcx, & * * repr, val) ;
1057
1080
kind = the_kind;
1058
1081
if let Some ( tval) = val_opt { test_val = tval; }
1059
1082
}
1060
- SliceLengthEqual ( _ ) | SliceLengthGreaterOrEqual ( _ , _ ) => {
1083
+ SliceLengthEqual ( .. ) | SliceLengthGreaterOrEqual ( .. ) => {
1061
1084
let ( _, len) = tvec:: get_base_and_len ( bcx, val, left_ty) ;
1062
1085
test_val = len;
1063
1086
kind = Switch ;
@@ -1066,8 +1089,8 @@ fn compile_submatch_continue<'a, 'p, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
1066
1089
}
1067
1090
for o in & opts {
1068
1091
match * o {
1069
- ConstantRange ( _ , _ ) => { kind = Compare ; break } ,
1070
- SliceLengthGreaterOrEqual ( _ , _ ) => { kind = CompareSliceLength ; break } ,
1092
+ ConstantRange ( .. ) => { kind = Compare ; break } ,
1093
+ SliceLengthGreaterOrEqual ( .. ) => { kind = CompareSliceLength ; break } ,
1071
1094
_ => ( )
1072
1095
}
1073
1096
}
@@ -1093,10 +1116,12 @@ fn compile_submatch_continue<'a, 'p, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
1093
1116
// for the current conditional branch.
1094
1117
let mut branch_chk = None ;
1095
1118
let mut opt_cx = else_cx;
1119
+ let debug_loc = opt. debug_loc ( ) ;
1120
+
1096
1121
if !exhaustive || i + 1 < len {
1097
1122
opt_cx = bcx. fcx . new_temp_block ( "match_case" ) ;
1098
1123
match kind {
1099
- Single => Br ( bcx, opt_cx. llbb , DebugLoc :: None ) ,
1124
+ Single => Br ( bcx, opt_cx. llbb , debug_loc ) ,
1100
1125
Switch => {
1101
1126
match opt. trans ( bcx) {
1102
1127
SingleResult ( r) => {
@@ -1119,7 +1144,7 @@ fn compile_submatch_continue<'a, 'p, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
1119
1144
let Result { bcx : after_cx, val : matches } = {
1120
1145
match opt. trans ( bcx) {
1121
1146
SingleResult ( Result { bcx, val } ) => {
1122
- compare_values ( bcx, test_val, val, t)
1147
+ compare_values ( bcx, test_val, val, t, debug_loc )
1123
1148
}
1124
1149
RangeResult ( Result { val : vbegin, .. } ,
1125
1150
Result { bcx, val : vend } ) => {
@@ -1131,7 +1156,7 @@ fn compile_submatch_continue<'a, 'p, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
1131
1156
compare_scalar_types (
1132
1157
bcx, test_val, vend,
1133
1158
t, ast:: BiLe ) ;
1134
- Result :: new ( bcx, And ( bcx, llge, llle, DebugLoc :: None ) )
1159
+ Result :: new ( bcx, And ( bcx, llge, llle, debug_loc ) )
1135
1160
}
1136
1161
LowerBound ( Result { bcx, val } ) => {
1137
1162
compare_scalar_types ( bcx, test_val, val, t, ast:: BiGe )
@@ -1149,37 +1174,37 @@ fn compile_submatch_continue<'a, 'p, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
1149
1174
if i + 1 < len && ( guarded || multi_pats || kind == CompareSliceLength ) {
1150
1175
branch_chk = Some ( JumpToBasicBlock ( bcx. llbb ) ) ;
1151
1176
}
1152
- CondBr ( after_cx, matches, opt_cx. llbb , bcx. llbb , DebugLoc :: None ) ;
1177
+ CondBr ( after_cx, matches, opt_cx. llbb , bcx. llbb , debug_loc ) ;
1153
1178
}
1154
1179
_ => ( )
1155
1180
}
1156
1181
} else if kind == Compare || kind == CompareSliceLength {
1157
- Br ( bcx, else_cx. llbb , DebugLoc :: None ) ;
1182
+ Br ( bcx, else_cx. llbb , debug_loc ) ;
1158
1183
}
1159
1184
1160
1185
let mut size = 0 ;
1161
1186
let mut unpacked = Vec :: new ( ) ;
1162
1187
match * opt {
1163
- Variant ( disr_val, ref repr, _) => {
1188
+ Variant ( disr_val, ref repr, _, _ ) => {
1164
1189
let ExtractedBlock { vals : argvals, bcx : new_bcx} =
1165
1190
extract_variant_args ( opt_cx, & * * repr, disr_val, val) ;
1166
1191
size = argvals. len ( ) ;
1167
1192
unpacked = argvals;
1168
1193
opt_cx = new_bcx;
1169
1194
}
1170
- SliceLengthEqual ( len) => {
1195
+ SliceLengthEqual ( len, _ ) => {
1171
1196
let args = extract_vec_elems ( opt_cx, left_ty, len, 0 , val) ;
1172
1197
size = args. vals . len ( ) ;
1173
1198
unpacked = args. vals . clone ( ) ;
1174
1199
opt_cx = args. bcx ;
1175
1200
}
1176
- SliceLengthGreaterOrEqual ( before, after) => {
1201
+ SliceLengthGreaterOrEqual ( before, after, _ ) => {
1177
1202
let args = extract_vec_elems ( opt_cx, left_ty, before, after, val) ;
1178
1203
size = args. vals . len ( ) ;
1179
1204
unpacked = args. vals . clone ( ) ;
1180
1205
opt_cx = args. bcx ;
1181
1206
}
1182
- ConstantValue ( _ ) | ConstantRange ( _ , _ ) => ( )
1207
+ ConstantValue ( .. ) | ConstantRange ( .. ) => ( )
1183
1208
}
1184
1209
let opt_ms = enter_opt ( opt_cx, pat_id, dm, m, opt, col, size, val) ;
1185
1210
let mut opt_vals = unpacked;
0 commit comments