@@ -9,9 +9,11 @@ use rustc_span::Span;
9
9
10
10
use crate :: session_diagnostics:: {
11
11
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 ,
15
17
} ;
16
18
17
19
impl < ' cx , ' tcx > crate :: MirBorrowckCtxt < ' cx , ' tcx > {
@@ -20,7 +22,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
20
22
span : Span ,
21
23
desc : & str ,
22
24
) -> 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 } )
24
26
}
25
27
26
28
pub ( crate ) fn cannot_use_when_mutably_borrowed (
@@ -30,17 +32,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
30
32
borrow_span : Span ,
31
33
borrow_desc : & str ,
32
34
) -> 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 } )
44
36
}
45
37
46
38
pub ( crate ) fn cannot_mutably_borrow_multiply (
@@ -52,6 +44,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
52
44
old_opt_via : & str ,
53
45
old_load_end_span : Option < Span > ,
54
46
) -> DiagnosticBuilder < ' cx , ErrorGuaranteed > {
47
+ //FIXME: migrate later
55
48
let via =
56
49
|msg : & str | if msg. is_empty ( ) { "" . to_string ( ) } else { format ! ( " (via {})" , msg) } ;
57
50
let mut err = struct_span_err ! (
@@ -100,26 +93,22 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
100
93
old_loan_span : Span ,
101
94
old_load_end_span : Option < Span > ,
102
95
) -> 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 > ;
110
98
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 ;
115
101
} 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 ) ;
118
104
}
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
+ } )
123
112
}
124
113
125
114
pub ( crate ) fn cannot_uniquely_borrow_by_one_closure (
@@ -133,24 +122,16 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
133
122
old_opt_via : & str ,
134
123
previous_end_span : Option < Span > ,
135
124
) -> 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,
141
127
desc_new,
128
+ opt_via,
142
129
noun_old,
143
130
old_opt_via,
144
- ) ;
145
- err. span_label (
146
131
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
+ } )
154
135
}
155
136
156
137
pub ( crate ) fn cannot_reborrow_already_uniquely_borrowed (
@@ -165,27 +146,17 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
165
146
previous_end_span : Option < Span > ,
166
147
second_borrow_desc : & str ,
167
148
) -> 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,
173
151
desc_new,
174
152
opt_via,
175
153
kind_new,
176
- ) ;
177
- err . span_label (
154
+ old_opt_via ,
155
+ second_borrow_desc ,
178
156
new_loan_span,
179
- format ! ( "{}borrow occurs here{}" , second_borrow_desc, opt_via) ,
180
- ) ;
181
- err. span_label (
182
157
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
+ } )
189
160
}
190
161
191
162
pub ( crate ) fn cannot_reborrow_already_borrowed (
@@ -200,6 +171,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
200
171
msg_old : & str ,
201
172
old_load_end_span : Option < Span > ,
202
173
) -> DiagnosticBuilder < ' cx , ErrorGuaranteed > {
174
+ //FIXME: would it be better for manual impl for this case?
203
175
let via =
204
176
|msg : & str | if msg. is_empty ( ) { "" . to_string ( ) } else { format ! ( " (via {})" , msg) } ;
205
177
let mut err = struct_span_err ! (
@@ -289,16 +261,10 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
289
261
( & ty:: Slice ( _) , _) => "slice" ,
290
262
_ => span_bug ! ( move_from_span, "this path should not cause illegal move" ) ,
291
263
} ;
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 } )
302
268
}
303
269
304
270
pub ( crate ) fn cannot_move_out_of_interior_of_drop (
@@ -435,11 +401,5 @@ pub(crate) fn borrowed_data_escapes_closure<'tcx>(
435
401
escape_span : Span ,
436
402
escapes_from : & str ,
437
403
) -> 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 } )
445
405
}
0 commit comments