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

@ -1,4 +1,4 @@
use rustc_errors::{struct_span_err, DiagCtxt, DiagnosticBuilder};
use rustc_errors::{struct_span_code_err, DiagCtxt, DiagnosticBuilder};
use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_span::Span;
@ -31,7 +31,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
borrow_span: Span,
borrow_desc: &str,
) -> DiagnosticBuilder<'tcx> {
struct_span_err!(
struct_span_code_err!(
self.dcx(),
span,
E0503,
@ -52,7 +52,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
old_load_end_span: Option<Span>,
) -> DiagnosticBuilder<'tcx> {
let via = |msg: &str| if msg.is_empty() { "".to_string() } else { format!(" (via {msg})") };
let mut err = struct_span_err!(
let mut err = struct_span_code_err!(
self.dcx(),
new_loan_span,
E0499,
@ -98,7 +98,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
old_loan_span: Span,
old_load_end_span: Option<Span>,
) -> DiagnosticBuilder<'tcx> {
let mut err = struct_span_err!(
let mut err = struct_span_code_err!(
self.dcx(),
new_loan_span,
E0524,
@ -131,7 +131,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
old_opt_via: &str,
previous_end_span: Option<Span>,
) -> DiagnosticBuilder<'cx> {
let mut err = struct_span_err!(
let mut err = struct_span_code_err!(
self.dcx(),
new_loan_span,
E0500,
@ -163,7 +163,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
previous_end_span: Option<Span>,
second_borrow_desc: &str,
) -> DiagnosticBuilder<'cx> {
let mut err = struct_span_err!(
let mut err = struct_span_code_err!(
self.dcx(),
new_loan_span,
E0501,
@ -196,7 +196,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
old_load_end_span: Option<Span>,
) -> DiagnosticBuilder<'cx> {
let via = |msg: &str| if msg.is_empty() { "".to_string() } else { format!(" (via {msg})") };
let mut err = struct_span_err!(
let mut err = struct_span_code_err!(
self.dcx(),
span,
E0502,
@ -236,7 +236,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
borrow_span: Span,
desc: &str,
) -> DiagnosticBuilder<'cx> {
struct_span_err!(
struct_span_code_err!(
self.dcx(),
span,
E0506,
@ -254,11 +254,11 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
is_arg: bool,
) -> DiagnosticBuilder<'cx> {
let msg = if is_arg { "to immutable argument" } else { "twice to immutable variable" };
struct_span_err!(self.dcx(), span, E0384, "cannot assign {} {}", msg, desc)
struct_span_code_err!(self.dcx(), span, E0384, "cannot assign {} {}", msg, desc)
}
pub(crate) fn cannot_assign(&self, span: Span, desc: &str) -> DiagnosticBuilder<'tcx> {
struct_span_err!(self.dcx(), span, E0594, "cannot assign to {}", desc)
struct_span_code_err!(self.dcx(), span, E0594, "cannot assign to {}", desc)
}
pub(crate) fn cannot_move_out_of(
@ -266,7 +266,13 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
move_from_span: Span,
move_from_desc: &str,
) -> DiagnosticBuilder<'cx> {
struct_span_err!(self.dcx(), move_from_span, E0507, "cannot move out of {}", move_from_desc)
struct_span_code_err!(
self.dcx(),
move_from_span,
E0507,
"cannot move out of {}",
move_from_desc
)
}
/// Signal an error due to an attempt to move out of the interior
@ -283,7 +289,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
(&ty::Slice(_), _) => "slice",
_ => span_bug!(move_from_span, "this path should not cause illegal move"),
};
struct_span_err!(
struct_span_code_err!(
self.dcx(),
move_from_span,
E0508,
@ -299,7 +305,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
move_from_span: Span,
container_ty: Ty<'_>,
) -> DiagnosticBuilder<'cx> {
struct_span_err!(
struct_span_code_err!(
self.dcx(),
move_from_span,
E0509,
@ -318,7 +324,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
) -> DiagnosticBuilder<'tcx> {
let moved_path = moved_path.map(|mp| format!(": `{mp}`")).unwrap_or_default();
struct_span_err!(
struct_span_code_err!(
self.dcx(),
use_span,
E0382,
@ -335,7 +341,14 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
path: &str,
reason: &str,
) -> DiagnosticBuilder<'tcx> {
struct_span_err!(self.dcx(), span, E0596, "cannot borrow {} as mutable{}", path, reason)
struct_span_code_err!(
self.dcx(),
span,
E0596,
"cannot borrow {} as mutable{}",
path,
reason
)
}
pub(crate) fn cannot_mutate_in_immutable_section(
@ -346,7 +359,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
immutable_section: &str,
action: &str,
) -> DiagnosticBuilder<'tcx> {
struct_span_err!(
struct_span_code_err!(
self.dcx(),
mutate_span,
E0510,
@ -365,7 +378,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
yield_span: Span,
) -> DiagnosticBuilder<'tcx> {
let coroutine_kind = self.body.coroutine.as_ref().unwrap().coroutine_kind;
struct_span_err!(
struct_span_code_err!(
self.dcx(),
span,
E0626,
@ -378,7 +391,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
&self,
borrow_span: Span,
) -> DiagnosticBuilder<'tcx> {
struct_span_err!(
struct_span_code_err!(
self.dcx(),
borrow_span,
E0713,
@ -391,7 +404,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
span: Span,
path: &str,
) -> DiagnosticBuilder<'tcx> {
struct_span_err!(self.dcx(), span, E0597, "{} does not live long enough", path,)
struct_span_code_err!(self.dcx(), span, E0597, "{} does not live long enough", path,)
}
pub(crate) fn cannot_return_reference_to_local(
@ -401,7 +414,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
reference_desc: &str,
path_desc: &str,
) -> DiagnosticBuilder<'tcx> {
struct_span_err!(
struct_span_code_err!(
self.dcx(),
span,
E0515,
@ -424,7 +437,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
capture_span: Span,
scope: &str,
) -> DiagnosticBuilder<'tcx> {
struct_span_err!(
struct_span_code_err!(
self.dcx(),
closure_span,
E0373,
@ -439,7 +452,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
&self,
span: Span,
) -> DiagnosticBuilder<'tcx> {
struct_span_err!(
struct_span_code_err!(
self.dcx(),
span,
E0712,
@ -451,7 +464,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
&self,
span: Span,
) -> DiagnosticBuilder<'tcx> {
struct_span_err!(self.dcx(), span, E0716, "temporary value dropped while borrowed",)
struct_span_code_err!(self.dcx(), span, E0716, "temporary value dropped while borrowed",)
}
}
@ -460,7 +473,7 @@ pub(crate) fn borrowed_data_escapes_closure<'tcx>(
escape_span: Span,
escapes_from: &str,
) -> DiagnosticBuilder<'tcx> {
struct_span_err!(
struct_span_code_err!(
tcx.dcx(),
escape_span,
E0521,

View File

@ -1,7 +1,9 @@
// ignore-tidy-filelength
use either::Either;
use rustc_data_structures::captures::Captures;
use rustc_data_structures::fx::FxIndexSet;
use rustc_errors::{struct_span_err, Applicability, Diagnostic, DiagnosticBuilder, MultiSpan};
use rustc_errors::{struct_span_code_err, Applicability, Diagnostic, DiagnosticBuilder, MultiSpan};
use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res};
use rustc_hir::intravisit::{walk_block, walk_expr, Visitor};
@ -550,8 +552,12 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
};
let used = desired_action.as_general_verb_in_past_tense();
let mut err =
struct_span_err!(self.dcx(), span, E0381, "{used} binding {desc}{isnt_initialized}");
let mut err = struct_span_code_err!(
self.dcx(),
span,
E0381,
"{used} binding {desc}{isnt_initialized}"
);
use_spans.var_path_only_subdiag(&mut err, desired_action);
if let InitializationRequiringAction::PartialAssignment

View File

@ -1,6 +1,6 @@
use rustc_ast::{ast, attr, MetaItemKind, NestedMetaItem};
use rustc_attr::{list_contains_name, InlineAttr, InstructionSetAttr, OptimizeAttr};
use rustc_errors::struct_span_err;
use rustc_errors::struct_span_code_err;
use rustc_hir as hir;
use rustc_hir::def::DefKind;
use rustc_hir::def_id::{DefId, LocalDefId, LOCAL_CRATE};
@ -216,7 +216,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
if let Some(fn_sig) = fn_sig()
&& !matches!(fn_sig.skip_binder().abi(), abi::Abi::C { .. })
{
struct_span_err!(
struct_span_code_err!(
tcx.dcx(),
attr.span,
E0776,
@ -225,7 +225,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
.emit();
}
if !tcx.sess.target.llvm_target.contains("thumbv8m") {
struct_span_err!(tcx.dcx(), attr.span, E0775, "`#[cmse_nonsecure_entry]` is only valid for targets with the TrustZone-M extension")
struct_span_code_err!(tcx.dcx(), attr.span, E0775, "`#[cmse_nonsecure_entry]` is only valid for targets with the TrustZone-M extension")
.emit();
}
codegen_fn_attrs.flags |= CodegenFnAttrFlags::CMSE_NONSECURE_ENTRY
@ -238,7 +238,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
&& let Some(fn_sig) = fn_sig()
&& fn_sig.skip_binder().abi() != abi::Abi::Rust
{
struct_span_err!(
struct_span_code_err!(
tcx.dcx(),
attr.span,
E0737,
@ -265,7 +265,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
if s.as_str().contains('\0') {
// `#[export_name = ...]` will be converted to a null-terminated string,
// so it may not contain any null characters.
struct_span_err!(
struct_span_code_err!(
tcx.dcx(),
attr.span,
E0648,
@ -385,7 +385,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
match segments.as_slice() {
[sym::arm, sym::a32] | [sym::arm, sym::t32] => {
if !tcx.sess.target.has_thumb_interworking {
struct_span_err!(
struct_span_code_err!(
tcx.dcx(),
attr.span,
E0779,
@ -402,7 +402,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
}
}
_ => {
struct_span_err!(
struct_span_code_err!(
tcx.dcx(),
attr.span,
E0779,
@ -414,7 +414,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
}
}
[] => {
struct_span_err!(
struct_span_code_err!(
tcx.dcx(),
attr.span,
E0778,
@ -424,7 +424,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
None
}
_ => {
struct_span_err!(
struct_span_code_err!(
tcx.dcx(),
attr.span,
E0779,
@ -442,7 +442,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
{
rustc_attr::parse_alignment(&literal.kind)
.map_err(|msg| {
struct_span_err!(
struct_span_code_err!(
tcx.dcx(),
attr.span,
E0589,
@ -469,14 +469,15 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
Some(MetaItemKind::List(ref items)) => {
inline_span = Some(attr.span);
if items.len() != 1 {
struct_span_err!(tcx.dcx(), attr.span, E0534, "expected one argument").emit();
struct_span_code_err!(tcx.dcx(), attr.span, E0534, "expected one argument")
.emit();
InlineAttr::None
} else if list_contains_name(items, sym::always) {
InlineAttr::Always
} else if list_contains_name(items, sym::never) {
InlineAttr::Never
} else {
struct_span_err!(tcx.dcx(), items[0].span(), E0535, "invalid argument")
struct_span_code_err!(tcx.dcx(), items[0].span(), E0535, "invalid argument")
.help_mv("valid inline arguments are `always` and `never`")
.emit();
@ -492,7 +493,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
if !attr.has_name(sym::optimize) {
return ia;
}
let err = |sp, s| struct_span_err!(tcx.dcx(), sp, E0722, "{}", s).emit();
let err = |sp, s| struct_span_code_err!(tcx.dcx(), sp, E0722, "{}", s).emit();
match attr.meta_kind() {
Some(MetaItemKind::Word) => {
err(attr.span, "expected one argument");

View File

@ -453,7 +453,7 @@ impl<G: EmissionGuarantee> Drop for DiagnosticBuilder<'_, G> {
}
#[macro_export]
macro_rules! struct_span_err {
macro_rules! struct_span_code_err {
($dcx:expr, $span:expr, $code:ident, $($message:tt)*) => ({
$dcx.struct_span_err(
$span,

View File

@ -1,5 +1,5 @@
use rustc_data_structures::fx::FxHashMap;
use rustc_errors::struct_span_err;
use rustc_errors::struct_span_code_err;
use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res};
use rustc_hir::def_id::{DefId, LocalDefId};
@ -462,7 +462,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
late_bound_in_trait_ref,
late_bound_in_ty,
|br_name| {
struct_span_err!(
struct_span_code_err!(
tcx.dcx(),
binding.span,
E0582,

View File

@ -7,7 +7,7 @@ use crate::fluent_generated as fluent;
use crate::traits::error_reporting::report_object_safety_error;
use rustc_data_structures::fx::{FxHashMap, FxIndexMap, FxIndexSet};
use rustc_data_structures::unord::UnordMap;
use rustc_errors::{pluralize, struct_span_err, Applicability, Diagnostic, ErrorGuaranteed};
use rustc_errors::{pluralize, struct_span_code_err, Applicability, Diagnostic, ErrorGuaranteed};
use rustc_hir as hir;
use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_infer::traits::FulfillmentError;
@ -346,7 +346,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
candidates: Vec<DefId>,
span: Span,
) -> ErrorGuaranteed {
let mut err = struct_span_err!(
let mut err = struct_span_code_err!(
self.tcx().dcx(),
name.span,
E0034,
@ -445,7 +445,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
String::new()
};
let mut err = struct_span_err!(
let mut err = struct_span_code_err!(
tcx.dcx(),
name.span,
E0220,
@ -697,7 +697,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
let names = names.join(", ");
trait_bound_spans.sort();
let mut err = struct_span_err!(
let mut err = struct_span_code_err!(
tcx.dcx(),
trait_bound_spans,
E0191,

View File

@ -5,7 +5,7 @@ use crate::astconv::{
};
use crate::structured_errors::{GenericArgsInfo, StructuredDiagnostic, WrongNumberOfGenericArgs};
use rustc_ast::ast::ParamKindOrd;
use rustc_errors::{struct_span_err, Applicability, Diagnostic, ErrorGuaranteed, MultiSpan};
use rustc_errors::{struct_span_code_err, Applicability, Diagnostic, ErrorGuaranteed, MultiSpan};
use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res};
use rustc_hir::def_id::DefId;
@ -27,7 +27,7 @@ fn generic_arg_mismatch_err(
help: Option<String>,
) -> ErrorGuaranteed {
let sess = tcx.sess;
let mut err = struct_span_err!(
let mut err = struct_span_code_err!(
tcx.dcx(),
arg.span(),
E0747,
@ -650,7 +650,7 @@ pub(crate) fn prohibit_explicit_late_bound_lifetimes(
if position == GenericArgPosition::Value
&& args.num_lifetime_params() != param_counts.lifetimes
{
struct_span_err!(tcx.dcx(), span, E0794, "{}", msg)
struct_span_code_err!(tcx.dcx(), span, E0794, "{}", msg)
.span_note_mv(span_late, note)
.emit();
} else {

View File

@ -213,7 +213,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
let msg = "trait objects must include the `dyn` keyword";
let label = "add `dyn` keyword before this trait";
let mut diag =
rustc_errors::struct_span_err!(tcx.dcx(), self_ty.span, E0782, "{}", msg);
rustc_errors::struct_span_code_err!(tcx.dcx(), self_ty.span, E0782, "{}", msg);
if self_ty.span.can_be_used_for_suggestions()
&& !self.maybe_lint_impl_trait(self_ty, &mut diag)
{

View File

@ -18,8 +18,8 @@ use crate::require_c_abi_if_c_variadic;
use rustc_ast::TraitObjectSyntax;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_errors::{
error_code, struct_span_err, Applicability, Diagnostic, DiagnosticBuilder, ErrorGuaranteed,
FatalError, MultiSpan,
error_code, struct_span_code_err, Applicability, Diagnostic, DiagnosticBuilder,
ErrorGuaranteed, FatalError, MultiSpan,
};
use rustc_hir as hir;
use rustc_hir::def::{CtorOf, DefKind, Namespace, Res};
@ -866,7 +866,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
traits: &[String],
name: Symbol,
) -> ErrorGuaranteed {
let mut err = struct_span_err!(self.tcx().dcx(), span, E0223, "ambiguous associated type");
let mut err =
struct_span_code_err!(self.tcx().dcx(), span, E0223, "ambiguous associated type");
if self
.tcx()
.resolutions(())
@ -1313,7 +1314,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
let msg = format!("expected type, found variant `{assoc_ident}`");
tcx.dcx().span_err(span, msg)
} else if qself_ty.is_enum() {
let mut err = struct_span_err!(
let mut err = struct_span_code_err!(
tcx.dcx(),
assoc_ident.span,
E0599,
@ -1354,7 +1355,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
reported
} else if let ty::Alias(ty::Opaque, alias_ty) = qself_ty.kind() {
// `<impl Trait as OtherTrait>::Assoc` makes no sense.
struct_span_err!(
struct_span_code_err!(
tcx.dcx(),
tcx.def_span(alias_ty.def_id),
E0667,
@ -1850,7 +1851,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
};
let last_span = *arg_spans.last().unwrap();
let span: MultiSpan = arg_spans.into();
let mut err = struct_span_err!(
let mut err = struct_span_code_err!(
self.tcx().dcx(),
span,
E0109,
@ -2601,7 +2602,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
let late_bound_in_ret = tcx.collect_referenced_late_bound_regions(&output);
self.validate_late_bound_regions(late_bound_in_args, late_bound_in_ret, |br_name| {
struct_span_err!(
struct_span_code_err!(
tcx.dcx(),
decl.output.span(),
E0581,

View File

@ -2,7 +2,7 @@ use crate::astconv::{GenericArgCountMismatch, GenericArgCountResult, OnlySelfBou
use crate::bounds::Bounds;
use crate::errors::TraitObjectDeclaredWithNoTraits;
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
use rustc_errors::struct_span_err;
use rustc_errors::struct_span_code_err;
use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res};
use rustc_hir::def_id::DefId;
@ -89,7 +89,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
if regular_traits.len() > 1 {
let first_trait = &regular_traits[0];
let additional_trait = &regular_traits[1];
let mut err = struct_span_err!(
let mut err = struct_span_code_err!(
tcx.dcx(),
additional_trait.bottom().1,
E0225,
@ -290,7 +290,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
if references_self {
let def_id = i.bottom().0.def_id();
struct_span_err!(
struct_span_code_err!(
tcx.dcx(),
i.bottom().1,
E0038,
@ -375,7 +375,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
self.ast_region_to_region(lifetime, None)
} else {
self.re_infer(None, span).unwrap_or_else(|| {
let err = struct_span_err!(
let err = struct_span_code_err!(
tcx.dcx(),
span,
E0228,

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")
}

View File

@ -1,5 +1,5 @@
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_errors::struct_span_err;
use rustc_errors::struct_span_code_err;
use rustc_hir as hir;
use rustc_hir::def::DefKind;
use rustc_hir::def_id::DefId;
@ -70,7 +70,7 @@ impl<'tcx> InherentOverlapChecker<'tcx> {
match seen_items.entry(norm_ident) {
Entry::Occupied(entry) => {
let former = entry.get();
struct_span_err!(
struct_span_code_err!(
self.tcx.dcx(),
span,
E0592,
@ -104,7 +104,7 @@ impl<'tcx> InherentOverlapChecker<'tcx> {
if let Some(item2) = collision {
let name = item1.ident(self.tcx).normalize_to_macros_2_0();
let mut err = struct_span_err!(
let mut err = struct_span_code_err!(
self.tcx.dcx(),
self.tcx.def_span(item1.def_id),
E0592,

View File

@ -6,7 +6,7 @@
// mappings. That mapping code resides here.
use crate::errors;
use rustc_errors::{error_code, struct_span_err};
use rustc_errors::{error_code, struct_span_code_err};
use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_middle::query::Providers;
use rustc_middle::ty::{self, TyCtxt, TypeVisitableExt};
@ -45,7 +45,7 @@ fn enforce_trait_manually_implementable(
// Disallow *all* explicit impls of traits marked `#[rustc_deny_explicit_impl]`
if tcx.trait_def(trait_def_id).deny_explicit_impl {
let trait_name = tcx.item_name(trait_def_id);
let mut err = struct_span_err!(
let mut err = struct_span_code_err!(
tcx.dcx(),
impl_header_span,
E0322,
@ -88,7 +88,7 @@ fn enforce_empty_impls_for_marker_traits(
return;
}
struct_span_err!(
struct_span_code_err!(
tcx.dcx(),
tcx.def_span(impl_def_id),
E0715,
@ -173,7 +173,7 @@ fn check_object_overlap<'tcx>(
let mut supertrait_def_ids = traits::supertrait_def_ids(tcx, component_def_id);
if supertrait_def_ids.any(|d| d == trait_def_id) {
let span = tcx.def_span(impl_def_id);
struct_span_err!(
struct_span_code_err!(
tcx.dcx(),
span,
E0371,

View File

@ -1,7 +1,7 @@
//! Unsafety checker: every impl either implements a trait defined in this
//! crate or pertains to a type defined in this crate.
use rustc_errors::struct_span_err;
use rustc_errors::struct_span_code_err;
use rustc_hir as hir;
use rustc_hir::Unsafety;
use rustc_middle::ty::TyCtxt;
@ -18,7 +18,7 @@ pub(super) fn check_item(tcx: TyCtxt<'_>, def_id: LocalDefId) {
impl_.generics.params.iter().find(|p| p.pure_wrt_drop).map(|_| "may_dangle");
match (trait_def.unsafety, unsafe_attr, impl_.unsafety, impl_.polarity) {
(Unsafety::Normal, None, Unsafety::Unsafe, hir::ImplPolarity::Positive) => {
struct_span_err!(
struct_span_code_err!(
tcx.dcx(),
tcx.def_span(def_id),
E0199,
@ -35,7 +35,7 @@ pub(super) fn check_item(tcx: TyCtxt<'_>, def_id: LocalDefId) {
}
(Unsafety::Unsafe, _, Unsafety::Normal, hir::ImplPolarity::Positive) => {
struct_span_err!(
struct_span_code_err!(
tcx.dcx(),
tcx.def_span(def_id),
E0200,
@ -58,7 +58,7 @@ pub(super) fn check_item(tcx: TyCtxt<'_>, def_id: LocalDefId) {
}
(Unsafety::Normal, Some(attr_name), Unsafety::Normal, hir::ImplPolarity::Positive) => {
struct_span_err!(
struct_span_code_err!(
tcx.dcx(),
tcx.def_span(def_id),
E0569,

View File

@ -8,7 +8,7 @@
use rustc_ast::walk_list;
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
use rustc_errors::struct_span_err;
use rustc_errors::struct_span_code_err;
use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res};
use rustc_hir::def_id::LocalDefId;
@ -737,7 +737,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
// Ensure that the parent of the def is an item, not HRTB
let parent_id = self.tcx.hir().parent_id(hir_id);
if !parent_id.is_owner() {
struct_span_err!(
struct_span_code_err!(
self.tcx.dcx(),
lifetime.ident.span,
E0657,

View File

@ -12,7 +12,7 @@ use crate::constrained_generic_params as cgp;
use min_specialization::check_min_specialization;
use rustc_data_structures::fx::FxHashSet;
use rustc_errors::struct_span_err;
use rustc_errors::struct_span_code_err;
use rustc_hir::def::DefKind;
use rustc_hir::def_id::{LocalDefId, LocalModDefId};
use rustc_middle::query::Providers;
@ -170,7 +170,7 @@ fn enforce_impl_params_are_constrained(tcx: TyCtxt<'_>, impl_def_id: LocalDefId)
}
fn report_unused_parameter(tcx: TyCtxt<'_>, span: Span, kind: &str, name: Symbol) {
let mut err = struct_span_err!(
let mut err = struct_span_code_err!(
tcx.dcx(),
span,
E0207,

View File

@ -36,7 +36,7 @@
//! ```
use crate::FnCtxt;
use rustc_errors::{struct_span_err, Applicability, Diagnostic, DiagnosticBuilder, MultiSpan};
use rustc_errors::{struct_span_code_err, Applicability, Diagnostic, DiagnosticBuilder, MultiSpan};
use rustc_hir as hir;
use rustc_hir::def_id::DefId;
use rustc_hir::intravisit::{self, Visitor};
@ -1571,7 +1571,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
let mut visitor = CollectRetsVisitor { ret_exprs: vec![] };
match *cause.code() {
ObligationCauseCode::ReturnNoExpression => {
err = struct_span_err!(
err = struct_span_code_err!(
fcx.dcx(),
cause.span,
E0069,

View File

@ -25,7 +25,7 @@ use rustc_ast as ast;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::stack::ensure_sufficient_stack;
use rustc_errors::{
pluralize, struct_span_err, AddToDiagnostic, Applicability, Diagnostic, DiagnosticBuilder,
pluralize, struct_span_code_err, AddToDiagnostic, Applicability, Diagnostic, DiagnosticBuilder,
DiagnosticId, ErrorGuaranteed, StashKey,
};
use rustc_hir as hir;
@ -1760,7 +1760,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// Make sure the programmer specified correct number of fields.
if adt_kind == AdtKind::Union {
if ast_fields.len() != 1 {
struct_span_err!(
struct_span_code_err!(
tcx.dcx(),
span,
E0784,
@ -1967,7 +1967,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
};
let mut err = struct_span_err!(
let mut err = struct_span_code_err!(
self.dcx(),
span,
E0063,
@ -2194,7 +2194,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let mut err = self.err_ctxt().type_error_struct_with_diag(
field.ident.span,
|actual| match ty.kind() {
ty::Adt(adt, ..) if adt.is_enum() => struct_span_err!(
ty::Adt(adt, ..) if adt.is_enum() => struct_span_code_err!(
self.dcx(),
field.ident.span,
E0559,
@ -2204,7 +2204,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
variant.name,
field.ident
),
_ => struct_span_err!(
_ => struct_span_code_err!(
self.dcx(),
field.ident.span,
E0560,
@ -2832,7 +2832,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
fn private_field_err(&self, field: Ident, base_did: DefId) -> DiagnosticBuilder<'_> {
let struct_path = self.tcx().def_path_str(base_did);
let kind_name = self.tcx().def_descr(base_did);
struct_span_err!(
struct_span_code_err!(
self.dcx(),
field.span,
E0616,

View File

@ -6,7 +6,8 @@ use crate::method::MethodCallee;
use crate::TupleArgumentsFlag::*;
use crate::{errors, Expectation::*};
use crate::{
struct_span_err, BreakableCtxt, Diverges, Expectation, FnCtxt, Needs, RawTy, TupleArgumentsFlag,
struct_span_code_err, BreakableCtxt, Diverges, Expectation, FnCtxt, Needs, RawTy,
TupleArgumentsFlag,
};
use rustc_ast as ast;
use rustc_data_structures::fx::FxIndexSet;
@ -204,7 +205,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
_ => {
// Otherwise, there's a mismatch, so clear out what we're expecting, and set
// our input types to err_args so we don't blow up the error messages
struct_span_err!(
struct_span_code_err!(
tcx.dcx(),
call_span,
E0059,
@ -807,7 +808,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
let mut err = if formal_and_expected_inputs.len() == provided_args.len() {
struct_span_err!(
struct_span_code_err!(
tcx.dcx(),
full_call_span,
E0308,
@ -1378,7 +1379,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// (issue #88844).
guar
}
_ => struct_span_err!(
_ => struct_span_code_err!(
self.dcx(),
path_span,
E0071,

View File

@ -1,5 +1,5 @@
use hir::HirId;
use rustc_errors::struct_span_err;
use rustc_errors::struct_span_code_err;
use rustc_hir as hir;
use rustc_index::Idx;
use rustc_middle::ty::layout::{LayoutError, SizeSkeleton};
@ -73,7 +73,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if let (&ty::FnDef(..), SizeSkeleton::Known(size_to)) = (from.kind(), sk_to)
&& size_to == Pointer(dl.instruction_address_space).size(&tcx)
{
struct_span_err!(tcx.dcx(), span, E0591, "can't transmute zero-sized type")
struct_span_code_err!(tcx.dcx(), span, E0591, "can't transmute zero-sized type")
.note_mv(format!("source type: {from}"))
.note_mv(format!("target type: {to}"))
.help_mv("cast with `as` to a pointer instead")
@ -112,7 +112,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
Err(err) => err.to_string(),
};
let mut err = struct_span_err!(
let mut err = struct_span_code_err!(
tcx.dcx(),
span,
E0512,

View File

@ -52,7 +52,7 @@ use crate::expectation::Expectation;
use crate::fn_ctxt::RawTy;
use crate::gather_locals::GatherLocalsVisitor;
use rustc_data_structures::unord::UnordSet;
use rustc_errors::{struct_span_err, DiagnosticId, ErrorGuaranteed};
use rustc_errors::{struct_span_code_err, DiagnosticId, ErrorGuaranteed};
use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res};
use rustc_hir::intravisit::Visitor;
@ -72,7 +72,7 @@ rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
#[macro_export]
macro_rules! type_error_struct {
($dcx:expr, $span:expr, $typ:expr, $code:ident, $($message:tt)*) => ({
let mut err = rustc_errors::struct_span_err!($dcx, $span, $code, $($message)*);
let mut err = rustc_errors::struct_span_code_err!($dcx, $span, $code, $($message)*);
if $typ.references_error() {
err.downgrade_to_delayed_bug();

View File

@ -13,7 +13,7 @@ use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
use rustc_data_structures::unord::UnordSet;
use rustc_errors::StashKey;
use rustc_errors::{
pluralize, struct_span_err, Applicability, Diagnostic, DiagnosticBuilder, MultiSpan,
pluralize, struct_span_code_err, Applicability, Diagnostic, DiagnosticBuilder, MultiSpan,
};
use rustc_hir as hir;
use rustc_hir::def::DefKind;
@ -148,7 +148,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
MethodError::Ambiguity(mut sources) => {
let mut err = struct_span_err!(
let mut err = struct_span_code_err!(
self.dcx(),
item_name.span,
E0034,
@ -171,7 +171,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
MethodError::PrivateMatch(kind, def_id, out_of_scope_traits) => {
let kind = self.tcx.def_kind_descr(kind, def_id);
let mut err = struct_span_err!(
let mut err = struct_span_code_err!(
self.dcx(),
item_name.span,
E0624,
@ -263,8 +263,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
) -> DiagnosticBuilder<'_> {
let mut file = None;
let ty_str = self.tcx.short_ty_string(rcvr_ty, &mut file);
let mut err =
struct_span_err!(self.dcx(), rcvr_expr.span, E0599, "cannot write into `{}`", ty_str);
let mut err = struct_span_code_err!(
self.dcx(),
rcvr_expr.span,
E0599,
"cannot write into `{}`",
ty_str
);
err.span_note(
rcvr_expr.span,
"must implement `io::Write`, `fmt::Write`, or have a `write_fmt` method",
@ -1836,7 +1841,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
&& !actual.has_concrete_skeleton()
&& let SelfSource::MethodCall(expr) = source
{
let mut err = struct_span_err!(
let mut err = struct_span_code_err!(
tcx.dcx(),
span,
E0689,

View File

@ -4,7 +4,7 @@ use super::method::MethodCallee;
use super::{has_expected_num_generic_args, FnCtxt};
use crate::Expectation;
use rustc_ast as ast;
use rustc_errors::{struct_span_err, Applicability, Diagnostic, DiagnosticBuilder};
use rustc_errors::{struct_span_code_err, Applicability, Diagnostic, DiagnosticBuilder};
use rustc_hir as hir;
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
use rustc_infer::traits::ObligationCauseCode;
@ -306,7 +306,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
.map(|def_id| with_no_trimmed_paths!(self.tcx.def_path_str(def_id)));
let (mut err, output_def_id) = match is_assign {
IsAssign::Yes => {
let mut err = struct_span_err!(
let mut err = struct_span_code_err!(
self.dcx(),
expr.span,
E0368,
@ -370,7 +370,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
})
.cloned()
});
let mut err = struct_span_err!(self.dcx(), op.span, E0369, "{message}");
let mut err =
struct_span_code_err!(self.dcx(), op.span, E0369, "{message}");
if !lhs_expr.span.eq(&rhs_expr.span) {
err.span_label(lhs_expr.span, lhs_ty.to_string());
err.span_label(rhs_expr.span, rhs_ty.to_string());
@ -788,7 +789,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
Err(errors) => {
let actual = self.resolve_vars_if_possible(operand_ty);
let guar = actual.error_reported().err().unwrap_or_else(|| {
let mut err = struct_span_err!(
let mut err = struct_span_code_err!(
self.dcx(),
ex.span,
E0600,

View File

@ -3,7 +3,7 @@ use crate::{errors, FnCtxt, RawTy};
use rustc_ast as ast;
use rustc_data_structures::fx::FxHashMap;
use rustc_errors::{
pluralize, struct_span_err, Applicability, Diagnostic, DiagnosticBuilder, ErrorGuaranteed,
pluralize, struct_span_code_err, Applicability, Diagnostic, DiagnosticBuilder, ErrorGuaranteed,
MultiSpan,
};
use rustc_hir as hir;
@ -546,7 +546,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
(_, Some((true, _, sp))) => sp,
_ => span_bug!(span, "emit_err_pat_range: no side failed or exists but still error?"),
};
let mut err = struct_span_err!(
let mut err = struct_span_code_err!(
self.dcx(),
span,
E0029,
@ -837,7 +837,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// This is "x = SomeTrait" being reduced from
// "let &x = &SomeTrait" or "let box x = Box<SomeTrait>", an error.
let type_str = self.ty_to_string(expected);
let mut err = struct_span_err!(
let mut err = struct_span_code_err!(
self.dcx(),
span,
E0033,
@ -1171,7 +1171,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
};
let last_field_def_span = *field_def_spans.last().unwrap();
let mut err = struct_span_err!(
let mut err = struct_span_code_err!(
self.dcx(),
MultiSpan::from_spans(subpat_spans),
E0023,
@ -1516,7 +1516,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let has_shorthand_field_name = field_patterns.iter().any(|field| field.is_shorthand);
if has_shorthand_field_name {
let path = rustc_hir_pretty::qpath_to_string(qpath);
let mut err = struct_span_err!(
let mut err = struct_span_code_err!(
self.dcx(),
pat.span,
E0769,
@ -1541,7 +1541,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let sp_comma = sm.end_point(pat.span.with_hi(sp_brace.hi()));
let sugg = if no_fields || sp_brace != sp_comma { ".. }" } else { ", .. }" };
struct_span_err!(
struct_span_code_err!(
self.dcx(),
pat.span,
E0638,
@ -1562,7 +1562,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
ident: Ident,
other_field: Span,
) -> ErrorGuaranteed {
struct_span_err!(
struct_span_code_err!(
self.dcx(),
span,
E0025,
@ -1601,7 +1601,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
)
};
let spans = inexistent_fields.iter().map(|field| field.ident.span).collect::<Vec<_>>();
let mut err = struct_span_err!(
let mut err = struct_span_code_err!(
tcx.dcx(),
spans,
E0026,
@ -1698,7 +1698,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
let path = rustc_hir_pretty::qpath_to_string(qpath);
let mut err = struct_span_err!(
let mut err = struct_span_code_err!(
self.dcx(),
pat.span,
E0769,
@ -1876,7 +1876,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
.join(", ");
format!("fields {fields}{inaccessible}")
};
let mut err = struct_span_err!(
let mut err = struct_span_code_err!(
self.dcx(),
pat.span,
E0027,
@ -2226,7 +2226,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
min_len: u64,
size: u64,
) -> ErrorGuaranteed {
struct_span_err!(
struct_span_code_err!(
self.dcx(),
span,
E0527,
@ -2245,7 +2245,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
min_len: u64,
size: u64,
) -> ErrorGuaranteed {
struct_span_err!(
struct_span_code_err!(
self.dcx(),
span,
E0528,
@ -2262,7 +2262,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
fn error_scrutinee_unfixed_length(&self, span: Span) -> ErrorGuaranteed {
struct_span_err!(
struct_span_code_err!(
self.dcx(),
span,
E0730,
@ -2277,7 +2277,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
expected_ty: Ty<'tcx>,
ti: TopInfo<'tcx>,
) -> ErrorGuaranteed {
let mut err = struct_span_err!(
let mut err = struct_span_code_err!(
self.dcx(),
span,
E0529,

View File

@ -60,8 +60,8 @@ use crate::traits::{
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
use rustc_errors::{
error_code, pluralize, struct_span_err, Applicability, DiagCtxt, Diagnostic, DiagnosticBuilder,
DiagnosticStyledString, ErrorGuaranteed, IntoDiagnosticArg,
error_code, pluralize, struct_span_code_err, Applicability, DiagCtxt, Diagnostic,
DiagnosticBuilder, DiagnosticStyledString, ErrorGuaranteed, IntoDiagnosticArg,
};
use rustc_hir as hir;
use rustc_hir::def::DefKind;
@ -2780,7 +2780,7 @@ impl<'tcx> InferCtxt<'tcx> {
infer::Nll(..) => bug!("NLL variable found in lexical phase"),
};
struct_span_err!(
struct_span_code_err!(
self.tcx.dcx(),
var_origin.span(),
E0495,

View File

@ -2,7 +2,7 @@ use super::ObjectSafetyViolation;
use crate::infer::InferCtxt;
use rustc_data_structures::fx::FxIndexSet;
use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder, MultiSpan};
use rustc_errors::{struct_span_code_err, Applicability, DiagnosticBuilder, MultiSpan};
use rustc_hir as hir;
use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::intravisit::Map;
@ -20,7 +20,7 @@ impl<'tcx> InferCtxt<'tcx> {
trait_item_def_id: DefId,
requirement: &dyn fmt::Display,
) -> DiagnosticBuilder<'tcx> {
let mut err = struct_span_err!(
let mut err = struct_span_code_err!(
self.tcx.dcx(),
error_span,
E0276,
@ -52,7 +52,7 @@ pub fn report_object_safety_error<'tcx>(
hir::Node::Item(item) => Some(item.ident.span),
_ => None,
});
let mut err = struct_span_err!(
let mut err = struct_span_code_err!(
tcx.dcx(),
span,
E0038,

View File

@ -1,7 +1,7 @@
use crate::dep_graph::dep_kinds;
use crate::query::plumbing::CyclePlaceholder;
use rustc_data_structures::fx::FxHashSet;
use rustc_errors::{pluralize, struct_span_err, Applicability, MultiSpan};
use rustc_errors::{pluralize, struct_span_code_err, Applicability, MultiSpan};
use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res};
use rustc_middle::ty::Representability;
@ -175,7 +175,7 @@ impl<'tcx, T> Value<TyCtxt<'tcx>> for Result<T, &'_ ty::layout::LayoutError<'_>>
} else {
tcx.def_span(def_id)
};
let mut diag = struct_span_err!(
let mut diag = struct_span_code_err!(
tcx.sess.dcx(),
span,
E0733,
@ -309,7 +309,7 @@ pub fn recursive_type_error(
}
s
};
struct_span_err!(
struct_span_code_err!(
tcx.dcx(),
err_span,
E0072,

View File

@ -11,7 +11,9 @@ use rustc_arena::{DroplessArena, TypedArena};
use rustc_ast::Mutability;
use rustc_data_structures::fx::FxIndexSet;
use rustc_data_structures::stack::ensure_sufficient_stack;
use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder, ErrorGuaranteed, MultiSpan};
use rustc_errors::{
struct_span_code_err, Applicability, DiagnosticBuilder, ErrorGuaranteed, MultiSpan,
};
use rustc_hir as hir;
use rustc_hir::def::*;
use rustc_hir::def_id::LocalDefId;
@ -55,7 +57,7 @@ pub(crate) fn check_match(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(), Err
}
fn create_e0004(sess: &Session, sp: Span, error_message: String) -> DiagnosticBuilder<'_> {
struct_span_err!(sess.dcx(), sp, E0004, "{}", &error_message)
struct_span_code_err!(sess.dcx(), sp, E0004, "{}", &error_message)
}
#[derive(Debug, Copy, Clone, PartialEq)]

View File

@ -10,7 +10,7 @@ use rustc_ast::tokenstream::{DelimSpan, TokenStream, TokenTree};
use rustc_ast::util::case::Case;
use rustc_ast::{self as ast};
use rustc_ast_pretty::pprust;
use rustc_errors::{struct_span_err, Applicability, PResult, StashKey};
use rustc_errors::{struct_span_code_err, Applicability, PResult, StashKey};
use rustc_span::edit_distance::edit_distance;
use rustc_span::edition::Edition;
use rustc_span::source_map;
@ -759,7 +759,7 @@ impl<'a> Parser<'a> {
if let token::DocComment(..) = self.token.kind {
if self.look_ahead(1, |tok| tok == &token::CloseDelim(Delimiter::Brace)) {
// FIXME: merge with `DocCommentDoesNotDocumentAnything` (E0585)
struct_span_err!(
struct_span_code_err!(
self.dcx(),
self.token.span,
E0584,

View File

@ -19,7 +19,7 @@ use rustc_ast::{self as ast, AssocItem, AssocItemKind, MetaItemKind, StmtKind};
use rustc_ast::{Block, Fn, ForeignItem, ForeignItemKind, Impl, Item, ItemKind, NodeId};
use rustc_attr as attr;
use rustc_data_structures::sync::Lrc;
use rustc_errors::{struct_span_err, Applicability};
use rustc_errors::{struct_span_code_err, Applicability};
use rustc_expand::expand::AstFragment;
use rustc_hir::def::{self, *};
use rustc_hir::def_id::{DefId, LocalDefId, CRATE_DEF_ID};
@ -1010,7 +1010,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
for attr in &item.attrs {
if attr.has_name(sym::macro_use) {
if self.parent_scope.module.parent.is_some() {
struct_span_err!(
struct_span_code_err!(
self.r.dcx(),
item.span,
E0468,
@ -1024,7 +1024,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
}
}
let ill_formed = |span| {
struct_span_err!(self.r.dcx(), span, E0466, "bad macro import").emit();
struct_span_code_err!(self.r.dcx(), span, E0466, "bad macro import").emit();
};
match attr.meta() {
Some(meta) => match meta.kind {
@ -1095,8 +1095,13 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
allow_shadowing,
);
} else {
struct_span_err!(self.r.dcx(), ident.span, E0469, "imported macro not found")
.emit();
struct_span_code_err!(
self.r.dcx(),
ident.span,
E0469,
"imported macro not found"
)
.emit();
}
}
}

View File

@ -6,7 +6,7 @@ use rustc_ast::{MetaItemKind, NestedMetaItem};
use rustc_ast_pretty::pprust;
use rustc_data_structures::fx::FxHashSet;
use rustc_errors::{
pluralize, report_ambiguity_error, struct_span_err, Applicability, DiagCtxt, Diagnostic,
pluralize, report_ambiguity_error, struct_span_code_err, Applicability, DiagCtxt, Diagnostic,
DiagnosticBuilder, ErrorGuaranteed, MultiSpan, SuggestionStyle,
};
use rustc_feature::BUILTIN_ATTRIBUTES;
@ -153,7 +153,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
BuiltinLintDiagnostics::AmbiguousGlobImports { diag },
);
} else {
let mut err = struct_span_err!(self.dcx(), diag.span, E0659, "{}", &diag.msg);
let mut err = struct_span_code_err!(self.dcx(), diag.span, E0659, "{}", &diag.msg);
report_ambiguity_error(&mut err, diag);
err.emit();
}
@ -254,15 +254,15 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
let msg = format!("the name `{name}` is defined multiple times");
let mut err = match (old_binding.is_extern_crate(), new_binding.is_extern_crate()) {
(true, true) => struct_span_err!(self.dcx(), span, E0259, "{}", msg),
(true, true) => struct_span_code_err!(self.dcx(), span, E0259, "{}", msg),
(true, _) | (_, true) => match new_binding.is_import() && old_binding.is_import() {
true => struct_span_err!(self.dcx(), span, E0254, "{}", msg),
false => struct_span_err!(self.dcx(), span, E0260, "{}", msg),
true => struct_span_code_err!(self.dcx(), span, E0254, "{}", msg),
false => struct_span_code_err!(self.dcx(), span, E0260, "{}", msg),
},
_ => match (old_binding.is_import_user_facing(), new_binding.is_import_user_facing()) {
(false, false) => struct_span_err!(self.dcx(), span, E0428, "{}", msg),
(true, true) => struct_span_err!(self.dcx(), span, E0252, "{}", msg),
_ => struct_span_err!(self.dcx(), span, E0255, "{}", msg),
(false, false) => struct_span_code_err!(self.dcx(), span, E0428, "{}", msg),
(true, true) => struct_span_code_err!(self.dcx(), span, E0252, "{}", msg),
_ => struct_span_code_err!(self.dcx(), span, E0255, "{}", msg),
},
};
@ -659,7 +659,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
let origin_sp = origin.iter().copied().collect::<Vec<_>>();
let msp = MultiSpan::from_spans(target_sp.clone());
let mut err = struct_span_err!(
let mut err = struct_span_code_err!(
self.dcx(),
msp,
E0408,
@ -788,7 +788,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
}
ResolutionError::FailedToResolve { last_segment, label, suggestion, module } => {
let mut err =
struct_span_err!(self.dcx(), span, E0433, "failed to resolve: {}", &label);
struct_span_code_err!(self.dcx(), span, E0433, "failed to resolve: {}", &label);
err.span_label(span, label);
if let Some((suggestions, msg, applicability)) = suggestion {
@ -1702,8 +1702,14 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
// Print the primary message.
let descr = get_descr(binding);
let mut err =
struct_span_err!(self.dcx(), ident.span, E0603, "{} `{}` is private", descr, ident);
let mut err = struct_span_code_err!(
self.dcx(),
ident.span,
E0603,
"{} `{}` is private",
descr,
ident
);
err.span_label(ident.span, format!("private {descr}"));
let mut not_publicly_reexported = false;

View File

@ -17,7 +17,7 @@ use crate::{NameBinding, NameBindingData, NameBindingKind, PathResult};
use rustc_ast::NodeId;
use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::intern::Interned;
use rustc_errors::{pluralize, struct_span_err, Applicability, MultiSpan};
use rustc_errors::{pluralize, struct_span_code_err, Applicability, MultiSpan};
use rustc_hir::def::{self, DefKind, PartialRes};
use rustc_middle::metadata::ModChild;
use rustc_middle::metadata::Reexport;
@ -686,7 +686,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
.collect::<Vec<_>>();
let msg = format!("unresolved import{} {}", pluralize!(paths.len()), paths.join(", "),);
let mut diag = struct_span_err!(self.dcx(), span, E0432, "{}", &msg);
let mut diag = struct_span_code_err!(self.dcx(), span, E0432, "{}", &msg);
if let Some((_, UnresolvedImportError { note: Some(note), .. })) = errors.iter().last() {
diag.note(note.clone());

View File

@ -1664,7 +1664,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
} else {
("`'_` cannot be used here", "`'_` is a reserved lifetime name")
};
let mut diag = rustc_errors::struct_span_err!(
let mut diag = rustc_errors::struct_span_code_err!(
self.r.dcx(),
lifetime.ident.span,
E0637,
@ -1853,7 +1853,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
LifetimeRibKind::AnonymousCreateParameter { report_in_path: true, .. }
| LifetimeRibKind::AnonymousWarn(_) => {
let sess = self.r.tcx.sess;
let mut err = rustc_errors::struct_span_err!(
let mut err = rustc_errors::struct_span_code_err!(
sess.dcx(),
path_span,
E0726,
@ -2594,7 +2594,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
}
if param.ident.name == kw::UnderscoreLifetime {
rustc_errors::struct_span_err!(
rustc_errors::struct_span_code_err!(
self.r.dcx(),
param.ident.span,
E0637,
@ -2608,7 +2608,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
}
if param.ident.name == kw::StaticLifetime {
rustc_errors::struct_span_err!(
rustc_errors::struct_span_code_err!(
self.r.dcx(),
param.ident.span,
E0262,

View File

@ -16,7 +16,7 @@ use rustc_ast::{
use rustc_ast_pretty::pprust::where_bound_predicate_to_string;
use rustc_data_structures::fx::FxHashSet;
use rustc_errors::{
pluralize, struct_span_err, Applicability, Diagnostic, DiagnosticBuilder, ErrorGuaranteed,
pluralize, struct_span_code_err, Applicability, Diagnostic, DiagnosticBuilder, ErrorGuaranteed,
MultiSpan, SuggestionStyle,
};
use rustc_hir as hir;
@ -2603,7 +2603,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
) {
debug_assert_ne!(lifetime_ref.ident.name, kw::UnderscoreLifetime);
let mut err = if let Some(outer) = outer_lifetime_ref {
struct_span_err!(
struct_span_code_err!(
self.r.dcx(),
lifetime_ref.ident.span,
E0401,
@ -2612,7 +2612,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
.span_label_mv(lifetime_ref.ident.span, "use of generic parameter from outer item")
.span_label_mv(outer.span, "lifetime parameter from outer item")
} else {
struct_span_err!(
struct_span_code_err!(
self.r.dcx(),
lifetime_ref.ident.span,
E0261,
@ -2777,7 +2777,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
let num_lifetimes: usize = lifetime_refs.iter().map(|lt| lt.count).sum();
let spans: Vec<_> = lifetime_refs.iter().map(|lt| lt.span).collect();
let mut err = struct_span_err!(
let mut err = struct_span_code_err!(
self.r.dcx(),
spans,
E0106,
@ -3282,7 +3282,7 @@ fn mk_where_bound_predicate(
/// Report lifetime/lifetime shadowing as an error.
pub(super) fn signal_lifetime_shadowing(sess: &Session, orig: Ident, shadower: Ident) {
struct_span_err!(
struct_span_code_err!(
sess.dcx(),
shadower.span,
E0496,

View File

@ -15,7 +15,7 @@ use rustc_ast_pretty::pprust;
use rustc_attr::StabilityLevel;
use rustc_data_structures::intern::Interned;
use rustc_data_structures::sync::Lrc;
use rustc_errors::{struct_span_err, Applicability};
use rustc_errors::{struct_span_code_err, Applicability};
use rustc_expand::base::{Annotatable, DeriveResolutions, Indeterminate, ResolverExpand};
use rustc_expand::base::{SyntaxExtension, SyntaxExtensionKind};
use rustc_expand::compile_declarative_macro;
@ -948,7 +948,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
rule_spans = Vec::new();
}
BuiltinMacroState::AlreadySeen(span) => {
struct_span_err!(
struct_span_code_err!(
self.dcx(),
item.span,
E0773,

View File

@ -1,7 +1,7 @@
use crate::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
use crate::infer::InferCtxt;
use crate::traits::{Obligation, ObligationCause, ObligationCtxt};
use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder};
use rustc_errors::{pluralize, struct_span_code_err, Applicability, DiagnosticBuilder};
use rustc_hir as hir;
use rustc_hir::Node;
use rustc_middle::ty::{self, Ty};
@ -140,7 +140,7 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
let expected_str = args_str(&expected_args, &found_args);
let found_str = args_str(&found_args, &expected_args);
let mut err = struct_span_err!(
let mut err = struct_span_code_err!(
self.dcx(),
span,
E0593,

View File

@ -6,7 +6,7 @@ use rustc_ast::AttrKind;
use rustc_ast::{Attribute, MetaItem, NestedMetaItem};
use rustc_attr as attr;
use rustc_data_structures::fx::FxHashMap;
use rustc_errors::{struct_span_err, ErrorGuaranteed};
use rustc_errors::{struct_span_code_err, ErrorGuaranteed};
use rustc_hir as hir;
use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_middle::ty::GenericArgsRef;
@ -797,7 +797,7 @@ impl<'tcx> OnUnimplementedFormatString {
},
);
} else {
result = Err(struct_span_err!(
result = Err(struct_span_code_err!(
tcx.dcx(),
self.span,
E0230,
@ -816,7 +816,7 @@ impl<'tcx> OnUnimplementedFormatString {
}
// `{:1}` and `{}` are not to be used
Position::ArgumentIs(..) | Position::ArgumentImplicitlyIs(_) => {
let reported = struct_span_err!(
let reported = struct_span_code_err!(
tcx.dcx(),
self.span,
E0231,

View File

@ -13,7 +13,7 @@ use hir::def::CtorOf;
use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::stack::ensure_sufficient_stack;
use rustc_errors::{
error_code, pluralize, struct_span_err, Applicability, Diagnostic, DiagnosticBuilder,
error_code, pluralize, struct_span_code_err, Applicability, Diagnostic, DiagnosticBuilder,
MultiSpan, Style, SuggestionStyle,
};
use rustc_hir as hir;
@ -2145,7 +2145,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
ty::Coroutine(..) => "coroutine",
_ => "function",
};
let mut err = struct_span_err!(
let mut err = struct_span_code_err!(
self.dcx(),
span,
E0631,

View File

@ -19,7 +19,7 @@ use crate::traits::{
};
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
use rustc_errors::{
pluralize, struct_span_err, Applicability, Diagnostic, DiagnosticBuilder, ErrorGuaranteed,
pluralize, struct_span_code_err, Applicability, Diagnostic, DiagnosticBuilder, ErrorGuaranteed,
MultiSpan, StashKey, Style,
};
use rustc_hir as hir;
@ -280,7 +280,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
predicate.print(&mut cx).unwrap();
pred_str = cx.into_buffer();
}
let mut err = struct_span_err!(
let mut err = struct_span_code_err!(
self.dcx(),
span,
E0275,
@ -525,7 +525,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
(err_msg, None)
};
let mut err = struct_span_err!(self.dcx(), span, E0277, "{}", err_msg);
let mut err = struct_span_code_err!(self.dcx(), span, E0277, "{}", err_msg);
let mut suggested = false;
if is_try_conversion {
@ -1236,7 +1236,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
span_bug!(span, "const param tys cannot mention other generic parameters");
}
ty::Float(_) => {
struct_span_err!(
struct_span_code_err!(
self.dcx(),
span,
E0741,
@ -1244,7 +1244,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
)
}
ty::FnPtr(_) => {
struct_span_err!(
struct_span_code_err!(
self.dcx(),
span,
E0741,
@ -1252,7 +1252,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
)
}
ty::RawPtr(_) => {
struct_span_err!(
struct_span_code_err!(
self.dcx(),
span,
E0741,
@ -1261,7 +1261,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
}
ty::Adt(def, _) => {
// We should probably see if we're *allowed* to derive `ConstParamTy` on the type...
let mut diag = struct_span_err!(
let mut diag = struct_span_code_err!(
self.dcx(),
span,
E0741,
@ -1293,7 +1293,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
diag
}
_ => {
struct_span_err!(
struct_span_code_err!(
self.dcx(),
span,
E0741,
@ -1731,7 +1731,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
cx.into_buffer()
}))
});
let mut diag = struct_span_err!(self.dcx(), obligation.cause.span, E0271, "{msg}");
let mut diag = struct_span_code_err!(self.dcx(), obligation.cause.span, E0271, "{msg}");
let secondary_span = (|| {
let ty::PredicateKind::Clause(ty::ClauseKind::Projection(proj)) =
@ -2421,7 +2421,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
true,
)
} else {
struct_span_err!(
struct_span_code_err!(
self.dcx(),
span,
E0283,
@ -2664,7 +2664,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
.note_mv(format!("cannot satisfy `{predicate}`"))
} else {
// If we can't find a substitution, just print a generic error
struct_span_err!(
struct_span_code_err!(
self.dcx(),
span,
E0284,
@ -2691,7 +2691,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
err
} else {
// If we can't find a substitution, just print a generic error
struct_span_err!(
struct_span_code_err!(
self.dcx(),
span,
E0284,
@ -2705,7 +2705,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
if self.dcx().has_errors().is_some() || self.tainted_by_errors().is_some() {
return;
}
struct_span_err!(
struct_span_code_err!(
self.dcx(),
span,
E0284,

View File

@ -2995,7 +2995,7 @@ fn clean_use_statement_inner<'tcx>(
visibility.is_accessible_from(parent_mod, cx.tcx) && !current_mod.is_top_level_module();
if pub_underscore && let Some(ref inline) = inline_attr {
rustc_errors::struct_span_err!(
rustc_errors::struct_span_code_err!(
cx.tcx.dcx(),
inline.span(),
E0780,

View File

@ -495,7 +495,7 @@ impl<'tcx> Visitor<'tcx> for EmitIgnoredResolutionErrors<'tcx> {
.intersperse("::")
.collect::<String>()
);
rustc_errors::struct_span_err!(
rustc_errors::struct_span_code_err!(
self.tcx.dcx(),
path.span,
E0433,