@@ -15,9 +15,9 @@ use rustc::hir;
15
15
use rustc:: hir:: def_id:: DefId ;
16
16
use rustc:: middle:: region:: ScopeTree ;
17
17
use rustc:: mir:: {
18
- self , AggregateKind , BindingForm , BorrowKind , ClearCrossCrate , FakeReadCause , Field , Local ,
19
- LocalDecl , LocalKind , Location , Operand , Place , PlaceProjection , ProjectionElem , Rvalue ,
20
- Statement , StatementKind , TerminatorKind , VarBindingForm ,
18
+ self , AggregateKind , BindingForm , BorrowKind , ClearCrossCrate , Field , Local ,
19
+ LocalDecl , LocalKind , Location , Operand , Place , PlaceProjection , ProjectionElem ,
20
+ Rvalue , Statement , StatementKind , TerminatorKind , VarBindingForm ,
21
21
} ;
22
22
use rustc:: ty;
23
23
use rustc:: util:: ppaux:: with_highlight_region_for_bound_region;
@@ -262,7 +262,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
262
262
move_spans. var_span_label ( & mut err, "move occurs due to use in closure" ) ;
263
263
264
264
self . explain_why_borrow_contains_point ( context, borrow, None )
265
- . emit ( self . infcx . tcx , & mut err) ;
265
+ . emit ( self . infcx . tcx , & mut err, String :: new ( ) ) ;
266
266
err. buffer ( & mut self . errors_buffer ) ;
267
267
}
268
268
@@ -299,7 +299,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
299
299
} ) ;
300
300
301
301
self . explain_why_borrow_contains_point ( context, borrow, None )
302
- . emit ( self . infcx . tcx , & mut err) ;
302
+ . emit ( self . infcx . tcx , & mut err, String :: new ( ) ) ;
303
303
err. buffer ( & mut self . errors_buffer ) ;
304
304
}
305
305
@@ -319,6 +319,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
319
319
let desc_place = self . describe_place ( place) . unwrap_or ( "_" . to_owned ( ) ) ;
320
320
let tcx = self . infcx . tcx ;
321
321
322
+ let first_borrow_desc;
323
+
322
324
// FIXME: supply non-"" `opt_via` when appropriate
323
325
let mut err = match (
324
326
gen_borrow_kind,
@@ -328,8 +330,23 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
328
330
"immutable" ,
329
331
"mutable" ,
330
332
) {
331
- ( BorrowKind :: Shared , lft, _, BorrowKind :: Mut { .. } , _, rgt)
332
- | ( BorrowKind :: Mut { .. } , _, lft, BorrowKind :: Shared , rgt, _) => {
333
+ ( BorrowKind :: Shared , lft, _, BorrowKind :: Mut { .. } , _, rgt) => {
334
+ first_borrow_desc = "mutable " ;
335
+ tcx. cannot_reborrow_already_borrowed (
336
+ span,
337
+ & desc_place,
338
+ "" ,
339
+ lft,
340
+ issued_span,
341
+ "it" ,
342
+ rgt,
343
+ "" ,
344
+ None ,
345
+ Origin :: Mir ,
346
+ )
347
+ }
348
+ ( BorrowKind :: Mut { .. } , _, lft, BorrowKind :: Shared , rgt, _) => {
349
+ first_borrow_desc = "immutable " ;
333
350
tcx. cannot_reborrow_already_borrowed (
334
351
span,
335
352
& desc_place,
@@ -345,6 +362,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
345
362
}
346
363
347
364
( BorrowKind :: Mut { .. } , _, _, BorrowKind :: Mut { .. } , _, _) => {
365
+ first_borrow_desc = "first " ;
348
366
tcx. cannot_mutably_borrow_multiply (
349
367
span,
350
368
& desc_place,
@@ -357,6 +375,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
357
375
}
358
376
359
377
( BorrowKind :: Unique , _, _, BorrowKind :: Unique , _, _) => {
378
+ first_borrow_desc = "first " ;
360
379
tcx. cannot_uniquely_borrow_by_two_closures (
361
380
span,
362
381
& desc_place,
@@ -384,18 +403,22 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
384
403
return ;
385
404
}
386
405
387
- ( BorrowKind :: Unique , _, _, _, _, _) => tcx. cannot_uniquely_borrow_by_one_closure (
388
- span,
389
- & desc_place,
390
- "" ,
391
- issued_span,
392
- "it" ,
393
- "" ,
394
- None ,
395
- Origin :: Mir ,
396
- ) ,
406
+ ( BorrowKind :: Unique , _, _, _, _, _) => {
407
+ first_borrow_desc = "first " ;
408
+ tcx. cannot_uniquely_borrow_by_one_closure (
409
+ span,
410
+ & desc_place,
411
+ "" ,
412
+ issued_span,
413
+ "it" ,
414
+ "" ,
415
+ None ,
416
+ Origin :: Mir ,
417
+ )
418
+ } ,
397
419
398
420
( BorrowKind :: Shared , lft, _, BorrowKind :: Unique , _, _) => {
421
+ first_borrow_desc = "first " ;
399
422
tcx. cannot_reborrow_already_uniquely_borrowed (
400
423
span,
401
424
& desc_place,
@@ -409,6 +432,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
409
432
}
410
433
411
434
( BorrowKind :: Mut { .. } , _, lft, BorrowKind :: Unique , _, _) => {
435
+ first_borrow_desc = "first " ;
412
436
tcx. cannot_reborrow_already_uniquely_borrowed (
413
437
span,
414
438
& desc_place,
@@ -459,7 +483,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
459
483
}
460
484
461
485
self . explain_why_borrow_contains_point ( context, issued_borrow, None )
462
- . emit ( self . infcx . tcx , & mut err) ;
486
+ . emit ( self . infcx . tcx , & mut err, first_borrow_desc . to_string ( ) ) ;
463
487
464
488
err. buffer ( & mut self . errors_buffer ) ;
465
489
}
@@ -614,7 +638,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
614
638
615
639
if let BorrowExplanation :: MustBeValidFor ( ..) = explanation {
616
640
} else {
617
- explanation. emit ( self . infcx . tcx , & mut err) ;
641
+ explanation. emit ( self . infcx . tcx , & mut err, String :: new ( ) ) ;
618
642
}
619
643
} else {
620
644
err. span_label ( borrow_span, "borrowed value does not live long enough" ) ;
@@ -625,7 +649,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
625
649
626
650
borrow_spans. args_span_label ( & mut err, "value captured here" ) ;
627
651
628
- explanation. emit ( self . infcx . tcx , & mut err) ;
652
+ explanation. emit ( self . infcx . tcx , & mut err, String :: new ( ) ) ;
629
653
}
630
654
631
655
err
@@ -685,7 +709,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
685
709
_ => { }
686
710
}
687
711
688
- explanation. emit ( self . infcx . tcx , & mut err) ;
712
+ explanation. emit ( self . infcx . tcx , & mut err, String :: new ( ) ) ;
689
713
690
714
err. buffer ( & mut self . errors_buffer ) ;
691
715
}
@@ -752,7 +776,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
752
776
}
753
777
_ => { }
754
778
}
755
- explanation. emit ( self . infcx . tcx , & mut err) ;
779
+ explanation. emit ( self . infcx . tcx , & mut err, String :: new ( ) ) ;
756
780
757
781
borrow_spans. args_span_label ( & mut err, "value captured here" ) ;
758
782
@@ -889,7 +913,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
889
913
loan_spans. var_span_label ( & mut err, "borrow occurs due to use in closure" ) ;
890
914
891
915
self . explain_why_borrow_contains_point ( context, loan, None )
892
- . emit ( self . infcx . tcx , & mut err) ;
916
+ . emit ( self . infcx . tcx , & mut err, String :: new ( ) ) ;
893
917
894
918
err. buffer ( & mut self . errors_buffer ) ;
895
919
}
@@ -1262,21 +1286,6 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
1262
1286
}
1263
1287
}
1264
1288
1265
- /// Returns the `FakeReadCause` at this location if it is a `FakeRead` statement.
1266
- pub ( super ) fn retrieve_fake_read_cause_for_location (
1267
- & self ,
1268
- location : & Location ,
1269
- ) -> Option < FakeReadCause > {
1270
- let stmt = self . mir . basic_blocks ( ) [ location. block ]
1271
- . statements
1272
- . get ( location. statement_index ) ?;
1273
- if let StatementKind :: FakeRead ( cause, _) = stmt. kind {
1274
- Some ( cause)
1275
- } else {
1276
- None
1277
- }
1278
- }
1279
-
1280
1289
fn classify_drop_access_kind ( & self , place : & Place < ' tcx > ) -> StorageDeadOrDrop < ' tcx > {
1281
1290
let tcx = self . infcx . tcx ;
1282
1291
match place {
0 commit comments