@@ -256,25 +256,17 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
256
256
"report_move_out_while_borrowed: location={:?} place={:?} span={:?} borrow={:?}" ,
257
257
location, place, span, borrow
258
258
) ;
259
- let value_msg = match self . describe_place ( place. as_ref ( ) ) {
260
- Some ( name) => format ! ( "`{}`" , name) ,
261
- None => "value" . to_owned ( ) ,
262
- } ;
263
- let borrow_msg = match self . describe_place ( borrow. borrowed_place . as_ref ( ) ) {
264
- Some ( name) => format ! ( "`{}`" , name) ,
265
- None => "value" . to_owned ( ) ,
266
- } ;
259
+ let value_msg = self . describe_any_place ( place. as_ref ( ) ) ;
260
+ let borrow_msg = self . describe_any_place ( borrow. borrowed_place . as_ref ( ) ) ;
267
261
268
262
let borrow_spans = self . retrieve_borrow_spans ( borrow) ;
269
263
let borrow_span = borrow_spans. args_or_use ( ) ;
270
264
271
265
let move_spans = self . move_spans ( place. as_ref ( ) , location) ;
272
266
let span = move_spans. args_or_use ( ) ;
273
267
274
- let mut err = self . cannot_move_when_borrowed (
275
- span,
276
- & self . describe_place ( place. as_ref ( ) ) . unwrap_or_else ( || "_" . to_owned ( ) ) ,
277
- ) ;
268
+ let mut err =
269
+ self . cannot_move_when_borrowed ( span, & self . describe_any_place ( place. as_ref ( ) ) ) ;
278
270
err. span_label ( borrow_span, format ! ( "borrow of {} occurs here" , borrow_msg) ) ;
279
271
err. span_label ( span, format ! ( "move out of {} occurs here" , value_msg) ) ;
280
272
@@ -314,16 +306,15 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
314
306
315
307
let mut err = self . cannot_use_when_mutably_borrowed (
316
308
span,
317
- & self . describe_place ( place. as_ref ( ) ) . unwrap_or_else ( || "_" . to_owned ( ) ) ,
309
+ & self . describe_any_place ( place. as_ref ( ) ) ,
318
310
borrow_span,
319
- & self . describe_place ( borrow. borrowed_place . as_ref ( ) ) . unwrap_or_else ( || "_" . to_owned ( ) ) ,
311
+ & self . describe_any_place ( borrow. borrowed_place . as_ref ( ) ) ,
320
312
) ;
321
313
322
314
borrow_spans. var_span_label ( & mut err, {
323
315
let place = & borrow. borrowed_place ;
324
- let desc_place = self . describe_place ( place. as_ref ( ) ) . unwrap_or_else ( || "_" . to_owned ( ) ) ;
325
-
326
- format ! ( "borrow occurs due to use of `{}`{}" , desc_place, borrow_spans. describe( ) )
316
+ let desc_place = self . describe_any_place ( place. as_ref ( ) ) ;
317
+ format ! ( "borrow occurs due to use of {}{}" , desc_place, borrow_spans. describe( ) )
327
318
} ) ;
328
319
329
320
self . explain_why_borrow_contains_point ( location, borrow, None )
@@ -433,7 +424,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
433
424
borrow_spans. var_span_label (
434
425
& mut err,
435
426
format ! (
436
- "borrow occurs due to use of `{}` {}" ,
427
+ "borrow occurs due to use of {} {}" ,
437
428
desc_place,
438
429
borrow_spans. describe( ) ,
439
430
) ,
@@ -511,16 +502,15 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
511
502
if issued_spans == borrow_spans {
512
503
borrow_spans. var_span_label (
513
504
& mut err,
514
- format ! ( "borrows occur due to use of `{}` {}" , desc_place, borrow_spans. describe( ) ) ,
505
+ format ! ( "borrows occur due to use of {} {}" , desc_place, borrow_spans. describe( ) ) ,
515
506
) ;
516
507
} else {
517
508
let borrow_place = & issued_borrow. borrowed_place ;
518
- let borrow_place_desc =
519
- self . describe_place ( borrow_place. as_ref ( ) ) . unwrap_or_else ( || "_" . to_owned ( ) ) ;
509
+ let borrow_place_desc = self . describe_any_place ( borrow_place. as_ref ( ) ) ;
520
510
issued_spans. var_span_label (
521
511
& mut err,
522
512
format ! (
523
- "first borrow occurs due to use of `{}` {}" ,
513
+ "first borrow occurs due to use of {} {}" ,
524
514
borrow_place_desc,
525
515
issued_spans. describe( ) ,
526
516
) ,
@@ -529,7 +519,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
529
519
borrow_spans. var_span_label (
530
520
& mut err,
531
521
format ! (
532
- "second borrow occurs due to use of `{}` {}" ,
522
+ "second borrow occurs due to use of {} {}" ,
533
523
desc_place,
534
524
borrow_spans. describe( ) ,
535
525
) ,
@@ -538,7 +528,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
538
528
539
529
if union_type_name != "" {
540
530
err. note ( & format ! (
541
- "`{}` is a field of the union `{}`, so it overlaps the field `{}` " ,
531
+ "{} is a field of the union `{}`, so it overlaps the field {} " ,
542
532
msg_place, union_type_name, msg_borrow,
543
533
) ) ;
544
534
}
@@ -606,7 +596,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
606
596
let ty = Place :: ty_from ( place_base, place_projection, * self . body , self . infcx . tcx ) . ty ;
607
597
ty. ty_adt_def ( ) . filter ( |adt| adt. is_union ( ) ) . map ( |_| ty)
608
598
} ;
609
- let describe_place = |place| self . describe_place ( place) . unwrap_or_else ( || "_" . to_owned ( ) ) ;
610
599
611
600
// Start with an empty tuple, so we can use the functions on `Option` to reduce some
612
601
// code duplication (particularly around returning an empty description in the failure
@@ -645,30 +634,25 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
645
634
. and_then ( |( target_base, target_field) | {
646
635
// With the place of a union and a field access into it, we traverse the second
647
636
// borrowed place and look for a access to a different field of the same union.
648
- let Place { local, projection } = second_borrowed_place;
637
+ let Place { local, ref projection } = * second_borrowed_place;
649
638
650
639
let mut cursor = & projection[ ..] ;
651
640
while let [ proj_base @ .., elem] = cursor {
652
641
cursor = proj_base;
653
642
654
643
if let ProjectionElem :: Field ( field, _) = elem {
655
- if let Some ( union_ty) = union_ty ( * local, proj_base) {
644
+ if let Some ( union_ty) = union_ty ( local, proj_base) {
656
645
if field != target_field
657
- && * local == target_base. local
646
+ && local == target_base. local
658
647
&& proj_base == target_base. projection
659
648
{
660
- // FIXME when we avoid clone reuse describe_place closure
661
- let describe_base_place = self
662
- . describe_place ( PlaceRef {
663
- local : * local,
664
- projection : proj_base,
665
- } )
666
- . unwrap_or_else ( || "_" . to_owned ( ) ) ;
667
-
668
649
return Some ( (
669
- describe_base_place,
670
- describe_place ( first_borrowed_place. as_ref ( ) ) ,
671
- describe_place ( second_borrowed_place. as_ref ( ) ) ,
650
+ self . describe_any_place ( PlaceRef {
651
+ local,
652
+ projection : proj_base,
653
+ } ) ,
654
+ self . describe_any_place ( first_borrowed_place. as_ref ( ) ) ,
655
+ self . describe_any_place ( second_borrowed_place. as_ref ( ) ) ,
672
656
union_ty. to_string ( ) ,
673
657
) ) ;
674
658
}
@@ -681,7 +665,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
681
665
// If we didn't find a field access into a union, or both places match, then
682
666
// only return the description of the first place.
683
667
(
684
- describe_place ( first_borrowed_place. as_ref ( ) ) ,
668
+ self . describe_any_place ( first_borrowed_place. as_ref ( ) ) ,
685
669
"" . to_string ( ) ,
686
670
"" . to_string ( ) ,
687
671
"" . to_string ( ) ,
@@ -1404,12 +1388,13 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
1404
1388
let loan_spans = self . retrieve_borrow_spans ( loan) ;
1405
1389
let loan_span = loan_spans. args_or_use ( ) ;
1406
1390
1391
+ let descr_place = self . describe_any_place ( place. as_ref ( ) ) ;
1407
1392
if loan. kind == BorrowKind :: Shallow {
1408
1393
if let Some ( section) = self . classify_immutable_section ( & loan. assigned_place ) {
1409
1394
let mut err = self . cannot_mutate_in_immutable_section (
1410
1395
span,
1411
1396
loan_span,
1412
- & self . describe_place ( place . as_ref ( ) ) . unwrap_or_else ( || "_" . to_owned ( ) ) ,
1397
+ & descr_place ,
1413
1398
section,
1414
1399
"assign" ,
1415
1400
) ;
@@ -1424,11 +1409,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
1424
1409
}
1425
1410
}
1426
1411
1427
- let mut err = self . cannot_assign_to_borrowed (
1428
- span,
1429
- loan_span,
1430
- & self . describe_place ( place. as_ref ( ) ) . unwrap_or_else ( || "_" . to_owned ( ) ) ,
1431
- ) ;
1412
+ let mut err = self . cannot_assign_to_borrowed ( span, loan_span, & descr_place) ;
1432
1413
1433
1414
loan_spans
1434
1415
. var_span_label ( & mut err, format ! ( "borrow occurs due to use{}" , loan_spans. describe( ) ) ) ;
@@ -1482,27 +1463,19 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
1482
1463
} )
1483
1464
| Some ( LocalDecl { local_info : LocalInfo :: StaticRef { .. } , .. } )
1484
1465
| Some ( LocalDecl { local_info : LocalInfo :: Other , .. } )
1485
- | None => ( self . describe_place ( place. as_ref ( ) ) , assigned_span) ,
1486
- Some ( decl) => ( self . describe_place ( err_place. as_ref ( ) ) , decl. source_info . span ) ,
1466
+ | None => ( self . describe_any_place ( place. as_ref ( ) ) , assigned_span) ,
1467
+ Some ( decl) => ( self . describe_any_place ( err_place. as_ref ( ) ) , decl. source_info . span ) ,
1487
1468
} ;
1488
1469
1489
- let mut err = self . cannot_reassign_immutable (
1490
- span,
1491
- place_description. as_ref ( ) . map ( AsRef :: as_ref) . unwrap_or ( "_" ) ,
1492
- from_arg,
1493
- ) ;
1470
+ let mut err = self . cannot_reassign_immutable ( span, & place_description, from_arg) ;
1494
1471
let msg = if from_arg {
1495
1472
"cannot assign to immutable argument"
1496
1473
} else {
1497
1474
"cannot assign twice to immutable variable"
1498
1475
} ;
1499
1476
if span != assigned_span {
1500
1477
if !from_arg {
1501
- let value_msg = match place_description {
1502
- Some ( name) => format ! ( "`{}`" , name) ,
1503
- None => "value" . to_owned ( ) ,
1504
- } ;
1505
- err. span_label ( assigned_span, format ! ( "first assignment to {}" , value_msg) ) ;
1478
+ err. span_label ( assigned_span, format ! ( "first assignment to {}" , place_description) ) ;
1506
1479
}
1507
1480
}
1508
1481
if let Some ( decl) = local_decl {
0 commit comments