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.
This commit is contained in:
Nicholas Nethercote
2024-01-04 09:08:36 +11:00
parent 99b1b0f85c
commit 4864cb8aef
46 changed files with 277 additions and 224 deletions

View File

@@ -37,7 +37,7 @@ pub fn check_abi(tcx: TyCtxt<'_>, hir_id: hir::HirId, span: Span, abi: Abi) {
match tcx.sess.target.is_abi_supported(abi) {
Some(true) => (),
Some(false) => {
struct_span_err!(
struct_span_code_err!(
tcx.dcx(),
span,
E0570,
@@ -58,7 +58,7 @@ pub fn check_abi(tcx: TyCtxt<'_>, hir_id: hir::HirId, span: Span, abi: Abi) {
// This ABI is only allowed on function pointers
if abi == Abi::CCmseNonSecureCall {
struct_span_err!(
struct_span_code_err!(
tcx.dcx(),
span,
E0781,
@@ -560,7 +560,7 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) {
(0, _) => ("const", "consts", None),
_ => ("type or const", "types or consts", None),
};
struct_span_err!(
struct_span_code_err!(
tcx.dcx(),
item.span,
E0044,
@@ -687,7 +687,7 @@ fn check_impl_items_against_trait<'tcx>(
ty::ImplPolarity::Negative => {
if let [first_item_ref, ..] = impl_item_refs {
let first_item_span = tcx.def_span(first_item_ref);
struct_span_err!(
struct_span_code_err!(
tcx.dcx(),
first_item_span,
E0749,
@@ -840,12 +840,12 @@ pub fn check_simd(tcx: TyCtxt<'_>, sp: Span, def_id: LocalDefId) {
{
let fields = &def.non_enum_variant().fields;
if fields.is_empty() {
struct_span_err!(tcx.dcx(), sp, E0075, "SIMD vector cannot be empty").emit();
struct_span_code_err!(tcx.dcx(), sp, E0075, "SIMD vector cannot be empty").emit();
return;
}
let e = fields[FieldIdx::from_u32(0)].ty(tcx, args);
if !fields.iter().all(|f| f.ty(tcx, args) == e) {
struct_span_err!(tcx.dcx(), sp, E0076, "SIMD vector should be homogeneous")
struct_span_code_err!(tcx.dcx(), sp, E0076, "SIMD vector should be homogeneous")
.span_label_mv(sp, "SIMD elements must have the same type")
.emit();
return;
@@ -858,10 +858,10 @@ pub fn check_simd(tcx: TyCtxt<'_>, sp: Span, def_id: LocalDefId) {
};
if let Some(len) = len {
if len == 0 {
struct_span_err!(tcx.dcx(), sp, E0075, "SIMD vector cannot be empty").emit();
struct_span_code_err!(tcx.dcx(), sp, E0075, "SIMD vector cannot be empty").emit();
return;
} else if len > MAX_SIMD_LANES {
struct_span_err!(
struct_span_code_err!(
tcx.dcx(),
sp,
E0075,
@@ -884,7 +884,7 @@ pub fn check_simd(tcx: TyCtxt<'_>, sp: Span, def_id: LocalDefId) {
if matches!(t.kind(), ty::Int(_) | ty::Uint(_) | ty::Float(_) | ty::RawPtr(_)) =>
{ /* struct([f32; 4]) is ok */ }
_ => {
struct_span_err!(
struct_span_code_err!(
tcx.dcx(),
sp,
E0077,
@@ -907,7 +907,7 @@ pub(super) fn check_packed(tcx: TyCtxt<'_>, sp: Span, def: ty::AdtDef<'_>) {
&& let Some(repr_pack) = repr.pack
&& pack as u64 != repr_pack.bytes()
{
struct_span_err!(
struct_span_code_err!(
tcx.dcx(),
sp,
E0634,
@@ -918,7 +918,7 @@ pub(super) fn check_packed(tcx: TyCtxt<'_>, sp: Span, def: ty::AdtDef<'_>) {
}
}
if repr.align.is_some() {
struct_span_err!(
struct_span_code_err!(
tcx.dcx(),
sp,
E0587,
@@ -927,7 +927,7 @@ pub(super) fn check_packed(tcx: TyCtxt<'_>, sp: Span, def: ty::AdtDef<'_>) {
.emit();
} else {
if let Some(def_spans) = check_packed_inner(tcx, def.did(), &mut vec![]) {
let mut err = struct_span_err!(
let mut err = struct_span_code_err!(
tcx.dcx(),
sp,
E0588,
@@ -1117,7 +1117,7 @@ fn check_enum(tcx: TyCtxt<'_>, def_id: LocalDefId) {
if def.variants().is_empty() {
if let Some(attr) = tcx.get_attrs(def_id, sym::repr).next() {
struct_span_err!(
struct_span_code_err!(
tcx.dcx(),
attr.span,
E0084,
@@ -1156,7 +1156,7 @@ fn check_enum(tcx: TyCtxt<'_>, def_id: LocalDefId) {
let disr_non_unit = def.variants().iter().any(|var| !is_unit(var) && has_disr(var));
if disr_non_unit || (disr_units && has_non_units) {
struct_span_err!(
struct_span_code_err!(
tcx.dcx(),
tcx.def_span(def_id),
E0732,
@@ -1242,7 +1242,7 @@ fn detect_discriminant_duplicate<'tcx>(tcx: TyCtxt<'tcx>, adt: ty::AdtDef<'tcx>)
if discrs[i].1.val == discrs[o].1.val {
let err = error.get_or_insert_with(|| {
let mut ret = struct_span_err!(
let mut ret = struct_span_code_err!(
tcx.dcx(),
tcx.def_span(adt.did()),
E0081,
@@ -1309,9 +1309,15 @@ pub(super) fn check_type_params_are_used<'tcx>(
&& let ty::GenericParamDefKind::Type { .. } = param.kind
{
let span = tcx.def_span(param.def_id);
struct_span_err!(tcx.dcx(), span, E0091, "type parameter `{}` is unused", param.name,)
.span_label_mv(span, "unused type parameter")
.emit();
struct_span_code_err!(
tcx.dcx(),
span,
E0091,
"type parameter `{}` is unused",
param.name,
)
.span_label_mv(span, "unused type parameter")
.emit();
}
}
}
@@ -1329,7 +1335,7 @@ fn opaque_type_cycle_error(
opaque_def_id: LocalDefId,
span: Span,
) -> ErrorGuaranteed {
let mut err = struct_span_err!(tcx.dcx(), span, E0720, "cannot resolve opaque type");
let mut err = struct_span_code_err!(tcx.dcx(), span, E0720, "cannot resolve opaque type");
let mut label = false;
if let Some((def_id, visitor)) = get_owner_return_paths(tcx, opaque_def_id) {

View File

@@ -2,7 +2,7 @@ use super::potentially_plural_count;
use crate::errors::LifetimesOrBoundsMismatchOnTrait;
use hir::def_id::{DefId, DefIdMap, LocalDefId};
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet};
use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticId, ErrorGuaranteed};
use rustc_errors::{pluralize, struct_span_code_err, Applicability, DiagnosticId, ErrorGuaranteed};
use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res};
use rustc_hir::intravisit;
@@ -625,7 +625,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
match ocx.eq(&cause, param_env, trait_return_ty, impl_return_ty) {
Ok(()) => {}
Err(terr) => {
let mut diag = struct_span_err!(
let mut diag = struct_span_code_err!(
tcx.dcx(),
cause.span(),
E0053,
@@ -972,7 +972,7 @@ fn report_trait_method_mismatch<'tcx>(
let (impl_err_span, trait_err_span) =
extract_spans_for_error_reporting(infcx, terr, &cause, impl_m, trait_m);
let mut diag = struct_span_err!(
let mut diag = struct_span_code_err!(
tcx.dcx(),
impl_err_span,
E0053,
@@ -1217,7 +1217,7 @@ fn compare_self_type<'tcx>(
(false, true) => {
let self_descr = self_string(impl_m);
let impl_m_span = tcx.def_span(impl_m.def_id);
let mut err = struct_span_err!(
let mut err = struct_span_code_err!(
tcx.dcx(),
impl_m_span,
E0185,
@@ -1237,7 +1237,7 @@ fn compare_self_type<'tcx>(
(true, false) => {
let self_descr = self_string(trait_m);
let impl_m_span = tcx.def_span(impl_m.def_id);
let mut err = struct_span_err!(
let mut err = struct_span_code_err!(
tcx.dcx(),
impl_m_span,
E0186,
@@ -1463,7 +1463,7 @@ fn compare_number_of_method_arguments<'tcx>(
})
.unwrap_or_else(|| tcx.def_span(impl_m.def_id));
let mut err = struct_span_err!(
let mut err = struct_span_code_err!(
tcx.dcx(),
impl_span,
E0050,
@@ -1530,7 +1530,7 @@ fn compare_synthetic_generics<'tcx>(
let impl_def_id = impl_def_id.expect_local();
let impl_span = tcx.def_span(impl_def_id);
let trait_span = tcx.def_span(trait_def_id);
let mut err = struct_span_err!(
let mut err = struct_span_code_err!(
tcx.dcx(),
impl_span,
E0643,
@@ -1689,7 +1689,7 @@ fn compare_generic_param_kinds<'tcx>(
let param_impl_span = tcx.def_span(param_impl.def_id);
let param_trait_span = tcx.def_span(param_trait.def_id);
let mut err = struct_span_err!(
let mut err = struct_span_code_err!(
tcx.dcx(),
param_impl_span,
E0053,
@@ -1836,7 +1836,7 @@ fn compare_const_predicate_entailment<'tcx>(
let (ty, _) = tcx.hir().expect_impl_item(impl_ct_def_id).expect_const();
cause.span = ty.span;
let mut diag = struct_span_err!(
let mut diag = struct_span_code_err!(
tcx.dcx(),
cause.span,
E0326,

View File

@@ -2,7 +2,7 @@
//
// We don't do any drop checking during hir typeck.
use rustc_data_structures::fx::FxHashSet;
use rustc_errors::{struct_span_err, ErrorGuaranteed};
use rustc_errors::{struct_span_code_err, ErrorGuaranteed};
use rustc_infer::infer::outlives::env::OutlivesEnvironment;
use rustc_infer::infer::{RegionResolutionError, TyCtxtInferExt};
use rustc_middle::ty::util::CheckRegions;
@@ -88,8 +88,12 @@ fn ensure_drop_params_and_item_params_correspond<'tcx>(
let drop_impl_span = tcx.def_span(drop_impl_did);
let item_span = tcx.def_span(self_type_did);
let self_descr = tcx.def_descr(self_type_did);
let mut err =
struct_span_err!(tcx.dcx(), drop_impl_span, E0366, "`Drop` impls cannot be specialized");
let mut err = struct_span_code_err!(
tcx.dcx(),
drop_impl_span,
E0366,
"`Drop` impls cannot be specialized"
);
match arg {
ty::util::NotUniqueParam::DuplicateParam(arg) => {
err.note(format!("`{arg}` is mentioned multiple times"))
@@ -154,7 +158,7 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>(
let item_span = tcx.def_span(adt_def_id);
let self_descr = tcx.def_descr(adt_def_id.to_def_id());
guar = Some(
struct_span_err!(
struct_span_code_err!(
tcx.dcx(),
error.root_obligation.cause.span,
E0367,
@@ -186,7 +190,7 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>(
}
};
guar = Some(
struct_span_err!(
struct_span_code_err!(
tcx.dcx(),
error.origin().span(),
E0367,

View File

@@ -8,7 +8,7 @@ use crate::errors::{
};
use hir::def_id::DefId;
use rustc_errors::{struct_span_err, DiagnosticMessage};
use rustc_errors::{struct_span_code_err, DiagnosticMessage};
use rustc_hir as hir;
use rustc_middle::traits::{ObligationCause, ObligationCauseCode};
use rustc_middle::ty::{self, Ty, TyCtxt};
@@ -29,7 +29,7 @@ fn equate_intrinsic_type<'tcx>(
(own_counts, generics.span)
}
_ => {
struct_span_err!(tcx.dcx(), it.span, E0622, "intrinsic must be a function")
struct_span_code_err!(tcx.dcx(), it.span, E0622, "intrinsic must be a function")
.span_label_mv(it.span, "expected a function")
.emit();
return;

View File

@@ -78,7 +78,7 @@ use std::num::NonZeroU32;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_errors::ErrorGuaranteed;
use rustc_errors::{pluralize, struct_span_err, Diagnostic, DiagnosticBuilder};
use rustc_errors::{pluralize, struct_span_code_err, Diagnostic, DiagnosticBuilder};
use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::intravisit::Visitor;
use rustc_index::bit_set::BitSet;

View File

@@ -3,7 +3,9 @@ use crate::constrained_generic_params::{identify_constrained_generic_params, Par
use rustc_ast as ast;
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet};
use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder, ErrorGuaranteed};
use rustc_errors::{
pluralize, struct_span_code_err, Applicability, DiagnosticBuilder, ErrorGuaranteed,
};
use rustc_hir as hir;
use rustc_hir::def_id::{DefId, LocalDefId, LocalModDefId};
use rustc_hir::lang_items::LangItem;
@@ -217,7 +219,7 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) -> Result<()
if let hir::Defaultness::Default { .. } = impl_.defaultness {
let mut spans = vec![span];
spans.extend(impl_.defaultness_span);
res = Err(struct_span_err!(
res = Err(struct_span_code_err!(
tcx.dcx(),
spans,
E0750,
@@ -1116,7 +1118,7 @@ fn check_trait(tcx: TyCtxt<'_>, item: &hir::Item<'_>) -> Result<(), ErrorGuarant
|| matches!(trait_def.specialization_kind, TraitSpecializationKind::Marker)
{
for associated_def_id in &*tcx.associated_item_def_ids(def_id) {
struct_span_err!(
struct_span_code_err!(
tcx.dcx(),
tcx.def_span(*associated_def_id),
E0714,
@@ -1610,7 +1612,7 @@ fn check_method_receiver<'tcx>(
}
fn e0307(tcx: TyCtxt<'_>, span: Span, receiver_ty: Ty<'_>) -> ErrorGuaranteed {
struct_span_err!(tcx.dcx(), span, E0307, "invalid `self` parameter type: {receiver_ty}")
struct_span_code_err!(tcx.dcx(), span, E0307, "invalid `self` parameter type: {receiver_ty}")
.note_mv("type of `self` must be `Self` or a type that dereferences to it")
.help_mv(HELP_FOR_SELF_TYPE)
.emit()
@@ -1920,7 +1922,7 @@ fn check_mod_type_wf(tcx: TyCtxt<'_>, module: LocalModDefId) -> Result<(), Error
}
fn error_392(tcx: TyCtxt<'_>, span: Span, param_name: Symbol) -> DiagnosticBuilder<'_> {
struct_span_err!(tcx.dcx(), span, E0392, "parameter `{param_name}` is never used")
struct_span_code_err!(tcx.dcx(), span, E0392, "parameter `{param_name}` is never used")
.span_label_mv(span, "unused parameter")
}