@@ -614,11 +614,12 @@ 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
+ Origin :: Ast ) ;
622
623
let need_note = match lp. ty . sty {
623
624
ty:: TypeVariants :: TyClosure ( id, _) => {
624
625
let node_id = self . tcx . hir . as_local_node_id ( id) . unwrap ( ) ;
@@ -698,10 +699,10 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
698
699
& self ,
699
700
span : Span ,
700
701
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 ) ) ;
702
+ self . cannot_partially_reinit_an_uninit_struct ( span ,
703
+ & self . loan_path_to_string ( lp ) ,
704
+ Origin :: Ast )
705
+ . emit ( ) ;
705
706
}
706
707
707
708
pub fn report_reassigned_immutable_variable ( & self ,
@@ -776,8 +777,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
776
777
db
777
778
}
778
779
BorrowViolation ( euv:: ClosureCapture ( _) ) => {
779
- struct_span_err ! ( self . tcx. sess, error_span, E0595 ,
780
- "closure cannot assign to {}" , descr)
780
+ self . closure_cannot_assign_to_borrowed ( error_span, & descr, Origin :: Ast )
781
781
}
782
782
BorrowViolation ( euv:: OverloadedOperator ) |
783
783
BorrowViolation ( euv:: AddrOf ) |
@@ -786,8 +786,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
786
786
BorrowViolation ( euv:: AutoUnsafe ) |
787
787
BorrowViolation ( euv:: ForLoop ) |
788
788
BorrowViolation ( euv:: MatchDiscriminant ) => {
789
- struct_span_err ! ( self . tcx. sess, error_span, E0596 ,
790
- "cannot borrow {} as mutable" , descr)
789
+ self . cannot_borrow_path_as_mutable ( error_span, & descr, Origin :: Ast )
791
790
}
792
791
BorrowViolation ( euv:: ClosureInvocation ) => {
793
792
span_bug ! ( err. span,
@@ -869,21 +868,12 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
869
868
870
869
if let Some ( ( yield_span, _) ) = maybe_borrow_across_yield {
871
870
debug ! ( "err_out_of_scope: opt_yield_span = {:?}" , yield_span) ;
872
- struct_span_err ! ( self . tcx. sess,
873
- error_span,
874
- E0626 ,
875
- "borrow may still be in use when generator yields" )
876
- . span_label ( yield_span, "possible yield occurs here" )
871
+ self . cannot_borrow_across_generator_yield ( error_span, yield_span, Origin :: Ast )
877
872
. emit ( ) ;
878
873
return ;
879
874
}
880
875
881
- let mut db = struct_span_err ! ( self . tcx. sess,
882
- error_span,
883
- E0597 ,
884
- "{} does not live long enough" ,
885
- msg) ;
886
-
876
+ let mut db = self . path_does_not_live_long_enough ( error_span, & msg, Origin :: Ast ) ;
887
877
let ( value_kind, value_msg) = match err. cmt . cat {
888
878
mc:: Categorization :: Rvalue ( ..) =>
889
879
( "temporary value" , "temporary value created here" ) ,
@@ -992,11 +982,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
992
982
}
993
983
err_borrowed_pointer_too_short( loan_scope, ptr_scope) => {
994
984
let descr = self . cmt_to_path_or_string ( & err. cmt ) ;
995
- let mut db = struct_span_err ! ( self . tcx. sess, error_span, E0598 ,
996
- "lifetime of {} is too short to guarantee \
997
- its contents can be safely reborrowed",
998
- descr) ;
999
-
985
+ let mut db = self . lifetime_too_short_for_reborrow ( error_span, & descr, Origin :: Ast ) ;
1000
986
let descr = match opt_loan_path ( & err. cmt ) {
1001
987
Some ( lp) => {
1002
988
format ! ( "`{}`" , self . loan_path_to_string( & lp) )
@@ -1068,12 +1054,8 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
1068
1054
let blame = cmt. immutability_blame ( ) ;
1069
1055
let mut err = match blame {
1070
1056
Some ( ImmutabilityBlame :: ClosureEnv ( id) ) => {
1071
- let mut err = struct_span_err ! (
1072
- self . tcx. sess, span, E0387 ,
1073
- "{} in a captured outer variable in an `Fn` closure" , prefix) ;
1074
-
1075
1057
// FIXME: the distinction between these 2 messages looks wrong.
1076
- let help = if let BorrowViolation ( euv:: ClosureCapture ( _) ) = kind {
1058
+ let help_msg = if let BorrowViolation ( euv:: ClosureCapture ( _) ) = kind {
1077
1059
// The aliasability violation with closure captures can
1078
1060
// happen for nested closures, so we know the enclosing
1079
1061
// closure incorrectly accepts an `Fn` while it needs to
@@ -1084,15 +1066,15 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
1084
1066
"consider changing this closure to take self by mutable reference"
1085
1067
} ;
1086
1068
let node_id = self . tcx . hir . def_index_to_node_id ( id) ;
1087
- err. span_help ( self . tcx . hir . span ( node_id) , help) ;
1088
- err
1069
+ let help_span = self . tcx . hir . span ( node_id) ;
1070
+ self . cannot_act_on_capture_in_sharable_fn ( span,
1071
+ prefix,
1072
+ ( help_span, help_msg) ,
1073
+ Origin :: Ast )
1089
1074
}
1090
1075
_ => {
1091
- let mut err = struct_span_err ! (
1092
- self . tcx. sess, span, E0389 ,
1093
- "{} in a `&` reference" , prefix) ;
1094
- err. span_label ( span, "assignment into an immutable reference" ) ;
1095
- err
1076
+ self . cannot_assign_into_immutable_reference ( span, prefix,
1077
+ Origin :: Ast )
1096
1078
}
1097
1079
} ;
1098
1080
self . note_immutability_blame ( & mut err, blame) ;
@@ -1244,17 +1226,10 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
1244
1226
Err ( _) => format ! ( "move |<args>| <body>" )
1245
1227
} ;
1246
1228
1247
- struct_span_err ! ( self . tcx. sess, err. span, E0373 ,
1248
- "closure may outlive the current function, \
1249
- but it borrows {}, \
1250
- which is owned by the current function",
1251
- cmt_path_or_string)
1252
- . span_label ( capture_span,
1253
- format ! ( "{} is borrowed here" ,
1254
- cmt_path_or_string) )
1255
- . span_label ( err. span ,
1256
- format ! ( "may outlive borrowed value {}" ,
1257
- cmt_path_or_string) )
1229
+ self . cannot_capture_in_long_lived_closure ( err. span ,
1230
+ & cmt_path_or_string,
1231
+ capture_span,
1232
+ Origin :: Ast )
1258
1233
. span_suggestion ( err. span ,
1259
1234
& format ! ( "to force the closure to take ownership of {} \
1260
1235
(and any other referenced variables), \
0 commit comments