1010
1111use rustc:: hir;
1212use 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 } ;
1617use rustc_data_structures:: indexed_vec:: Idx ;
1718use syntax_pos:: Span ;
1819
@@ -22,7 +23,7 @@ use util::borrowck_errors::{BorrowckErrors, Origin};
2223use util:: collect_writes:: FindAssignments ;
2324use util:: suggest_ref_mut;
2425
25- #[ derive( Copy , Clone , Debug ) ]
26+ #[ derive( Copy , Clone , Debug , Eq , PartialEq ) ]
2627pub ( super ) enum AccessKind {
2728 MutableBorrow ,
2829 Mutate ,
@@ -394,6 +395,47 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
394395 ) ;
395396 }
396397
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+
397439 _ => {
398440 err. span_label ( span, format ! ( "cannot {ACT}" , ACT = act) ) ;
399441 }
0 commit comments