@@ -527,8 +527,8 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
527
527
r) . as_slice ( ) )
528
528
}
529
529
} ;
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" , "" ) ) ;
532
532
self . tcx . sess . span_note (
533
533
expr_span,
534
534
format ! ( "`{}` moved here{} because it has type `{}`, which is {}" ,
@@ -540,13 +540,15 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
540
540
541
541
move_data:: MovePat => {
542
542
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,
544
545
format ! ( "`{}` moved here{} because it has type `{}`, \
545
- which is moved by default (use `ref` to \
546
- override)",
546
+ which is moved by default",
547
547
ol,
548
548
moved_lp_msg,
549
549
pat_ty. user_string( self . tcx) ) . as_slice ( ) ) ;
550
+ self . tcx . sess . span_help ( span,
551
+ "use `ref` to override" ) ;
550
552
}
551
553
552
554
move_data:: Captured => {
@@ -563,9 +565,9 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
563
565
r) . as_slice ( ) )
564
566
}
565
567
} ;
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" ) ) ;
569
571
self . tcx . sess . span_note (
570
572
expr_span,
571
573
format ! ( "`{}` moved into closure environment here{} because it \
@@ -574,21 +576,23 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
574
576
moved_lp_msg,
575
577
expr_ty. user_string( self . tcx) ,
576
578
suggestion) . as_slice ( ) ) ;
579
+ self . tcx . sess . span_help ( expr_span, help) ;
577
580
}
578
581
}
579
582
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 ) {
582
585
match ty:: get ( ty) . sty {
583
586
ty:: ty_closure( box ty:: ClosureTy {
584
587
store : ty:: RegionTraitStore ( ..) ,
585
588
..
586
589
} ) =>
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" ) ,
589
592
_ 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,
592
596
}
593
597
}
594
598
}
@@ -733,7 +737,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
733
737
self . tcx . sess . span_err ( span,
734
738
format ! ( "{} in a captured outer \
735
739
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) ,
737
741
"consider changing this closure to take self by mutable reference" ) ;
738
742
}
739
743
mc:: AliasableStatic ( ..) |
@@ -750,7 +754,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
750
754
}
751
755
752
756
if is_closure {
753
- self . tcx . sess . span_note (
757
+ self . tcx . sess . span_help (
754
758
span,
755
759
"closures behind references must be called via `&mut`" ) ;
756
760
}
@@ -770,7 +774,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
770
774
_ => unreachable ! ( )
771
775
} ;
772
776
if kind == ty:: FnUnboxedClosureKind {
773
- self . tcx . sess . span_note (
777
+ self . tcx . sess . span_help (
774
778
self . tcx . map . span ( upvar_id. closure_expr_id ) ,
775
779
"consider changing this closure to take \
776
780
self by mutable reference") ;
@@ -787,15 +791,20 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
787
791
sub_scope,
788
792
"..." ) ;
789
793
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")
791
795
} else {
792
- ""
796
+ None
793
797
} ;
794
- note_and_explain_region (
798
+ let span = note_and_explain_region (
795
799
self . tcx ,
796
800
"...but borrowed value is only valid for " ,
797
801
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
+ }
799
808
}
800
809
801
810
err_borrowed_pointer_too_short( loan_scope, ptr_scope) => {
0 commit comments