8
8
// option. This file may not be copied, modified, or distributed
9
9
// except according to those terms.
10
10
11
- use syntax_pos :: Span ;
11
+ use borrow_check :: WriteKind ;
12
12
use rustc:: middle:: region:: ScopeTree ;
13
13
use rustc:: mir:: { BorrowKind , Field , Local , LocalKind , Location , Operand } ;
14
14
use rustc:: mir:: { Place , ProjectionElem , Rvalue , Statement , StatementKind } ;
15
15
use rustc:: ty:: { self , RegionKind } ;
16
16
use rustc_data_structures:: indexed_vec:: Idx ;
17
17
use rustc_data_structures:: sync:: Lrc ;
18
+ use syntax_pos:: Span ;
18
19
20
+ use super :: borrow_set:: BorrowData ;
19
21
use super :: { Context , MirBorrowckCtxt } ;
20
22
use super :: { InitializationRequiringAction , PrefixSet } ;
21
- use super :: borrow_set:: BorrowData ;
22
23
23
- use dataflow:: { FlowAtLocation , MovingOutStatements } ;
24
24
use dataflow:: move_paths:: MovePathIndex ;
25
+ use dataflow:: { FlowAtLocation , MovingOutStatements } ;
25
26
use util:: borrowck_errors:: { BorrowckErrors , Origin } ;
26
27
27
28
impl < ' cx , ' gcx , ' tcx > MirBorrowckCtxt < ' cx , ' gcx , ' tcx > {
@@ -39,22 +40,17 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
39
40
. collect :: < Vec < _ > > ( ) ;
40
41
41
42
if mois. is_empty ( ) {
42
- let root_place = self . prefixes ( & place, PrefixSet :: All )
43
- . last ( )
44
- . unwrap ( ) ;
43
+ let root_place = self . prefixes ( & place, PrefixSet :: All ) . last ( ) . unwrap ( ) ;
45
44
46
- if self . moved_error_reported
47
- . contains ( & root_place. clone ( ) )
48
- {
45
+ if self . moved_error_reported . contains ( & root_place. clone ( ) ) {
49
46
debug ! (
50
47
"report_use_of_moved_or_uninitialized place: error about {:?} suppressed" ,
51
48
root_place
52
49
) ;
53
50
return ;
54
51
}
55
52
56
- self . moved_error_reported
57
- . insert ( root_place. clone ( ) ) ;
53
+ self . moved_error_reported . insert ( root_place. clone ( ) ) ;
58
54
59
55
let item_msg = match self . describe_place ( place) {
60
56
Some ( name) => format ! ( "`{}`" , name) ,
@@ -162,7 +158,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
162
158
format ! ( "borrow of {} occurs here" , borrow_msg) ,
163
159
) ;
164
160
err. span_label ( span, format ! ( "move out of {} occurs here" , value_msg) ) ;
165
- self . explain_why_borrow_contains_point ( context, borrow, & mut err) ;
161
+ self . explain_why_borrow_contains_point ( context, borrow, None , & mut err) ;
166
162
err. emit ( ) ;
167
163
}
168
164
@@ -177,12 +173,13 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
177
173
span,
178
174
& self . describe_place ( place) . unwrap_or ( "_" . to_owned ( ) ) ,
179
175
self . retrieve_borrow_span ( borrow) ,
180
- & self . describe_place ( & borrow. borrowed_place )
176
+ & self
177
+ . describe_place ( & borrow. borrowed_place )
181
178
. unwrap_or ( "_" . to_owned ( ) ) ,
182
179
Origin :: Mir ,
183
180
) ;
184
181
185
- self . explain_why_borrow_contains_point ( context, borrow, & mut err) ;
182
+ self . explain_why_borrow_contains_point ( context, borrow, None , & mut err) ;
186
183
187
184
err. emit ( ) ;
188
185
}
@@ -286,8 +283,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
286
283
"mutable" ,
287
284
) {
288
285
( BorrowKind :: Shared , lft, _, BorrowKind :: Mut { .. } , _, rgt)
289
- | ( BorrowKind :: Mut { .. } , _, lft, BorrowKind :: Shared , rgt, _) => {
290
- tcx . cannot_reborrow_already_borrowed (
286
+ | ( BorrowKind :: Mut { .. } , _, lft, BorrowKind :: Shared , rgt, _) => tcx
287
+ . cannot_reborrow_already_borrowed (
291
288
span,
292
289
& desc_place,
293
290
"" ,
@@ -298,30 +295,27 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
298
295
"" ,
299
296
None ,
300
297
Origin :: Mir ,
301
- )
302
- }
298
+ ) ,
303
299
304
- ( BorrowKind :: Mut { .. } , _, _, BorrowKind :: Mut { .. } , _, _) => {
305
- tcx . cannot_mutably_borrow_multiply (
300
+ ( BorrowKind :: Mut { .. } , _, _, BorrowKind :: Mut { .. } , _, _) => tcx
301
+ . cannot_mutably_borrow_multiply (
306
302
span,
307
303
& desc_place,
308
304
"" ,
309
305
issued_span,
310
306
"" ,
311
307
None ,
312
308
Origin :: Mir ,
313
- )
314
- }
309
+ ) ,
315
310
316
- ( BorrowKind :: Unique , _, _, BorrowKind :: Unique , _, _) => {
317
- tcx . cannot_uniquely_borrow_by_two_closures (
311
+ ( BorrowKind :: Unique , _, _, BorrowKind :: Unique , _, _) => tcx
312
+ . cannot_uniquely_borrow_by_two_closures (
318
313
span,
319
314
& desc_place,
320
315
issued_span,
321
316
None ,
322
317
Origin :: Mir ,
323
- )
324
- }
318
+ ) ,
325
319
326
320
( BorrowKind :: Unique , _, _, _, _, _) => tcx. cannot_uniquely_borrow_by_one_closure (
327
321
span,
@@ -334,8 +328,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
334
328
Origin :: Mir ,
335
329
) ,
336
330
337
- ( BorrowKind :: Shared , lft, _, BorrowKind :: Unique , _, _) => {
338
- tcx . cannot_reborrow_already_uniquely_borrowed (
331
+ ( BorrowKind :: Shared , lft, _, BorrowKind :: Unique , _, _) => tcx
332
+ . cannot_reborrow_already_uniquely_borrowed (
339
333
span,
340
334
& desc_place,
341
335
"" ,
@@ -344,11 +338,10 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
344
338
"" ,
345
339
None ,
346
340
Origin :: Mir ,
347
- )
348
- }
341
+ ) ,
349
342
350
- ( BorrowKind :: Mut { .. } , _, lft, BorrowKind :: Unique , _, _) => {
351
- tcx . cannot_reborrow_already_uniquely_borrowed (
343
+ ( BorrowKind :: Mut { .. } , _, lft, BorrowKind :: Unique , _, _) => tcx
344
+ . cannot_reborrow_already_uniquely_borrowed (
352
345
span,
353
346
& desc_place,
354
347
"" ,
@@ -357,8 +350,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
357
350
"" ,
358
351
None ,
359
352
Origin :: Mir ,
360
- )
361
- }
353
+ ) ,
362
354
363
355
( BorrowKind :: Shared , _, _, BorrowKind :: Shared , _, _) => unreachable ! ( ) ,
364
356
} ;
@@ -380,7 +372,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
380
372
) ;
381
373
}
382
374
383
- self . explain_why_borrow_contains_point ( context, issued_borrow, & mut err) ;
375
+ self . explain_why_borrow_contains_point ( context, issued_borrow, None , & mut err) ;
384
376
385
377
err. emit ( ) ;
386
378
}
@@ -389,10 +381,13 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
389
381
& mut self ,
390
382
context : Context ,
391
383
borrow : & BorrowData < ' tcx > ,
392
- drop_span : Span ,
384
+ place_span : ( & Place < ' tcx > , Span ) ,
385
+ kind : Option < WriteKind > ,
393
386
) {
387
+ let drop_span = place_span. 1 ;
394
388
let scope_tree = self . tcx . region_scope_tree ( self . mir_def_id ) ;
395
- let root_place = self . prefixes ( & borrow. borrowed_place , PrefixSet :: All )
389
+ let root_place = self
390
+ . prefixes ( & borrow. borrowed_place , PrefixSet :: All )
396
391
. last ( )
397
392
. unwrap ( ) ;
398
393
@@ -402,7 +397,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
402
397
_ => drop_span,
403
398
} ;
404
399
405
- if self . access_place_error_reported
400
+ if self
401
+ . access_place_error_reported
406
402
. contains ( & ( root_place. clone ( ) , borrow_span) )
407
403
{
408
404
debug ! (
@@ -450,6 +446,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
450
446
drop_span,
451
447
borrow_span,
452
448
proper_span,
449
+ kind. map ( |k| ( k, place_span. 0 ) ) ,
453
450
) ;
454
451
}
455
452
( RegionKind :: ReEarlyBound ( _) , None )
@@ -471,8 +468,11 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
471
468
| ( RegionKind :: ReClosureBound ( _) , _)
472
469
| ( RegionKind :: ReCanonical ( _) , _)
473
470
| ( RegionKind :: ReErased , _) => {
474
- span_bug ! ( drop_span, "region {:?} does not make sense in this context" ,
475
- borrow. region) ;
471
+ span_bug ! (
472
+ drop_span,
473
+ "region {:?} does not make sense in this context" ,
474
+ borrow. region
475
+ ) ;
476
476
}
477
477
}
478
478
}
@@ -495,7 +495,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
495
495
drop_span,
496
496
format ! ( "`{}` dropped here while still borrowed" , name) ,
497
497
) ;
498
- self . explain_why_borrow_contains_point ( context, borrow, & mut err) ;
498
+ self . explain_why_borrow_contains_point ( context, borrow, None , & mut err) ;
499
499
err. emit ( ) ;
500
500
}
501
501
@@ -517,7 +517,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
517
517
"temporary value dropped here while still borrowed" ,
518
518
) ;
519
519
err. note ( "consider using a `let` binding to increase its lifetime" ) ;
520
- self . explain_why_borrow_contains_point ( context, borrow, & mut err) ;
520
+ self . explain_why_borrow_contains_point ( context, borrow, None , & mut err) ;
521
521
err. emit ( ) ;
522
522
}
523
523
@@ -530,6 +530,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
530
530
drop_span : Span ,
531
531
borrow_span : Span ,
532
532
_proper_span : Span ,
533
+ kind_place : Option < ( WriteKind , & Place < ' tcx > ) > ,
533
534
) {
534
535
debug ! (
535
536
"report_unscoped_local_value_does_not_live_long_enough(\
@@ -544,7 +545,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
544
545
err. span_label ( borrow_span, "borrowed value does not live long enough" ) ;
545
546
err. span_label ( drop_span, "borrowed value only lives until here" ) ;
546
547
547
- self . explain_why_borrow_contains_point ( context, borrow, & mut err) ;
548
+ self . explain_why_borrow_contains_point ( context, borrow, kind_place , & mut err) ;
548
549
err. emit ( ) ;
549
550
}
550
551
@@ -570,7 +571,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
570
571
err. span_label ( proper_span, "temporary value does not live long enough" ) ;
571
572
err. span_label ( drop_span, "temporary value only lives until here" ) ;
572
573
573
- self . explain_why_borrow_contains_point ( context, borrow, & mut err) ;
574
+ self . explain_why_borrow_contains_point ( context, borrow, None , & mut err) ;
574
575
err. emit ( ) ;
575
576
}
576
577
@@ -588,7 +589,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
588
589
Origin :: Mir ,
589
590
) ;
590
591
591
- self . explain_why_borrow_contains_point ( context, loan, & mut err) ;
592
+ self . explain_why_borrow_contains_point ( context, loan, None , & mut err) ;
592
593
593
594
err. emit ( ) ;
594
595
}
@@ -759,9 +760,10 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
759
760
Place :: Static ( ref static_) => self . describe_field_from_ty ( & static_. ty , field) ,
760
761
Place :: Projection ( ref proj) => match proj. elem {
761
762
ProjectionElem :: Deref => self . describe_field ( & proj. base , field) ,
762
- ProjectionElem :: Downcast ( def, variant_index) => {
763
- format ! ( "{}" , def. variants[ variant_index] . fields[ field. index( ) ] . ident)
764
- }
763
+ ProjectionElem :: Downcast ( def, variant_index) => format ! (
764
+ "{}" ,
765
+ def. variants[ variant_index] . fields[ field. index( ) ] . ident
766
+ ) ,
765
767
ProjectionElem :: Field ( _, field_type) => {
766
768
self . describe_field_from_ty ( & field_type, field)
767
769
}
0 commit comments