@@ -614,11 +614,11 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
614
614
let partial = moved_lp. depth ( ) > lp. depth ( ) ;
615
615
let msg = if !has_fork && partial { "partially " }
616
616
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) ) ;
622
622
let need_note = match lp. ty . sty {
623
623
ty:: TypeVariants :: TyClosure ( id, _) => {
624
624
let node_id = self . tcx . hir . as_local_node_id ( id) . unwrap ( ) ;
@@ -698,10 +698,8 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
698
698
& self ,
699
699
span : Span ,
700
700
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 ( ) ;
705
703
}
706
704
707
705
pub fn report_reassigned_immutable_variable ( & self ,
@@ -762,8 +760,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
762
760
self . cannot_assign ( error_span, & descr, Origin :: Ast )
763
761
}
764
762
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)
767
764
}
768
765
BorrowViolation ( euv:: OverloadedOperator ) |
769
766
BorrowViolation ( euv:: AddrOf ) |
@@ -772,8 +769,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
772
769
BorrowViolation ( euv:: AutoUnsafe ) |
773
770
BorrowViolation ( euv:: ForLoop ) |
774
771
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)
777
773
}
778
774
BorrowViolation ( euv:: ClosureInvocation ) => {
779
775
span_bug ! ( err. span,
@@ -855,21 +851,12 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
855
851
856
852
if let Some ( ( yield_span, _) ) = maybe_borrow_across_yield {
857
853
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)
863
855
. emit ( ) ;
864
856
return ;
865
857
}
866
858
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) ;
873
860
let ( value_kind, value_msg) = match err. cmt . cat {
874
861
mc:: Categorization :: Rvalue ( ..) =>
875
862
( "temporary value" , "temporary value created here" ) ,
@@ -978,11 +965,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
978
965
}
979
966
err_borrowed_pointer_too_short( loan_scope, ptr_scope) => {
980
967
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) ;
986
969
let descr = match opt_loan_path ( & err. cmt ) {
987
970
Some ( lp) => {
988
971
format ! ( "`{}`" , self . loan_path_to_string( & lp) )
@@ -1054,12 +1037,8 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
1054
1037
let blame = cmt. immutability_blame ( ) ;
1055
1038
let mut err = match blame {
1056
1039
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
-
1061
1040
// 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 {
1063
1042
// The aliasability violation with closure captures can
1064
1043
// happen for nested closures, so we know the enclosing
1065
1044
// closure incorrectly accepts an `Fn` while it needs to
@@ -1070,15 +1049,11 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
1070
1049
"consider changing this closure to take self by mutable reference"
1071
1050
} ;
1072
1051
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 ) )
1075
1054
}
1076
1055
_ => {
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)
1082
1057
}
1083
1058
} ;
1084
1059
self . note_immutability_blame ( & mut err, blame) ;
@@ -1230,17 +1205,9 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
1230
1205
Err ( _) => format ! ( "move |<args>| <body>" )
1231
1206
} ;
1232
1207
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)
1244
1211
. span_suggestion ( err. span ,
1245
1212
& format ! ( "to force the closure to take ownership of {} \
1246
1213
(and any other referenced variables), \
0 commit comments