10
10
11
11
use rustc:: hir;
12
12
use rustc:: hir:: Node ;
13
- use rustc:: mir:: { self , BindingForm , ClearCrossCrate , Local , Location , Mir } ;
14
- use rustc:: mir:: { Mutability , Place , Projection , ProjectionElem , Static } ;
15
- use rustc:: ty:: { self , TyCtxt } ;
13
+ use rustc:: mir:: { self , BindingForm , Constant , ClearCrossCrate , Local , Location , Mir } ;
14
+ use rustc:: mir:: { Mutability , Operand , Place , Projection , ProjectionElem , Static , Terminator } ;
15
+ use rustc:: mir:: TerminatorKind ;
16
+ use rustc:: ty:: { self , Const , DefIdTree , TyS , TyKind , TyCtxt } ;
16
17
use rustc_data_structures:: indexed_vec:: Idx ;
17
18
use syntax_pos:: Span ;
18
19
@@ -22,7 +23,7 @@ use util::borrowck_errors::{BorrowckErrors, Origin};
22
23
use util:: collect_writes:: FindAssignments ;
23
24
use util:: suggest_ref_mut;
24
25
25
- #[ derive( Copy , Clone , Debug ) ]
26
+ #[ derive( Copy , Clone , Debug , Eq , PartialEq ) ]
26
27
pub ( super ) enum AccessKind {
27
28
MutableBorrow ,
28
29
Mutate ,
@@ -394,6 +395,47 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
394
395
) ;
395
396
}
396
397
398
+ Place :: Projection ( box Projection {
399
+ base : Place :: Local ( local) ,
400
+ elem : ProjectionElem :: Deref ,
401
+ } ) if error_access == AccessKind :: MutableBorrow => {
402
+ err. span_label ( span, format ! ( "cannot {ACT}" , ACT = act) ) ;
403
+
404
+ let mpi = self . move_data . rev_lookup . find_local ( * local) ;
405
+ for i in self . move_data . init_path_map [ mpi] . iter ( ) {
406
+ if let InitLocation :: Statement ( location) = self . move_data . inits [ * i] . location {
407
+ if let Some (
408
+ Terminator {
409
+ kind : TerminatorKind :: Call {
410
+ func : Operand :: Constant ( box Constant {
411
+ literal : Const {
412
+ ty : & TyS {
413
+ sty : TyKind :: FnDef ( id, substs) ,
414
+ ..
415
+ } ,
416
+ ..
417
+ } ,
418
+ ..
419
+ } ) ,
420
+ ..
421
+ } ,
422
+ ..
423
+ }
424
+ ) = & self . mir . basic_blocks ( ) [ location. block ] . terminator {
425
+ if self . tcx . parent ( id) == self . tcx . lang_items ( ) . index_trait ( ) {
426
+ err. help (
427
+ & format ! (
428
+ "trait `IndexMut` is required to modify indexed content, \
429
+ but it is not implemented for `{}`",
430
+ substs. type_at( 0 ) ,
431
+ ) ,
432
+ ) ;
433
+ }
434
+ }
435
+ }
436
+ }
437
+ }
438
+
397
439
_ => {
398
440
err. span_label ( span, format ! ( "cannot {ACT}" , ACT = act) ) ;
399
441
}
0 commit comments