@@ -527,8 +527,8 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
527527 r) . as_slice ( ) )
528528 }
529529 } ;
530- let suggestion = move_suggestion ( self . tcx , expr_ty,
531- "moved by default (use `copy` to override)" ) ;
530+ let ( suggestion, _ ) = move_suggestion ( self . tcx , expr_ty,
531+ ( "moved by default" , "" ) ) ;
532532 self . tcx . sess . span_note (
533533 expr_span,
534534 format ! ( "`{}` moved here{} because it has type `{}`, which is {}" ,
@@ -540,13 +540,15 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
540540
541541 move_data:: MovePat => {
542542 let pat_ty = ty:: node_id_to_type ( self . tcx , the_move. id ) ;
543- self . tcx . sess . span_note ( self . tcx . map . span ( the_move. id ) ,
543+ let span = self . tcx . map . span ( the_move. id ) ;
544+ self . tcx . sess . span_note ( span,
544545 format ! ( "`{}` moved here{} because it has type `{}`, \
545- which is moved by default (use `ref` to \
546- override)",
546+ which is moved by default",
547547 ol,
548548 moved_lp_msg,
549549 pat_ty. user_string( self . tcx) ) . as_slice ( ) ) ;
550+ self . tcx . sess . span_help ( span,
551+ "use `ref` to override" ) ;
550552 }
551553
552554 move_data:: Captured => {
@@ -563,9 +565,9 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
563565 r) . as_slice ( ) )
564566 }
565567 } ;
566- let suggestion = move_suggestion ( self . tcx , expr_ty,
567- "moved by default ( make a copy and \
568- capture that instead to override)" ) ;
568+ let ( suggestion, help ) = move_suggestion ( self . tcx , expr_ty,
569+ ( "moved by default" , " make a copy and \
570+ capture that instead to override" ) ) ;
569571 self . tcx . sess . span_note (
570572 expr_span,
571573 format ! ( "`{}` moved into closure environment here{} because it \
@@ -574,21 +576,23 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
574576 moved_lp_msg,
575577 expr_ty. user_string( self . tcx) ,
576578 suggestion) . as_slice ( ) ) ;
579+ self . tcx . sess . span_help ( expr_span, help) ;
577580 }
578581 }
579582
580- fn move_suggestion ( tcx : & ty:: ctxt , ty : ty:: t , default_msg : & ' static str )
581- -> & ' static str {
583+ fn move_suggestion ( tcx : & ty:: ctxt , ty : ty:: t , default_msgs : ( & ' static str , & ' static str ) )
584+ -> ( & ' static str , & ' static str ) {
582585 match ty:: get ( ty) . sty {
583586 ty:: ty_closure( box ty:: ClosureTy {
584587 store : ty:: RegionTraitStore ( ..) ,
585588 ..
586589 } ) =>
587- "a non-copyable stack closure (capture it in a new closure, \
588- e.g. `|x| f(x)`, to override)" ,
590+ ( "a non-copyable stack closure" ,
591+ "capture it in a new closure, e.g. `|x| f(x)`, to override" ) ,
589592 _ if ty:: type_moves_by_default ( tcx, ty) =>
590- "non-copyable (perhaps you meant to use clone()?)" ,
591- _ => default_msg,
593+ ( "non-copyable" ,
594+ "perhaps you meant to use `clone()`?" ) ,
595+ _ => default_msgs,
592596 }
593597 }
594598 }
@@ -733,7 +737,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
733737 self . tcx . sess . span_err ( span,
734738 format ! ( "{} in a captured outer \
735739 variable in an `Fn` closure", prefix) . as_slice ( ) ) ;
736- span_note ! ( self . tcx. sess, self . tcx. map. span( id) ,
740+ span_help ! ( self . tcx. sess, self . tcx. map. span( id) ,
737741 "consider changing this closure to take self by mutable reference" ) ;
738742 }
739743 mc:: AliasableStatic ( ..) |
@@ -750,7 +754,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
750754 }
751755
752756 if is_closure {
753- self . tcx . sess . span_note (
757+ self . tcx . sess . span_help (
754758 span,
755759 "closures behind references must be called via `&mut`" ) ;
756760 }
@@ -770,7 +774,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
770774 _ => unreachable ! ( )
771775 } ;
772776 if kind == ty:: FnUnboxedClosureKind {
773- self . tcx . sess . span_note (
777+ self . tcx . sess . span_help (
774778 self . tcx . map . span ( upvar_id. closure_expr_id ) ,
775779 "consider changing this closure to take \
776780 self by mutable reference") ;
@@ -787,15 +791,20 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
787791 sub_scope,
788792 "..." ) ;
789793 let suggestion = if is_statement_scope ( self . tcx , super_scope) {
790- "; consider using a `let` binding to increase its lifetime"
794+ Some ( " consider using a `let` binding to increase its lifetime")
791795 } else {
792- ""
796+ None
793797 } ;
794- note_and_explain_region (
798+ let span = note_and_explain_region (
795799 self . tcx ,
796800 "...but borrowed value is only valid for " ,
797801 super_scope,
798- suggestion) ;
802+ "" ) ;
803+ match ( span, suggestion) {
804+ ( _, None ) => { } ,
805+ ( Some ( span) , Some ( msg) ) => self . tcx . sess . span_help ( span, msg) ,
806+ ( None , Some ( msg) ) => self . tcx . sess . help ( msg) ,
807+ }
799808 }
800809
801810 err_borrowed_pointer_too_short( loan_scope, ptr_scope) => {
0 commit comments