Skip to content

Commit 4864cb8

Browse files
committed
Rename struct_span_err! as struct_span_code_err!.
Because it takes an error code after the span. This avoids the confusing overlap with the `DiagCtxt::struct_span_err` method, which doesn't take an error code.
1 parent 99b1b0f commit 4864cb8

File tree

46 files changed

+277
-224
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+277
-224
lines changed

compiler/rustc_borrowck/src/borrowck_errors.rs

+37-24
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use rustc_errors::{struct_span_err, DiagCtxt, DiagnosticBuilder};
1+
use rustc_errors::{struct_span_code_err, DiagCtxt, DiagnosticBuilder};
22
use rustc_middle::ty::{self, Ty, TyCtxt};
33
use rustc_span::Span;
44

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

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
// ignore-tidy-filelength
2+
13
use either::Either;
24
use rustc_data_structures::captures::Captures;
35
use rustc_data_structures::fx::FxIndexSet;
4-
use rustc_errors::{struct_span_err, Applicability, Diagnostic, DiagnosticBuilder, MultiSpan};
6+
use rustc_errors::{struct_span_code_err, Applicability, Diagnostic, DiagnosticBuilder, MultiSpan};
57
use rustc_hir as hir;
68
use rustc_hir::def::{DefKind, Res};
79
use rustc_hir::intravisit::{walk_block, walk_expr, Visitor};
@@ -550,8 +552,12 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
550552
};
551553

552554
let used = desired_action.as_general_verb_in_past_tense();
553-
let mut err =
554-
struct_span_err!(self.dcx(), span, E0381, "{used} binding {desc}{isnt_initialized}");
555+
let mut err = struct_span_code_err!(
556+
self.dcx(),
557+
span,
558+
E0381,
559+
"{used} binding {desc}{isnt_initialized}"
560+
);
555561
use_spans.var_path_only_subdiag(&mut err, desired_action);
556562

557563
if let InitializationRequiringAction::PartialAssignment

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

