@@ -9,9 +9,11 @@ use rustc_span::Span;
99
1010use crate :: session_diagnostics:: {
1111 ActMovedValueErr , AssignBorrowErr , AssignErr , BorrowAcrossDestructor ,
12- BorrowAcrossGeneratorYield , ClosureVarOutliveErr , ImmuteArgAssign , ImmuteVarReassign ,
13- InteriorDropMoveErr , MovedOutErr , MutateInImmute , PathShortLive , ReturnRefLocalErr ,
14- TemporaryDroppedErr , ThreadLocalOutliveErr ,
12+ BorrowAcrossGeneratorYield , BorrowEscapeClosure , ClosureConstructLabel ,
13+ ClosureUniquelyBorrowErr , ClosureVarOutliveErr , ImmuteArgAssign , ImmuteVarReassign ,
14+ InteriorDropMoveErr , InteriorNoncopyMoveErr , MoveBorrowedErr , MovedOutErr , MutateInImmute ,
15+ PathShortLive , ReturnRefLocalErr , TemporaryDroppedErr , ThreadLocalOutliveErr ,
16+ TwoClosuresUniquelyBorrowErr , UniquelyBorrowReborrowErr , UseMutBorrowErr ,
1517} ;
1618
1719impl < ' cx , ' tcx > crate :: MirBorrowckCtxt < ' cx , ' tcx > {
@@ -20,7 +22,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
2022 span : Span ,
2123 desc : & str ,
2224 ) -> DiagnosticBuilder < ' cx , ErrorGuaranteed > {
23- struct_span_err ! ( self , span , E0505 , "cannot move out of {} because it is borrowed" , desc , )
25+ self . infcx . tcx . sess . create_err ( MoveBorrowedErr { desc , span } )
2426 }
2527
2628 pub ( crate ) fn cannot_use_when_mutably_borrowed (
@@ -30,17 +32,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
3032 borrow_span : Span ,
3133 borrow_desc : & str ,
3234 ) -> DiagnosticBuilder < ' cx , ErrorGuaranteed > {
33- let mut err = struct_span_err ! (
34- self ,
35- span,
36- E0503 ,
37- "cannot use {} because it was mutably borrowed" ,
38- desc,
39- ) ;
40-
41- err. span_label ( borrow_span, format ! ( "borrow of {} occurs here" , borrow_desc) ) ;
42- err. span_label ( span, format ! ( "use of borrowed {}" , borrow_desc) ) ;
43- err
35+ self . infcx . tcx . sess . create_err ( UseMutBorrowErr { desc, borrow_desc, span, borrow_span } )
4436 }
4537
4638 pub ( crate ) fn cannot_mutably_borrow_multiply (
@@ -52,6 +44,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
5244 old_opt_via : & str ,
5345 old_load_end_span : Option < Span > ,
5446 ) -> DiagnosticBuilder < ' cx , ErrorGuaranteed > {
47+ //FIXME: migrate later
5548 let via =
5649 |msg : & str | if msg. is_empty ( ) { "" . to_string ( ) } else { format ! ( " (via {})" , msg) } ;
5750 let mut err = struct_span_err ! (
@@ -100,26 +93,22 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
10093 old_loan_span : Span ,
10194 old_load_end_span : Option < Span > ,
10295 ) -> DiagnosticBuilder < ' cx , ErrorGuaranteed > {
103- let mut err = struct_span_err ! (
104- self ,
105- new_loan_span,
106- E0524 ,
107- "two closures require unique access to {} at the same time" ,
108- desc,
109- ) ;
96+ let case: ClosureConstructLabel ;
97+ let diff_span: Option < Span > ;
11098 if old_loan_span == new_loan_span {
111- err. span_label (
112- old_loan_span,
113- "closures are constructed here in different iterations of loop" ,
114- ) ;
99+ case = ClosureConstructLabel :: Both { old_loan_span } ;
100+ diff_span = None ;
115101 } else {
116- err . span_label ( old_loan_span , "first closure is constructed here" ) ;
117- err . span_label ( new_loan_span , "second closure is constructed here" ) ;
102+ case = ClosureConstructLabel :: First { old_loan_span } ;
103+ diff_span = Some ( new_loan_span ) ;
118104 }
119- if let Some ( old_load_end_span) = old_load_end_span {
120- err. span_label ( old_load_end_span, "borrow from first closure ends here" ) ;
121- }
122- err
105+ self . infcx . tcx . sess . create_err ( TwoClosuresUniquelyBorrowErr {
106+ desc,
107+ case,
108+ new_loan_span,
109+ old_load_end_span,
110+ diff_span,
111+ } )
123112 }
124113
125114 pub ( crate ) fn cannot_uniquely_borrow_by_one_closure (
@@ -133,24 +122,16 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
133122 old_opt_via : & str ,
134123 previous_end_span : Option < Span > ,
135124 ) -> DiagnosticBuilder < ' cx , ErrorGuaranteed > {
136- let mut err = struct_span_err ! (
137- self ,
138- new_loan_span,
139- E0500 ,
140- "closure requires unique access to {} but {} is already borrowed{}" ,
125+ self . infcx . tcx . sess . create_err ( ClosureUniquelyBorrowErr {
126+ container_name,
141127 desc_new,
128+ opt_via,
142129 noun_old,
143130 old_opt_via,
144- ) ;
145- err. span_label (
146131 new_loan_span,
147- format ! ( "{} construction occurs here{}" , container_name, opt_via) ,
148- ) ;
149- err. span_label ( old_loan_span, format ! ( "borrow occurs here{}" , old_opt_via) ) ;
150- if let Some ( previous_end_span) = previous_end_span {
151- err. span_label ( previous_end_span, "borrow ends here" ) ;
152- }
153- err
132+ old_loan_span,
133+ previous_end_span,
134+ } )
154135 }
155136
156137 pub ( crate ) fn cannot_reborrow_already_uniquely_borrowed (
@@ -165,27 +146,17 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
165146 previous_end_span : Option < Span > ,
166147 second_borrow_desc : & str ,
167148 ) -> DiagnosticBuilder < ' cx , ErrorGuaranteed > {
168- let mut err = struct_span_err ! (
169- self ,
170- new_loan_span,
171- E0501 ,
172- "cannot borrow {}{} as {} because previous closure requires unique access" ,
149+ self . infcx . tcx . sess . create_err ( UniquelyBorrowReborrowErr {
150+ container_name,
173151 desc_new,
174152 opt_via,
175153 kind_new,
176- ) ;
177- err . span_label (
154+ old_opt_via ,
155+ second_borrow_desc ,
178156 new_loan_span,
179- format ! ( "{}borrow occurs here{}" , second_borrow_desc, opt_via) ,
180- ) ;
181- err. span_label (
182157 old_loan_span,
183- format ! ( "{} construction occurs here{}" , container_name, old_opt_via) ,
184- ) ;
185- if let Some ( previous_end_span) = previous_end_span {
186- err. span_label ( previous_end_span, "borrow from closure ends here" ) ;
187- }
188- err
158+ previous_end_span,
159+ } )
189160 }
190161
191162 pub ( crate ) fn cannot_reborrow_already_borrowed (
@@ -200,6 +171,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
200171 msg_old : & str ,
201172 old_load_end_span : Option < Span > ,
202173 ) -> DiagnosticBuilder < ' cx , ErrorGuaranteed > {
174+ //FIXME: would it be better for manual impl for this case?
203175 let via =
204176 |msg : & str | if msg. is_empty ( ) { "" . to_string ( ) } else { format ! ( " (via {})" , msg) } ;
205177 let mut err = struct_span_err ! (
@@ -289,16 +261,10 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
289261 ( & ty:: Slice ( _) , _) => "slice" ,
290262 _ => span_bug ! ( move_from_span, "this path should not cause illegal move" ) ,
291263 } ;
292- let mut err = struct_span_err ! (
293- self ,
294- move_from_span,
295- E0508 ,
296- "cannot move out of type `{}`, a non-copy {}" ,
297- ty,
298- type_name,
299- ) ;
300- err. span_label ( move_from_span, "cannot move out of here" ) ;
301- err
264+ //FIXME: failed ui test diag-migration
265+ // - error[E0508]: cannot move out of type `[S; 1]`, a non-copy array
266+ // + error[E0508]: cannot move out of type `S`, a non-copy array
267+ self . infcx . tcx . sess . create_err ( InteriorNoncopyMoveErr { ty, type_name, move_from_span } )
302268 }
303269
304270 pub ( crate ) fn cannot_move_out_of_interior_of_drop (
@@ -435,11 +401,5 @@ pub(crate) fn borrowed_data_escapes_closure<'tcx>(
435401 escape_span : Span ,
436402 escapes_from : & str ,
437403) -> DiagnosticBuilder < ' tcx , ErrorGuaranteed > {
438- struct_span_err ! (
439- tcx. sess,
440- escape_span,
441- E0521 ,
442- "borrowed data escapes outside of {}" ,
443- escapes_from,
444- )
404+ tcx. sess . create_err ( BorrowEscapeClosure { escapes_from, escape_span } )
445405}
0 commit comments