1
- use rustc_errors:: { struct_span_err , DiagCtxt , DiagnosticBuilder } ;
1
+ use rustc_errors:: { struct_span_code_err , DiagCtxt , DiagnosticBuilder } ;
2
2
use rustc_middle:: ty:: { self , Ty , TyCtxt } ;
3
3
use rustc_span:: Span ;
4
4
@@ -31,15 +31,15 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
31
31
borrow_span : Span ,
32
32
borrow_desc : & str ,
33
33
) -> DiagnosticBuilder < ' tcx > {
34
- struct_span_err ! (
34
+ struct_span_code_err ! (
35
35
self . dcx( ) ,
36
36
span,
37
37
E0503 ,
38
38
"cannot use {} because it was mutably borrowed" ,
39
39
desc,
40
40
)
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}" ) )
43
43
}
44
44
45
45
pub ( crate ) fn cannot_mutably_borrow_multiply (
@@ -52,7 +52,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
52
52
old_load_end_span : Option < Span > ,
53
53
) -> DiagnosticBuilder < ' tcx > {
54
54
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 ! (
56
56
self . dcx( ) ,
57
57
new_loan_span,
58
58
E0499 ,
@@ -98,7 +98,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
98
98
old_loan_span : Span ,
99
99
old_load_end_span : Option < Span > ,
100
100
) -> DiagnosticBuilder < ' tcx > {
101
- let mut err = struct_span_err ! (
101
+ let mut err = struct_span_code_err ! (
102
102
self . dcx( ) ,
103
103
new_loan_span,
104
104
E0524 ,
@@ -131,7 +131,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
131
131
old_opt_via : & str ,
132
132
previous_end_span : Option < Span > ,
133
133
) -> DiagnosticBuilder < ' cx > {
134
- let mut err = struct_span_err ! (
134
+ let mut err = struct_span_code_err ! (
135
135
self . dcx( ) ,
136
136
new_loan_span,
137
137
E0500 ,
@@ -163,7 +163,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
163
163
previous_end_span : Option < Span > ,
164
164
second_borrow_desc : & str ,
165
165
) -> DiagnosticBuilder < ' cx > {
166
- let mut err = struct_span_err ! (
166
+ let mut err = struct_span_code_err ! (
167
167
self . dcx( ) ,
168
168
new_loan_span,
169
169
E0501 ,
@@ -196,7 +196,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
196
196
old_load_end_span : Option < Span > ,
197
197
) -> DiagnosticBuilder < ' cx > {
198
198
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 ! (
200
200
self . dcx( ) ,
201
201
span,
202
202
E0502 ,
@@ -236,15 +236,15 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
236
236
borrow_span : Span ,
237
237
desc : & str ,
238
238
) -> DiagnosticBuilder < ' cx > {
239
- struct_span_err ! (
239
+ struct_span_code_err ! (
240
240
self . dcx( ) ,
241
241
span,
242
242
E0506 ,
243
243
"cannot assign to {} because it is borrowed" ,
244
244
desc,
245
245
)
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" ) )
248
248
}
249
249
250
250
pub ( crate ) fn cannot_reassign_immutable (
@@ -254,19 +254,25 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
254
254
is_arg : bool ,
255
255
) -> DiagnosticBuilder < ' cx > {
256
256
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)
258
258
}
259
259
260
260
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)
262
262
}
263
263
264
264
pub ( crate ) fn cannot_move_out_of (
265
265
& self ,
266
266
move_from_span : Span ,
267
267
move_from_desc : & str ,
268
268
) -> 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
+ )
270
276
}
271
277
272
278
/// Signal an error due to an attempt to move out of the interior
@@ -283,30 +289,30 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
283
289
( & ty:: Slice ( _) , _) => "slice" ,
284
290
_ => span_bug ! ( move_from_span, "this path should not cause illegal move" ) ,
285
291
} ;
286
- struct_span_err ! (
292
+ struct_span_code_err ! (
287
293
self . dcx( ) ,
288
294
move_from_span,
289
295
E0508 ,
290
296
"cannot move out of type `{}`, a non-copy {}" ,
291
297
ty,
292
298
type_name,
293
299
)
294
- . span_label_mv ( move_from_span, "cannot move out of here" )
300
+ . with_span_label ( move_from_span, "cannot move out of here" )
295
301
}
296
302
297
303
pub ( crate ) fn cannot_move_out_of_interior_of_drop (
298
304
& self ,
299
305
move_from_span : Span ,
300
306
container_ty : Ty < ' _ > ,
301
307
) -> DiagnosticBuilder < ' cx > {
302
- struct_span_err ! (
308
+ struct_span_code_err ! (
303
309
self . dcx( ) ,
304
310
move_from_span,
305
311
E0509 ,
306
312
"cannot move out of type `{}`, which implements the `Drop` trait" ,
307
313
container_ty,
308
314
)
309
- . span_label_mv ( move_from_span, "cannot move out of here" )
315
+ . with_span_label ( move_from_span, "cannot move out of here" )
310
316
}
311
317
312
318
pub ( crate ) fn cannot_act_on_moved_value (
@@ -318,7 +324,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
318
324
) -> DiagnosticBuilder < ' tcx > {
319
325
let moved_path = moved_path. map ( |mp| format ! ( ": `{mp}`" ) ) . unwrap_or_default ( ) ;
320
326
321
- struct_span_err ! (
327
+ struct_span_code_err ! (
322
328
self . dcx( ) ,
323
329
use_span,
324
330
E0382 ,
@@ -335,7 +341,14 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
335
341
path : & str ,
336
342
reason : & str ,
337
343
) -> 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
+ )
339
352
}
340
353
341
354
pub ( crate ) fn cannot_mutate_in_immutable_section (
@@ -346,7 +359,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
346
359
immutable_section : & str ,
347
360
action : & str ,
348
361
) -> DiagnosticBuilder < ' tcx > {
349
- struct_span_err ! (
362
+ struct_span_code_err ! (
350
363
self . dcx( ) ,
351
364
mutate_span,
352
365
E0510 ,
@@ -355,8 +368,8 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
355
368
immutable_place,
356
369
immutable_section,
357
370
)
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}" ) )
360
373
}
361
374
362
375
pub ( crate ) fn cannot_borrow_across_coroutine_yield (
@@ -365,20 +378,20 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
365
378
yield_span : Span ,
366
379
) -> DiagnosticBuilder < ' tcx > {
367
380
let coroutine_kind = self . body . coroutine . as_ref ( ) . unwrap ( ) . coroutine_kind ;
368
- struct_span_err ! (
381
+ struct_span_code_err ! (
369
382
self . dcx( ) ,
370
383
span,
371
384
E0626 ,
372
385
"borrow may still be in use when {coroutine_kind:#} yields" ,
373
386
)
374
- . span_label_mv ( yield_span, "possible yield occurs here" )
387
+ . with_span_label ( yield_span, "possible yield occurs here" )
375
388
}
376
389
377
390
pub ( crate ) fn cannot_borrow_across_destructor (
378
391
& self ,
379
392
borrow_span : Span ,
380
393
) -> DiagnosticBuilder < ' tcx > {
381
- struct_span_err ! (
394
+ struct_span_code_err ! (
382
395
self . dcx( ) ,
383
396
borrow_span,
384
397
E0713 ,
@@ -391,7 +404,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
391
404
span : Span ,
392
405
path : & str ,
393
406
) -> 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, )
395
408
}
396
409
397
410
pub ( crate ) fn cannot_return_reference_to_local (
@@ -401,7 +414,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
401
414
reference_desc : & str ,
402
415
path_desc : & str ,
403
416
) -> DiagnosticBuilder < ' tcx > {
404
- struct_span_err ! (
417
+ struct_span_code_err ! (
405
418
self . dcx( ) ,
406
419
span,
407
420
E0515 ,
@@ -410,7 +423,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
410
423
REFERENCE = reference_desc,
411
424
LOCAL = path_desc,
412
425
)
413
- . span_label_mv (
426
+ . with_span_label (
414
427
span,
415
428
format ! ( "{return_kind}s a {reference_desc} data owned by the current function" ) ,
416
429
)
@@ -424,22 +437,22 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
424
437
capture_span : Span ,
425
438
scope : & str ,
426
439
) -> DiagnosticBuilder < ' tcx > {
427
- struct_span_err ! (
440
+ struct_span_code_err ! (
428
441
self . dcx( ) ,
429
442
closure_span,
430
443
E0373 ,
431
444
"{closure_kind} may outlive the current {scope}, but it borrows {borrowed_path}, \
432
445
which is owned by the current {scope}",
433
446
)
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}" ) )
436
449
}
437
450
438
451
pub ( crate ) fn thread_local_value_does_not_live_long_enough (
439
452
& self ,
440
453
span : Span ,
441
454
) -> DiagnosticBuilder < ' tcx > {
442
- struct_span_err ! (
455
+ struct_span_code_err ! (
443
456
self . dcx( ) ,
444
457
span,
445
458
E0712 ,
@@ -451,7 +464,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
451
464
& self ,
452
465
span : Span ,
453
466
) -> 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" , )
455
468
}
456
469
}
457
470
@@ -460,7 +473,7 @@ pub(crate) fn borrowed_data_escapes_closure<'tcx>(
460
473
escape_span : Span ,
461
474
escapes_from : & str ,
462
475
) -> DiagnosticBuilder < ' tcx > {
463
- struct_span_err ! (
476
+ struct_span_code_err ! (
464
477
tcx. dcx( ) ,
465
478
escape_span,
466
479
E0521 ,
0 commit comments