@@ -614,11 +614,11 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
614614 let partial = moved_lp. depth ( ) > lp. depth ( ) ;
615615 let msg = if !has_fork && partial { "partially " }
616616 else if has_fork && !has_common { "collaterally " }
617- else { "" } ;
618- let mut err = struct_span_err ! (
619- self . tcx . sess , use_span , E0382 ,
620- "{} of {}moved value: `{}`" ,
621- verb , msg , nl) ;
617+ else { "" } ;
618+ let mut err = self . cannot_act_on_moved_value ( use_span ,
619+ verb ,
620+ msg ,
621+ & format ! ( "{}" , nl) ) ;
622622 let need_note = match lp. ty . sty {
623623 ty:: TypeVariants :: TyClosure ( id, _) => {
624624 let node_id = self . tcx . hir . as_local_node_id ( id) . unwrap ( ) ;
@@ -698,10 +698,8 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
698698 & self ,
699699 span : Span ,
700700 lp : & LoanPath < ' tcx > ) {
701- span_err ! (
702- self . tcx. sess, span, E0383 ,
703- "partial reinitialization of uninitialized structure `{}`" ,
704- self . loan_path_to_string( lp) ) ;
701+ self . cannot_partially_reinit_an_uninit_struct ( span, & self . loan_path_to_string ( lp) )
702+ . emit ( ) ;
705703 }
706704
707705 pub fn report_reassigned_immutable_variable ( & self ,
@@ -762,8 +760,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
762760 self . cannot_assign ( error_span, & descr, Origin :: Ast )
763761 }
764762 BorrowViolation ( euv:: ClosureCapture ( _) ) => {
765- struct_span_err ! ( self . tcx. sess, error_span, E0595 ,
766- "closure cannot assign to {}" , descr)
763+ self . closure_cannot_assign_to_borrowed ( error_span, & descr)
767764 }
768765 BorrowViolation ( euv:: OverloadedOperator ) |
769766 BorrowViolation ( euv:: AddrOf ) |
@@ -772,8 +769,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
772769 BorrowViolation ( euv:: AutoUnsafe ) |
773770 BorrowViolation ( euv:: ForLoop ) |
774771 BorrowViolation ( euv:: MatchDiscriminant ) => {
775- struct_span_err ! ( self . tcx. sess, error_span, E0596 ,
776- "cannot borrow {} as mutable" , descr)
772+ self . cannot_borrow_path_as_mutable ( error_span, & descr)
777773 }
778774 BorrowViolation ( euv:: ClosureInvocation ) => {
779775 span_bug ! ( err. span,
@@ -855,21 +851,12 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
855851
856852 if let Some ( ( yield_span, _) ) = maybe_borrow_across_yield {
857853 debug ! ( "err_out_of_scope: opt_yield_span = {:?}" , yield_span) ;
858- struct_span_err ! ( self . tcx. sess,
859- error_span,
860- E0626 ,
861- "borrow may still be in use when generator yields" )
862- . span_label ( yield_span, "possible yield occurs here" )
854+ self . cannot_borrow_across_generator_yield ( error_span, yield_span)
863855 . emit ( ) ;
864856 return ;
865857 }
866858
867- let mut db = struct_span_err ! ( self . tcx. sess,
868- error_span,
869- E0597 ,
870- "{} does not live long enough" ,
871- msg) ;
872-
859+ let mut db = self . path_does_not_live_long_enough ( error_span, & msg) ;
873860 let ( value_kind, value_msg) = match err. cmt . cat {
874861 mc:: Categorization :: Rvalue ( ..) =>
875862 ( "temporary value" , "temporary value created here" ) ,
@@ -978,11 +965,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
978965 }
979966 err_borrowed_pointer_too_short( loan_scope, ptr_scope) => {
980967 let descr = self . cmt_to_path_or_string ( & err. cmt ) ;
981- let mut db = struct_span_err ! ( self . tcx. sess, error_span, E0598 ,
982- "lifetime of {} is too short to guarantee \
983- its contents can be safely reborrowed",
984- descr) ;
985-
968+ let mut db = self . lifetime_too_short_for_reborrow ( error_span, & descr) ;
986969 let descr = match opt_loan_path ( & err. cmt ) {
987970 Some ( lp) => {
988971 format ! ( "`{}`" , self . loan_path_to_string( & lp) )
@@ -1054,12 +1037,8 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
10541037 let blame = cmt. immutability_blame ( ) ;
10551038 let mut err = match blame {
10561039 Some ( ImmutabilityBlame :: ClosureEnv ( id) ) => {
1057- let mut err = struct_span_err ! (
1058- self . tcx. sess, span, E0387 ,
1059- "{} in a captured outer variable in an `Fn` closure" , prefix) ;
1060-
10611040 // FIXME: the distinction between these 2 messages looks wrong.
1062- let help = if let BorrowViolation ( euv:: ClosureCapture ( _) ) = kind {
1041+ let help_msg = if let BorrowViolation ( euv:: ClosureCapture ( _) ) = kind {
10631042 // The aliasability violation with closure captures can
10641043 // happen for nested closures, so we know the enclosing
10651044 // closure incorrectly accepts an `Fn` while it needs to
@@ -1070,15 +1049,11 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
10701049 "consider changing this closure to take self by mutable reference"
10711050 } ;
10721051 let node_id = self . tcx . hir . def_index_to_node_id ( id) ;
1073- err . span_help ( self . tcx . hir . span ( node_id) , help ) ;
1074- err
1052+ let help_span = self . tcx . hir . span ( node_id) ;
1053+ self . cannot_act_on_capture_in_sharable_fn ( span , prefix , ( help_span , help_msg ) )
10751054 }
10761055 _ => {
1077- let mut err = struct_span_err ! (
1078- self . tcx. sess, span, E0389 ,
1079- "{} in a `&` reference" , prefix) ;
1080- err. span_label ( span, "assignment into an immutable reference" ) ;
1081- err
1056+ self . cannot_assign_into_immutable_reference ( span, prefix)
10821057 }
10831058 } ;
10841059 self . note_immutability_blame ( & mut err, blame) ;
@@ -1230,17 +1205,9 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
12301205 Err ( _) => format ! ( "move |<args>| <body>" )
12311206 } ;
12321207
1233- struct_span_err ! ( self . tcx. sess, err. span, E0373 ,
1234- "closure may outlive the current function, \
1235- but it borrows {}, \
1236- which is owned by the current function",
1237- cmt_path_or_string)
1238- . span_label ( capture_span,
1239- format ! ( "{} is borrowed here" ,
1240- cmt_path_or_string) )
1241- . span_label ( err. span ,
1242- format ! ( "may outlive borrowed value {}" ,
1243- cmt_path_or_string) )
1208+ self . cannot_capture_in_long_lived_closure ( err. span ,
1209+ & cmt_path_or_string,
1210+ capture_span)
12441211 . span_suggestion ( err. span ,
12451212 & format ! ( "to force the closure to take ownership of {} \
12461213 (and any other referenced variables), \
0 commit comments