1- use rustc_errors:: { struct_span_err , DiagCtxt , DiagnosticBuilder } ;
1+ use rustc_errors:: { struct_span_code_err , DiagCtxt , DiagnosticBuilder } ;
22use rustc_middle:: ty:: { self , Ty , TyCtxt } ;
33use rustc_span:: Span ;
44
@@ -31,15 +31,15 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
3131 borrow_span : Span ,
3232 borrow_desc : & str ,
3333 ) -> DiagnosticBuilder < ' tcx > {
34- struct_span_err ! (
34+ struct_span_code_err ! (
3535 self . dcx( ) ,
3636 span,
3737 E0503 ,
3838 "cannot use {} because it was mutably borrowed" ,
3939 desc,
4040 )
41- . span_label_mv ( borrow_span, format ! ( "{borrow_desc} is borrowed here" ) )
42- . span_label_mv ( span, format ! ( "use of borrowed {borrow_desc}" ) )
41+ . with_span_label ( borrow_span, format ! ( "{borrow_desc} is borrowed here" ) )
42+ . with_span_label ( span, format ! ( "use of borrowed {borrow_desc}" ) )
4343 }
4444
4545 pub ( crate ) fn cannot_mutably_borrow_multiply (
@@ -52,7 +52,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
5252 old_load_end_span : Option < Span > ,
5353 ) -> DiagnosticBuilder < ' tcx > {
5454 let via = |msg : & str | if msg. is_empty ( ) { "" . to_string ( ) } else { format ! ( " (via {msg})" ) } ;
55- let mut err = struct_span_err ! (
55+ let mut err = struct_span_code_err ! (
5656 self . dcx( ) ,
5757 new_loan_span,
5858 E0499 ,
@@ -98,7 +98,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
9898 old_loan_span : Span ,
9999 old_load_end_span : Option < Span > ,
100100 ) -> DiagnosticBuilder < ' tcx > {
101- let mut err = struct_span_err ! (
101+ let mut err = struct_span_code_err ! (
102102 self . dcx( ) ,
103103 new_loan_span,
104104 E0524 ,
@@ -131,7 +131,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
131131 old_opt_via : & str ,
132132 previous_end_span : Option < Span > ,
133133 ) -> DiagnosticBuilder < ' cx > {
134- let mut err = struct_span_err ! (
134+ let mut err = struct_span_code_err ! (
135135 self . dcx( ) ,
136136 new_loan_span,
137137 E0500 ,
@@ -163,7 +163,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
163163 previous_end_span : Option < Span > ,
164164 second_borrow_desc : & str ,
165165 ) -> DiagnosticBuilder < ' cx > {
166- let mut err = struct_span_err ! (
166+ let mut err = struct_span_code_err ! (
167167 self . dcx( ) ,
168168 new_loan_span,
169169 E0501 ,
@@ -196,7 +196,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
196196 old_load_end_span : Option < Span > ,
197197 ) -> DiagnosticBuilder < ' cx > {
198198 let via = |msg : & str | if msg. is_empty ( ) { "" . to_string ( ) } else { format ! ( " (via {msg})" ) } ;
199- let mut err = struct_span_err ! (
199+ let mut err = struct_span_code_err ! (
200200 self . dcx( ) ,
201201 span,
202202 E0502 ,
@@ -236,15 +236,15 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
236236 borrow_span : Span ,
237237 desc : & str ,
238238 ) -> DiagnosticBuilder < ' cx > {
239- struct_span_err ! (
239+ struct_span_code_err ! (
240240 self . dcx( ) ,
241241 span,
242242 E0506 ,
243243 "cannot assign to {} because it is borrowed" ,
244244 desc,
245245 )
246- . span_label_mv ( borrow_span, format ! ( "{desc} is borrowed here" ) )
247- . span_label_mv ( span, format ! ( "{desc} is assigned to here but it was already borrowed" ) )
246+ . with_span_label ( borrow_span, format ! ( "{desc} is borrowed here" ) )
247+ . with_span_label ( span, format ! ( "{desc} is assigned to here but it was already borrowed" ) )
248248 }
249249
250250 pub ( crate ) fn cannot_reassign_immutable (
@@ -254,19 +254,25 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
254254 is_arg : bool ,
255255 ) -> DiagnosticBuilder < ' cx > {
256256 let msg = if is_arg { "to immutable argument" } else { "twice to immutable variable" } ;
257- struct_span_err ! ( self . dcx( ) , span, E0384 , "cannot assign {} {}" , msg, desc)
257+ struct_span_code_err ! ( self . dcx( ) , span, E0384 , "cannot assign {} {}" , msg, desc)
258258 }
259259
260260 pub ( crate ) fn cannot_assign ( & self , span : Span , desc : & str ) -> DiagnosticBuilder < ' tcx > {
261- struct_span_err ! ( self . dcx( ) , span, E0594 , "cannot assign to {}" , desc)
261+ struct_span_code_err ! ( self . dcx( ) , span, E0594 , "cannot assign to {}" , desc)
262262 }
263263
264264 pub ( crate ) fn cannot_move_out_of (
265265 & self ,
266266 move_from_span : Span ,
267267 move_from_desc : & str ,
268268 ) -> DiagnosticBuilder < ' cx > {
269- struct_span_err ! ( self . dcx( ) , move_from_span, E0507 , "cannot move out of {}" , move_from_desc)
269+ struct_span_code_err ! (
270+ self . dcx( ) ,
271+ move_from_span,
272+ E0507 ,
273+ "cannot move out of {}" ,
274+ move_from_desc
275+ )
270276 }
271277
272278 /// Signal an error due to an attempt to move out of the interior
@@ -283,30 +289,30 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
283289 ( & ty:: Slice ( _) , _) => "slice" ,
284290 _ => span_bug ! ( move_from_span, "this path should not cause illegal move" ) ,
285291 } ;
286- struct_span_err ! (
292+ struct_span_code_err ! (
287293 self . dcx( ) ,
288294 move_from_span,
289295 E0508 ,
290296 "cannot move out of type `{}`, a non-copy {}" ,
291297 ty,
292298 type_name,
293299 )
294- . span_label_mv ( move_from_span, "cannot move out of here" )
300+ . with_span_label ( move_from_span, "cannot move out of here" )
295301 }
296302
297303 pub ( crate ) fn cannot_move_out_of_interior_of_drop (
298304 & self ,
299305 move_from_span : Span ,
300306 container_ty : Ty < ' _ > ,
301307 ) -> DiagnosticBuilder < ' cx > {
302- struct_span_err ! (
308+ struct_span_code_err ! (
303309 self . dcx( ) ,
304310 move_from_span,
305311 E0509 ,
306312 "cannot move out of type `{}`, which implements the `Drop` trait" ,
307313 container_ty,
308314 )
309- . span_label_mv ( move_from_span, "cannot move out of here" )
315+ . with_span_label ( move_from_span, "cannot move out of here" )
310316 }
311317
312318 pub ( crate ) fn cannot_act_on_moved_value (
@@ -318,7 +324,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
318324 ) -> DiagnosticBuilder < ' tcx > {
319325 let moved_path = moved_path. map ( |mp| format ! ( ": `{mp}`" ) ) . unwrap_or_default ( ) ;
320326
321- struct_span_err ! (
327+ struct_span_code_err ! (
322328 self . dcx( ) ,
323329 use_span,
324330 E0382 ,
@@ -335,7 +341,14 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
335341 path : & str ,
336342 reason : & str ,
337343 ) -> DiagnosticBuilder < ' tcx > {
338- struct_span_err ! ( self . dcx( ) , span, E0596 , "cannot borrow {} as mutable{}" , path, reason)
344+ struct_span_code_err ! (
345+ self . dcx( ) ,
346+ span,
347+ E0596 ,
348+ "cannot borrow {} as mutable{}" ,
349+ path,
350+ reason
351+ )
339352 }
340353
341354 pub ( crate ) fn cannot_mutate_in_immutable_section (
@@ -346,7 +359,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
346359 immutable_section : & str ,
347360 action : & str ,
348361 ) -> DiagnosticBuilder < ' tcx > {
349- struct_span_err ! (
362+ struct_span_code_err ! (
350363 self . dcx( ) ,
351364 mutate_span,
352365 E0510 ,
@@ -355,8 +368,8 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
355368 immutable_place,
356369 immutable_section,
357370 )
358- . span_label_mv ( mutate_span, format ! ( "cannot {action}" ) )
359- . span_label_mv ( immutable_span, format ! ( "value is immutable in {immutable_section}" ) )
371+ . with_span_label ( mutate_span, format ! ( "cannot {action}" ) )
372+ . with_span_label ( immutable_span, format ! ( "value is immutable in {immutable_section}" ) )
360373 }
361374
362375 pub ( crate ) fn cannot_borrow_across_coroutine_yield (
@@ -365,20 +378,20 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
365378 yield_span : Span ,
366379 ) -> DiagnosticBuilder < ' tcx > {
367380 let coroutine_kind = self . body . coroutine . as_ref ( ) . unwrap ( ) . coroutine_kind ;
368- struct_span_err ! (
381+ struct_span_code_err ! (
369382 self . dcx( ) ,
370383 span,
371384 E0626 ,
372385 "borrow may still be in use when {coroutine_kind:#} yields" ,
373386 )
374- . span_label_mv ( yield_span, "possible yield occurs here" )
387+ . with_span_label ( yield_span, "possible yield occurs here" )
375388 }
376389
377390 pub ( crate ) fn cannot_borrow_across_destructor (
378391 & self ,
379392 borrow_span : Span ,
380393 ) -> DiagnosticBuilder < ' tcx > {
381- struct_span_err ! (
394+ struct_span_code_err ! (
382395 self . dcx( ) ,
383396 borrow_span,
384397 E0713 ,
@@ -391,7 +404,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
391404 span : Span ,
392405 path : & str ,
393406 ) -> DiagnosticBuilder < ' tcx > {
394- struct_span_err ! ( self . dcx( ) , span, E0597 , "{} does not live long enough" , path, )
407+ struct_span_code_err ! ( self . dcx( ) , span, E0597 , "{} does not live long enough" , path, )
395408 }
396409
397410 pub ( crate ) fn cannot_return_reference_to_local (
@@ -401,7 +414,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
401414 reference_desc : & str ,
402415 path_desc : & str ,
403416 ) -> DiagnosticBuilder < ' tcx > {
404- struct_span_err ! (
417+ struct_span_code_err ! (
405418 self . dcx( ) ,
406419 span,
407420 E0515 ,
@@ -410,7 +423,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
410423 REFERENCE = reference_desc,
411424 LOCAL = path_desc,
412425 )
413- . span_label_mv (
426+ . with_span_label (
414427 span,
415428 format ! ( "{return_kind}s a {reference_desc} data owned by the current function" ) ,
416429 )
@@ -424,22 +437,22 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
424437 capture_span : Span ,
425438 scope : & str ,
426439 ) -> DiagnosticBuilder < ' tcx > {
427- struct_span_err ! (
440+ struct_span_code_err ! (
428441 self . dcx( ) ,
429442 closure_span,
430443 E0373 ,
431444 "{closure_kind} may outlive the current {scope}, but it borrows {borrowed_path}, \
432445 which is owned by the current {scope}",
433446 )
434- . span_label_mv ( capture_span, format ! ( "{borrowed_path} is borrowed here" ) )
435- . span_label_mv ( closure_span, format ! ( "may outlive borrowed value {borrowed_path}" ) )
447+ . with_span_label ( capture_span, format ! ( "{borrowed_path} is borrowed here" ) )
448+ . with_span_label ( closure_span, format ! ( "may outlive borrowed value {borrowed_path}" ) )
436449 }
437450
438451 pub ( crate ) fn thread_local_value_does_not_live_long_enough (
439452 & self ,
440453 span : Span ,
441454 ) -> DiagnosticBuilder < ' tcx > {
442- struct_span_err ! (
455+ struct_span_code_err ! (
443456 self . dcx( ) ,
444457 span,
445458 E0712 ,
@@ -451,7 +464,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
451464 & self ,
452465 span : Span ,
453466 ) -> DiagnosticBuilder < ' tcx > {
454- struct_span_err ! ( self . dcx( ) , span, E0716 , "temporary value dropped while borrowed" , )
467+ struct_span_code_err ! ( self . dcx( ) , span, E0716 , "temporary value dropped while borrowed" , )
455468 }
456469}
457470
@@ -460,7 +473,7 @@ pub(crate) fn borrowed_data_escapes_closure<'tcx>(
460473 escape_span : Span ,
461474 escapes_from : & str ,
462475) -> DiagnosticBuilder < ' tcx > {
463- struct_span_err ! (
476+ struct_span_code_err ! (
464477 tcx. dcx( ) ,
465478 escape_span,
466479 E0521 ,
0 commit comments