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,7 +31,7 @@ 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,
@@ -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,7 +236,7 @@ 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,
@@ -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,7 +289,7 @@ 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,
@@ -299,7 +305,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
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,
@@ -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,
@@ -365,7 +378,7 @@ 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,
@@ -378,7 +391,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
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,
@@ -424,7 +437,7 @@ 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,
@@ -439,7 +452,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
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