+14-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rustc_ast::{ast, attr, MetaItemKind, NestedMetaItem};
22
use rustc_attr::{list_contains_name, InlineAttr, InstructionSetAttr, OptimizeAttr};
3-
use rustc_errors::struct_span_err;
3+
use rustc_errors::struct_span_code_err;
44
use rustc_hir as hir;
55
use rustc_hir::def::DefKind;
66
use rustc_hir::def_id::{DefId, LocalDefId, LOCAL_CRATE};
@@ -216,7 +216,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
216216
if let Some(fn_sig) = fn_sig()
217217
&& !matches!(fn_sig.skip_binder().abi(), abi::Abi::C { .. })
218218
{
219-
struct_span_err!(
219+
struct_span_code_err!(
220220
tcx.dcx(),
221221
attr.span,
222222
E0776,
@@ -225,7 +225,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
225225
.emit();
226226
}
227227
if !tcx.sess.target.llvm_target.contains("thumbv8m") {
228-
struct_span_err!(tcx.dcx(), attr.span, E0775, "`#[cmse_nonsecure_entry]` is only valid for targets with the TrustZone-M extension")
228+
struct_span_code_err!(tcx.dcx(), attr.span, E0775, "`#[cmse_nonsecure_entry]` is only valid for targets with the TrustZone-M extension")
229229
.emit();
230230
}
231231
codegen_fn_attrs.flags |= CodegenFnAttrFlags::CMSE_NONSECURE_ENTRY
@@ -238,7 +238,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
238238
&& let Some(fn_sig) = fn_sig()
239239
&& fn_sig.skip_binder().abi() != abi::Abi::Rust
240240
{
241-
struct_span_err!(
241+
struct_span_code_err!(
242242
tcx.dcx(),
243243
attr.span,
244244
E0737,
@@ -265,7 +265,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
265265
if s.as_str().contains('\0') {
266266
// `#[export_name = ...]` will be converted to a null-terminated string,
267267
// so it may not contain any null characters.
268-
struct_span_err!(
268+
struct_span_code_err!(
269269
tcx.dcx(),
270270
attr.span,
271271
E0648,
@@ -385,7 +385,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
385385
match segments.as_slice() {
386386
[sym::arm, sym::a32] | [sym::arm, sym::t32] => {
387387
if !tcx.sess.target.has_thumb_interworking {
388-
struct_span_err!(
388+
struct_span_code_err!(
389389
tcx.dcx(),
390390
attr.span,
391391
E0779,
@@ -402,7 +402,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
402402
}
403403
}
404404
_ => {
405-
struct_span_err!(
405+
struct_span_code_err!(
406406
tcx.dcx(),
407407
attr.span,
408408
E0779,
@@ -414,7 +414,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
414414
}
415415
}
416416
[] => {
417-
struct_span_err!(
417+
struct_span_code_err!(
418418
tcx.dcx(),
419419
attr.span,
420420
E0778,
@@ -424,7 +424,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
424424
None
425425
}
426426
_ => {
427-
struct_span_err!(
427+
struct_span_code_err!(
428428
tcx.dcx(),
429429
attr.span,
430430
E0779,
@@ -442,7 +442,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
442442
{
443443
rustc_attr::parse_alignment(&literal.kind)
444444
.map_err(|msg| {
445-
struct_span_err!(
445+
struct_span_code_err!(
446446
tcx.dcx(),
447447
attr.span,
448448
E0589,
@@ -469,14 +469,15 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
469469
Some(MetaItemKind::List(ref items)) => {
470470
inline_span = Some(attr.span);
471471
if items.len() != 1 {
472-
struct_span_err!(tcx.dcx(), attr.span, E0534, "expected one argument").emit();
472+
struct_span_code_err!(tcx.dcx(), attr.span, E0534, "expected one argument")
473+
.emit();
473474
InlineAttr::None
474475
} else if list_contains_name(items, sym::always) {
475476
InlineAttr::Always
476477
} else if list_contains_name(items, sym::never) {
477478
InlineAttr::Never
478479
} else {
479-
struct_span_err!(tcx.dcx(), items[0].span(), E0535, "invalid argument")
480+
struct_span_code_err!(tcx.dcx(), items[0].span(), E0535, "invalid argument")
480481
.help_mv("valid inline arguments are `always` and `never`")
481482
.emit();
482483

@@ -492,7 +493,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
492493
if !attr.has_name(sym::optimize) {
493494
return ia;
494495
}
495-
let err = |sp, s| struct_span_err!(tcx.dcx(), sp, E0722, "{}", s).emit();
496+
let err = |sp, s| struct_span_code_err!(tcx.dcx(), sp, E0722, "{}", s).emit();
496497
match attr.meta_kind() {
497498
Some(MetaItemKind::Word) => {
498499
err(attr.span, "expected one argument");

compiler/rustc_errors/src/diagnostic_builder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ impl<G: EmissionGuarantee> Drop for DiagnosticBuilder<'_, G> {
453453
}
454454

455455
#[macro_export]
456-
macro_rules! struct_span_err {
456+
macro_rules! struct_span_code_err {
457457
($dcx:expr, $span:expr, $code:ident, $($message:tt)*) => ({
458458
$dcx.struct_span_err(
459459
$span,

compiler/rustc_hir_analysis/src/astconv/bounds.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use rustc_data_structures::fx::FxHashMap;
2-
use rustc_errors::struct_span_err;
2+
use rustc_errors::struct_span_code_err;
33
use rustc_hir as hir;
44
use rustc_hir::def::{DefKind, Res};
55
use rustc_hir::def_id::{DefId, LocalDefId};
@@ -462,7 +462,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
462462
late_bound_in_trait_ref,
463463
late_bound_in_ty,
464464
|br_name| {
465-
struct_span_err!(
465+
struct_span_code_err!(
466466
tcx.dcx(),
467467
binding.span,
468468
E0582,

0 commit comments

Comments
 (0)