@@ -21,7 +21,7 @@ use rustc_middle::mir::*;
21
21
use rustc_middle:: thir:: { self , * } ;
22
22
use rustc_middle:: ty:: { self , CanonicalUserTypeAnnotation , Ty } ;
23
23
use rustc_span:: symbol:: Symbol ;
24
- use rustc_span:: Span ;
24
+ use rustc_span:: { BytePos , Pos , Span } ;
25
25
use rustc_target:: abi:: VariantIdx ;
26
26
use smallvec:: { smallvec, SmallVec } ;
27
27
@@ -143,8 +143,15 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
143
143
let mut candidates =
144
144
arm_candidates. iter_mut ( ) . map ( |( _, candidate) | candidate) . collect :: < Vec < _ > > ( ) ;
145
145
146
- let fake_borrow_temps =
147
- self . lower_match_tree ( block, scrutinee_span, match_has_guard, & mut candidates) ;
146
+ let match_start_span = span. shrink_to_lo ( ) . to ( scrutinee. span ) ;
147
+
148
+ let fake_borrow_temps = self . lower_match_tree (
149
+ block,
150
+ scrutinee_span,
151
+ match_start_span,
152
+ match_has_guard,
153
+ & mut candidates,
154
+ ) ;
148
155
149
156
self . lower_match_arms (
150
157
destination,
@@ -224,6 +231,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
224
231
& mut self ,
225
232
block : BasicBlock ,
226
233
scrutinee_span : Span ,
234
+ match_start_span : Span ,
227
235
match_has_guard : bool ,
228
236
candidates : & mut [ & mut Candidate < ' pat , ' tcx > ] ,
229
237
) -> Vec < ( Place < ' tcx > , Local ) > {
@@ -236,7 +244,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
236
244
237
245
// This will generate code to test scrutinee_place and
238
246
// branch to the appropriate arm block
239
- self . match_candidates ( scrutinee_span, block, & mut otherwise, candidates, & mut fake_borrows) ;
247
+ self . match_candidates (
248
+ match_start_span,
249
+ scrutinee_span,
250
+ block,
251
+ & mut otherwise,
252
+ candidates,
253
+ & mut fake_borrows,
254
+ ) ;
240
255
241
256
if let Some ( otherwise_block) = otherwise {
242
257
// See the doc comment on `match_candidates` for why we may have an
@@ -339,8 +354,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
339
354
// all the arm blocks will rejoin here
340
355
let end_block = self . cfg . start_new_block ( ) ;
341
356
357
+ let end_brace = self . source_info (
358
+ outer_source_info. span . with_lo ( outer_source_info. span . hi ( ) - BytePos :: from_usize ( 1 ) ) ,
359
+ ) ;
342
360
for arm_block in arm_end_blocks {
343
- self . cfg . goto ( unpack ! ( arm_block) , outer_source_info, end_block) ;
361
+ let block = & self . cfg . basic_blocks [ arm_block. 0 ] ;
362
+ let last_location = block. statements . last ( ) . map ( |s| s. source_info ) ;
363
+
364
+ self . cfg . goto ( unpack ! ( arm_block) , last_location. unwrap_or ( end_brace) , end_block) ;
344
365
}
345
366
346
367
self . source_scope = outer_source_info. scope ;
@@ -533,8 +554,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
533
554
set_match_place : bool ,
534
555
) -> BlockAnd < ( ) > {
535
556
let mut candidate = Candidate :: new ( initializer. clone ( ) , & irrefutable_pat, false ) ;
536
- let fake_borrow_temps =
537
- self . lower_match_tree ( block, irrefutable_pat. span , false , & mut [ & mut candidate] ) ;
557
+ let fake_borrow_temps = self . lower_match_tree (
558
+ block,
559
+ irrefutable_pat. span ,
560
+ irrefutable_pat. span ,
561
+ false ,
562
+ & mut [ & mut candidate] ,
563
+ ) ;
538
564
// For matches and function arguments, the place that is being matched
539
565
// can be set when creating the variables. But the place for
540
566
// let PATTERN = ... might not even exist until we do the assignment.
@@ -993,6 +1019,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
993
1019
fn match_candidates < ' pat > (
994
1020
& mut self ,
995
1021
span : Span ,
1022
+ scrutinee_span : Span ,
996
1023
start_block : BasicBlock ,
997
1024
otherwise_block : & mut Option < BasicBlock > ,
998
1025
candidates : & mut [ & mut Candidate < ' pat , ' tcx > ] ,
@@ -1022,6 +1049,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
1022
1049
}
1023
1050
self . match_simplified_candidates (
1024
1051
span,
1052
+ scrutinee_span,
1025
1053
start_block,
1026
1054
otherwise_block,
1027
1055
& mut * new_candidates,
@@ -1030,6 +1058,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
1030
1058
} else {
1031
1059
self . match_simplified_candidates (
1032
1060
span,
1061
+ scrutinee_span,
1033
1062
start_block,
1034
1063
otherwise_block,
1035
1064
candidates,
@@ -1042,6 +1071,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
1042
1071
fn match_simplified_candidates (
1043
1072
& mut self ,
1044
1073
span : Span ,
1074
+ scrutinee_span : Span ,
1045
1075
start_block : BasicBlock ,
1046
1076
otherwise_block : & mut Option < BasicBlock > ,
1047
1077
candidates : & mut [ & mut Candidate < ' _ , ' tcx > ] ,
@@ -1087,6 +1117,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
1087
1117
// Test for the remaining candidates.
1088
1118
self . test_candidates_with_or (
1089
1119
span,
1120
+ scrutinee_span,
1090
1121
unmatched_candidates,
1091
1122
block,
1092
1123
otherwise_block,
@@ -1257,6 +1288,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
1257
1288
fn test_candidates_with_or (
1258
1289
& mut self ,
1259
1290
span : Span ,
1291
+ scrutinee_span : Span ,
1260
1292
candidates : & mut [ & mut Candidate < ' _ , ' tcx > ] ,
1261
1293
block : BasicBlock ,
1262
1294
otherwise_block : & mut Option < BasicBlock > ,
@@ -1269,7 +1301,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
1269
1301
match * first_candidate. match_pairs [ 0 ] . pattern . kind {
1270
1302
PatKind :: Or { .. } => ( ) ,
1271
1303
_ => {
1272
- self . test_candidates ( span, candidates, block, otherwise_block, fake_borrows) ;
1304
+ self . test_candidates (
1305
+ span,
1306
+ scrutinee_span,
1307
+ candidates,
1308
+ block,
1309
+ otherwise_block,
1310
+ fake_borrows,
1311
+ ) ;
1273
1312
return ;
1274
1313
}
1275
1314
}
@@ -1302,6 +1341,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
1302
1341
1303
1342
self . match_candidates (
1304
1343
span,
1344
+ scrutinee_span,
1305
1345
remainder_start,
1306
1346
otherwise_block,
1307
1347
remaining_candidates,
@@ -1330,6 +1370,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
1330
1370
otherwise
1331
1371
} ;
1332
1372
self . match_candidates (
1373
+ or_span,
1333
1374
or_span,
1334
1375
candidate. pre_binding_block . unwrap ( ) ,
1335
1376
otherwise,
@@ -1497,6 +1538,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
1497
1538
fn test_candidates < ' pat , ' b , ' c > (
1498
1539
& mut self ,
1499
1540
span : Span ,
1541
+ scrutinee_span : Span ,
1500
1542
mut candidates : & ' b mut [ & ' c mut Candidate < ' pat , ' tcx > ] ,
1501
1543
block : BasicBlock ,
1502
1544
otherwise_block : & mut Option < BasicBlock > ,
@@ -1591,6 +1633,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
1591
1633
let candidate_start = this. cfg . start_new_block ( ) ;
1592
1634
this. match_candidates (
1593
1635
span,
1636
+ scrutinee_span,
1594
1637
candidate_start,
1595
1638
remainder_start,
1596
1639
& mut * candidates,
@@ -1607,6 +1650,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
1607
1650
let remainder_start = remainder_start. unwrap_or_else ( || this. cfg . start_new_block ( ) ) ;
1608
1651
this. match_candidates (
1609
1652
span,
1653
+ scrutinee_span,
1610
1654
remainder_start,
1611
1655
otherwise_block,
1612
1656
candidates,
@@ -1617,7 +1661,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
1617
1661
target_blocks
1618
1662
} ;
1619
1663
1620
- self . perform_test ( block, match_place, & test, make_target_blocks) ;
1664
+ self . perform_test ( span , scrutinee_span , block, match_place, & test, make_target_blocks) ;
1621
1665
}
1622
1666
1623
1667
/// Determine the fake borrows that are needed from a set of places that
@@ -1713,6 +1757,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
1713
1757
let fake_borrow_temps = self . lower_match_tree (
1714
1758
block,
1715
1759
pat. span ,
1760
+ pat. span ,
1716
1761
false ,
1717
1762
& mut [ & mut guard_candidate, & mut otherwise_candidate] ,
1718
1763
) ;
0 commit comments