@@ -213,7 +213,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
213213 AccessKind :: Mutate => {
214214 err = self . cannot_assign ( span, & ( item_msg + & reason) ) ;
215215 act = "assign" ;
216- acted_on = "written" ;
216+ acted_on = "written to " ;
217217 span
218218 }
219219 AccessKind :: MutableBorrow => {
@@ -518,8 +518,8 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
518518 err. span_label (
519519 span,
520520 format ! (
521- "`{name}` is a `{pointer_sigil}` {pointer_desc}, \
522- so the data it refers to cannot be {acted_on}",
521+ "`{name}` is a `{pointer_sigil}` {pointer_desc}, so it cannot be \
522+ {acted_on}",
523523 ) ,
524524 ) ;
525525
@@ -542,7 +542,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
542542 self . expected_fn_found_fn_mut_call ( & mut err, span, act) ;
543543 }
544544
545- PlaceRef { local : _ , projection : [ .., ProjectionElem :: Deref ] } => {
545+ PlaceRef { local, projection : [ .., ProjectionElem :: Deref ] } => {
546546 err. span_label ( span, format ! ( "cannot {act}" ) ) ;
547547
548548 match opt_source {
@@ -559,11 +559,36 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
559559 ) ) ;
560560 self . suggest_map_index_mut_alternatives ( ty, & mut err, span) ;
561561 }
562- _ => ( ) ,
562+ _ => {
563+ let local = & self . body . local_decls [ local] ;
564+ match local. local_info ( ) {
565+ LocalInfo :: StaticRef { def_id, .. } => {
566+ let span = self . infcx . tcx . def_span ( def_id) ;
567+ err. span_label ( span, format ! ( "this `static` cannot be {acted_on}" ) ) ;
568+ }
569+ LocalInfo :: ConstRef { def_id } => {
570+ let span = self . infcx . tcx . def_span ( def_id) ;
571+ err. span_label ( span, format ! ( "this `const` cannot be {acted_on}" ) ) ;
572+ }
573+ LocalInfo :: BlockTailTemp ( _) | LocalInfo :: Boring
574+ if !local. source_info . span . overlaps ( span) =>
575+ {
576+ err. span_label (
577+ local. source_info . span ,
578+ format ! ( "this cannot be {acted_on}" ) ,
579+ ) ;
580+ }
581+ _ => { }
582+ }
583+ }
563584 }
564585 }
565586
566- _ => {
587+ PlaceRef { local, .. } => {
588+ let local = & self . body . local_decls [ local] ;
589+ if !local. source_info . span . overlaps ( span) {
590+ err. span_label ( local. source_info . span , format ! ( "this cannot be {acted_on}" ) ) ;
591+ }
567592 err. span_label ( span, format ! ( "cannot {act}" ) ) ;
568593 }
569594 }
0 commit comments