1
Fork 0

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_middle::ty::{self, Ty, TyCtxt};
use rustc_span::Span; use rustc_span::Span;
@ -31,7 +31,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
borrow_span: Span, borrow_span: Span,
borrow_desc: &str, borrow_desc: &str,
) -> DiagnosticBuilder<'tcx> { ) -> DiagnosticBuilder<'tcx> {
struct_span_err!( struct_span_code_err!(
self.dcx(), self.dcx(),
span, span,
E0503, E0503,
@ -52,7 +52,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
old_load_end_span: Option<Span>, old_load_end_span: Option<Span>,
) -> DiagnosticBuilder<'tcx> { ) -> DiagnosticBuilder<'tcx> {
let via = |msg: &str| if msg.is_empty() { "".to_string() } else { format!(" (via {msg})") }; 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(), self.dcx(),
new_loan_span, new_loan_span,
E0499, E0499,
@ -98,7 +98,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
old_loan_span: Span, old_loan_span: Span,
old_load_end_span: Option<Span>, old_load_end_span: Option<Span>,
) -> DiagnosticBuilder<'tcx> { ) -> DiagnosticBuilder<'tcx> {
let mut err = struct_span_err!( let mut err = struct_span_code_err!(
self.dcx(), self.dcx(),
new_loan_span, new_loan_span,
E0524, E0524,
@ -131,7 +131,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
old_opt_via: &str, old_opt_via: &str,
previous_end_span: Option<Span>, previous_end_span: Option<Span>,
) -> DiagnosticBuilder<'cx> { ) -> DiagnosticBuilder<'cx> {
let mut err = struct_span_err!( let mut err = struct_span_code_err!(
self.dcx(), self.dcx(),
new_loan_span, new_loan_span,
E0500, E0500,
@ -163,7 +163,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
previous_end_span: Option<Span>, previous_end_span: Option<Span>,
second_borrow_desc: &str, second_borrow_desc: &str,
) -> DiagnosticBuilder<'cx> { ) -> DiagnosticBuilder<'cx> {
let mut err = struct_span_err!( let mut err = struct_span_code_err!(
self.dcx(), self.dcx(),
new_loan_span, new_loan_span,
E0501, E0501,
@ -196,7 +196,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
old_load_end_span: Option<Span>, old_load_end_span: Option<Span>,
) -> DiagnosticBuilder<'cx> { ) -> DiagnosticBuilder<'cx> {
let via = |msg: &str| if msg.is_empty() { "".to_string() } else { format!(" (via {msg})") }; 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(), self.dcx(),
span, span,
E0502, E0502,
@ -236,7 +236,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
borrow_span: Span, borrow_span: Span,
desc: &str, desc: &str,
) -> DiagnosticBuilder<'cx> { ) -> DiagnosticBuilder<'cx> {
struct_span_err!( struct_span_code_err!(
self.dcx(), self.dcx(),
span, span,
E0506, E0506,
@ -254,11 +254,11 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
is_arg: bool, is_arg: bool,
) -> DiagnosticBuilder<'cx> { ) -> DiagnosticBuilder<'cx> {
let msg = if is_arg { "to immutable argument" } else { "twice to immutable variable" }; 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> { 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( pub(crate) fn cannot_move_out_of(
@ -266,7 +266,13 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
move_from_span: Span, move_from_span: Span,
move_from_desc: &str, move_from_desc: &str,
) -> DiagnosticBuilder<'cx> { ) -> 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 /// 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", (&ty::Slice(_), _) => "slice",
_ => span_bug!(move_from_span, "this path should not cause illegal move"), _ => span_bug!(move_from_span, "this path should not cause illegal move"),
}; };
struct_span_err!( struct_span_code_err!(
self.dcx(), self.dcx(),
move_from_span, move_from_span,
E0508, E0508,
@ -299,7 +305,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
move_from_span: Span, move_from_span: Span,
container_ty: Ty<'_>, container_ty: Ty<'_>,
) -> DiagnosticBuilder<'cx> { ) -> DiagnosticBuilder<'cx> {
struct_span_err!( struct_span_code_err!(
self.dcx(), self.dcx(),
move_from_span, move_from_span,
E0509, E0509,
@ -318,7 +324,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
) -> DiagnosticBuilder<'tcx> { ) -> DiagnosticBuilder<'tcx> {
let moved_path = moved_path.map(|mp| format!(": `{mp}`")).unwrap_or_default(); let moved_path = moved_path.map(|mp| format!(": `{mp}`")).unwrap_or_default();
struct_span_err!( struct_span_code_err!(
self.dcx(), self.dcx(),
use_span, use_span,
E0382, E0382,
@ -335,7 +341,14 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
path: &str, path: &str,
reason: &str, reason: &str,
) -> DiagnosticBuilder<'tcx> { ) -> 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( pub(crate) fn cannot_mutate_in_immutable_section(
@ -346,7 +359,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
immutable_section: &str, immutable_section: &str,
action: &str, action: &str,
) -> DiagnosticBuilder<'tcx> { ) -> DiagnosticBuilder<'tcx> {
struct_span_err!( struct_span_code_err!(
self.dcx(), self.dcx(),
mutate_span, mutate_span,
E0510, E0510,
@ -365,7 +378,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
yield_span: Span, yield_span: Span,
) -> DiagnosticBuilder<'tcx> { ) -> DiagnosticBuilder<'tcx> {
let coroutine_kind = self.body.coroutine.as_ref().unwrap().coroutine_kind; let coroutine_kind = self.body.coroutine.as_ref().unwrap().coroutine_kind;
struct_span_err!( struct_span_code_err!(
self.dcx(), self.dcx(),
span, span,
E0626, E0626,
@ -378,7 +391,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
&self, &self,
borrow_span: Span, borrow_span: Span,
) -> DiagnosticBuilder<'tcx> { ) -> DiagnosticBuilder<'tcx> {
struct_span_err!( struct_span_code_err!(
self.dcx(), self.dcx(),
borrow_span, borrow_span,
E0713, E0713,
@ -391,7 +404,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
span: Span, span: Span,
path: &str, path: &str,
) -> DiagnosticBuilder<'tcx> { ) -> 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( pub(crate) fn cannot_return_reference_to_local(
@ -401,7 +414,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
reference_desc: &str, reference_desc: &str,
path_desc: &str, path_desc: &str,
) -> DiagnosticBuilder<'tcx> { ) -> DiagnosticBuilder<'tcx> {
struct_span_err!( struct_span_code_err!(
self.dcx(), self.dcx(),
span, span,
E0515, E0515,
@ -424,7 +437,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
capture_span: Span, capture_span: Span,
scope: &str, scope: &str,
) -> DiagnosticBuilder<'tcx> { ) -> DiagnosticBuilder<'tcx> {
struct_span_err!( struct_span_code_err!(
self.dcx(), self.dcx(),
closure_span, closure_span,
E0373, E0373,
@ -439,7 +452,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
&self, &self,
span: Span, span: Span,
) -> DiagnosticBuilder<'tcx> { ) -> DiagnosticBuilder<'tcx> {
struct_span_err!( struct_span_code_err!(
self.dcx(), self.dcx(),
span, span,
E0712, E0712,
@ -451,7 +464,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
&self, &self,
span: Span, span: Span,
) -> DiagnosticBuilder<'tcx> { ) -> 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, escape_span: Span,
escapes_from: &str, escapes_from: &str,
) -> DiagnosticBuilder<'tcx> { ) -> DiagnosticBuilder<'tcx> {
struct_span_err!( struct_span_code_err!(
tcx.dcx(), tcx.dcx(),
escape_span, escape_span,
E0521, E0521,

View file

@ -1,7 +1,9 @@
// ignore-tidy-filelength
use either::Either; use either::Either;
use rustc_data_structures::captures::Captures; use rustc_data_structures::captures::Captures;
use rustc_data_structures::fx::FxIndexSet; 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 as hir;
use rustc_hir::def::{DefKind, Res}; use rustc_hir::def::{DefKind, Res};
use rustc_hir::intravisit::{walk_block, walk_expr, Visitor}; 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 used = desired_action.as_general_verb_in_past_tense();
let mut err = let mut err = struct_span_code_err!(
struct_span_err!(self.dcx(), span, E0381, "{used} binding {desc}{isnt_initialized}"); self.dcx(),
span,
E0381,
"{used} binding {desc}{isnt_initialized}"
);
use_spans.var_path_only_subdiag(&mut err, desired_action); use_spans.var_path_only_subdiag(&mut err, desired_action);
if let InitializationRequiringAction::PartialAssignment if let InitializationRequiringAction::PartialAssignment

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -2,7 +2,7 @@ use crate::astconv::{GenericArgCountMismatch, GenericArgCountResult, OnlySelfBou
use crate::bounds::Bounds; use crate::bounds::Bounds;
use crate::errors::TraitObjectDeclaredWithNoTraits; use crate::errors::TraitObjectDeclaredWithNoTraits;
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet}; 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 as hir;
use rustc_hir::def::{DefKind, Res}; use rustc_hir::def::{DefKind, Res};
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
@ -89,7 +89,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
if regular_traits.len() > 1 { if regular_traits.len() > 1 {
let first_trait = &regular_traits[0]; let first_trait = &regular_traits[0];
let additional_trait = &regular_traits[1]; let additional_trait = &regular_traits[1];
let mut err = struct_span_err!( let mut err = struct_span_code_err!(
tcx.dcx(), tcx.dcx(),
additional_trait.bottom().1, additional_trait.bottom().1,
E0225, E0225,
@ -290,7 +290,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
if references_self { if references_self {
let def_id = i.bottom().0.def_id(); let def_id = i.bottom().0.def_id();
struct_span_err!( struct_span_code_err!(
tcx.dcx(), tcx.dcx(),
i.bottom().1, i.bottom().1,
E0038, E0038,
@ -375,7 +375,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
self.ast_region_to_region(lifetime, None) self.ast_region_to_region(lifetime, None)
} else { } else {
self.re_infer(None, span).unwrap_or_else(|| { self.re_infer(None, span).unwrap_or_else(|| {
let err = struct_span_err!( let err = struct_span_code_err!(
tcx.dcx(), tcx.dcx(),
span, span,
E0228, 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) { match tcx.sess.target.is_abi_supported(abi) {
Some(true) => (), Some(true) => (),
Some(false) => { Some(false) => {
struct_span_err!( struct_span_code_err!(
tcx.dcx(), tcx.dcx(),
span, span,
E0570, 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 // This ABI is only allowed on function pointers
if abi == Abi::CCmseNonSecureCall { if abi == Abi::CCmseNonSecureCall {
struct_span_err!( struct_span_code_err!(
tcx.dcx(), tcx.dcx(),
span, span,
E0781, E0781,
@ -560,7 +560,7 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) {
(0, _) => ("const", "consts", None), (0, _) => ("const", "consts", None),
_ => ("type or const", "types or consts", None), _ => ("type or const", "types or consts", None),
}; };
struct_span_err!( struct_span_code_err!(
tcx.dcx(), tcx.dcx(),
item.span, item.span,
E0044, E0044,
@ -687,7 +687,7 @@ fn check_impl_items_against_trait<'tcx>(
ty::ImplPolarity::Negative => { ty::ImplPolarity::Negative => {
if let [first_item_ref, ..] = impl_item_refs { if let [first_item_ref, ..] = impl_item_refs {
let first_item_span = tcx.def_span(first_item_ref); let first_item_span = tcx.def_span(first_item_ref);
struct_span_err!( struct_span_code_err!(
tcx.dcx(), tcx.dcx(),
first_item_span, first_item_span,
E0749, E0749,
@ -840,12 +840,12 @@ pub fn check_simd(tcx: TyCtxt<'_>, sp: Span, def_id: LocalDefId) {
{ {
let fields = &def.non_enum_variant().fields; let fields = &def.non_enum_variant().fields;
if fields.is_empty() { 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; return;
} }
let e = fields[FieldIdx::from_u32(0)].ty(tcx, args); let e = fields[FieldIdx::from_u32(0)].ty(tcx, args);
if !fields.iter().all(|f| f.ty(tcx, args) == e) { 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") .span_label_mv(sp, "SIMD elements must have the same type")
.emit(); .emit();
return; return;
@ -858,10 +858,10 @@ pub fn check_simd(tcx: TyCtxt<'_>, sp: Span, def_id: LocalDefId) {
}; };
if let Some(len) = len { if let Some(len) = len {
if len == 0 { 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; return;
} else if len > MAX_SIMD_LANES { } else if len > MAX_SIMD_LANES {
struct_span_err!( struct_span_code_err!(
tcx.dcx(), tcx.dcx(),
sp, sp,
E0075, 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(_)) => if matches!(t.kind(), ty::Int(_) | ty::Uint(_) | ty::Float(_) | ty::RawPtr(_)) =>
{ /* struct([f32; 4]) is ok */ } { /* struct([f32; 4]) is ok */ }
_ => { _ => {
struct_span_err!( struct_span_code_err!(
tcx.dcx(), tcx.dcx(),
sp, sp,
E0077, E0077,
@ -907,7 +907,7 @@ pub(super) fn check_packed(tcx: TyCtxt<'_>, sp: Span, def: ty::AdtDef<'_>) {
&& let Some(repr_pack) = repr.pack && let Some(repr_pack) = repr.pack
&& pack as u64 != repr_pack.bytes() && pack as u64 != repr_pack.bytes()
{ {
struct_span_err!( struct_span_code_err!(
tcx.dcx(), tcx.dcx(),
sp, sp,
E0634, E0634,
@ -918,7 +918,7 @@ pub(super) fn check_packed(tcx: TyCtxt<'_>, sp: Span, def: ty::AdtDef<'_>) {
} }
} }
if repr.align.is_some() { if repr.align.is_some() {
struct_span_err!( struct_span_code_err!(
tcx.dcx(), tcx.dcx(),
sp, sp,
E0587, E0587,
@ -927,7 +927,7 @@ pub(super) fn check_packed(tcx: TyCtxt<'_>, sp: Span, def: ty::AdtDef<'_>) {
.emit(); .emit();
} else { } else {
if let Some(def_spans) = check_packed_inner(tcx, def.did(), &mut vec![]) { 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(), tcx.dcx(),
sp, sp,
E0588, E0588,
@ -1117,7 +1117,7 @@ fn check_enum(tcx: TyCtxt<'_>, def_id: LocalDefId) {
if def.variants().is_empty() { if def.variants().is_empty() {
if let Some(attr) = tcx.get_attrs(def_id, sym::repr).next() { if let Some(attr) = tcx.get_attrs(def_id, sym::repr).next() {
struct_span_err!( struct_span_code_err!(
tcx.dcx(), tcx.dcx(),
attr.span, attr.span,
E0084, 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)); let disr_non_unit = def.variants().iter().any(|var| !is_unit(var) && has_disr(var));
if disr_non_unit || (disr_units && has_non_units) { if disr_non_unit || (disr_units && has_non_units) {
struct_span_err!( struct_span_code_err!(
tcx.dcx(), tcx.dcx(),
tcx.def_span(def_id), tcx.def_span(def_id),
E0732, 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 { if discrs[i].1.val == discrs[o].1.val {
let err = error.get_or_insert_with(|| { let err = error.get_or_insert_with(|| {
let mut ret = struct_span_err!( let mut ret = struct_span_code_err!(
tcx.dcx(), tcx.dcx(),
tcx.def_span(adt.did()), tcx.def_span(adt.did()),
E0081, E0081,
@ -1309,9 +1309,15 @@ pub(super) fn check_type_params_are_used<'tcx>(
&& let ty::GenericParamDefKind::Type { .. } = param.kind && let ty::GenericParamDefKind::Type { .. } = param.kind
{ {
let span = tcx.def_span(param.def_id); let span = tcx.def_span(param.def_id);
struct_span_err!(tcx.dcx(), span, E0091, "type parameter `{}` is unused", param.name,) struct_span_code_err!(
.span_label_mv(span, "unused type parameter") tcx.dcx(),
.emit(); 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, opaque_def_id: LocalDefId,
span: Span, span: Span,
) -> ErrorGuaranteed { ) -> 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; let mut label = false;
if let Some((def_id, visitor)) = get_owner_return_paths(tcx, opaque_def_id) { 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 crate::errors::LifetimesOrBoundsMismatchOnTrait;
use hir::def_id::{DefId, DefIdMap, LocalDefId}; use hir::def_id::{DefId, DefIdMap, LocalDefId};
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet}; 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 as hir;
use rustc_hir::def::{DefKind, Res}; use rustc_hir::def::{DefKind, Res};
use rustc_hir::intravisit; 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) { match ocx.eq(&cause, param_env, trait_return_ty, impl_return_ty) {
Ok(()) => {} Ok(()) => {}
Err(terr) => { Err(terr) => {
let mut diag = struct_span_err!( let mut diag = struct_span_code_err!(
tcx.dcx(), tcx.dcx(),
cause.span(), cause.span(),
E0053, E0053,
@ -972,7 +972,7 @@ fn report_trait_method_mismatch<'tcx>(
let (impl_err_span, trait_err_span) = let (impl_err_span, trait_err_span) =
extract_spans_for_error_reporting(infcx, terr, &cause, impl_m, trait_m); 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(), tcx.dcx(),
impl_err_span, impl_err_span,
E0053, E0053,
@ -1217,7 +1217,7 @@ fn compare_self_type<'tcx>(
(false, true) => { (false, true) => {
let self_descr = self_string(impl_m); let self_descr = self_string(impl_m);
let impl_m_span = tcx.def_span(impl_m.def_id); 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(), tcx.dcx(),
impl_m_span, impl_m_span,
E0185, E0185,
@ -1237,7 +1237,7 @@ fn compare_self_type<'tcx>(
(true, false) => { (true, false) => {
let self_descr = self_string(trait_m); let self_descr = self_string(trait_m);
let impl_m_span = tcx.def_span(impl_m.def_id); 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(), tcx.dcx(),
impl_m_span, impl_m_span,
E0186, E0186,
@ -1463,7 +1463,7 @@ fn compare_number_of_method_arguments<'tcx>(
}) })
.unwrap_or_else(|| tcx.def_span(impl_m.def_id)); .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(), tcx.dcx(),
impl_span, impl_span,
E0050, E0050,
@ -1530,7 +1530,7 @@ fn compare_synthetic_generics<'tcx>(
let impl_def_id = impl_def_id.expect_local(); let impl_def_id = impl_def_id.expect_local();
let impl_span = tcx.def_span(impl_def_id); let impl_span = tcx.def_span(impl_def_id);
let trait_span = tcx.def_span(trait_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(), tcx.dcx(),
impl_span, impl_span,
E0643, E0643,
@ -1689,7 +1689,7 @@ fn compare_generic_param_kinds<'tcx>(
let param_impl_span = tcx.def_span(param_impl.def_id); let param_impl_span = tcx.def_span(param_impl.def_id);
let param_trait_span = tcx.def_span(param_trait.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(), tcx.dcx(),
param_impl_span, param_impl_span,
E0053, E0053,
@ -1836,7 +1836,7 @@ fn compare_const_predicate_entailment<'tcx>(
let (ty, _) = tcx.hir().expect_impl_item(impl_ct_def_id).expect_const(); let (ty, _) = tcx.hir().expect_impl_item(impl_ct_def_id).expect_const();
cause.span = ty.span; cause.span = ty.span;
let mut diag = struct_span_err!( let mut diag = struct_span_code_err!(
tcx.dcx(), tcx.dcx(),
cause.span, cause.span,
E0326, E0326,

View file

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

View file

@ -8,7 +8,7 @@ use crate::errors::{
}; };
use hir::def_id::DefId; 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_hir as hir;
use rustc_middle::traits::{ObligationCause, ObligationCauseCode}; use rustc_middle::traits::{ObligationCause, ObligationCauseCode};
use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_middle::ty::{self, Ty, TyCtxt};
@ -29,7 +29,7 @@ fn equate_intrinsic_type<'tcx>(
(own_counts, generics.span) (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") .span_label_mv(it.span, "expected a function")
.emit(); .emit();
return; return;

View file

@ -78,7 +78,7 @@ use std::num::NonZeroU32;
use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_errors::ErrorGuaranteed; 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::def_id::{DefId, LocalDefId};
use rustc_hir::intravisit::Visitor; use rustc_hir::intravisit::Visitor;
use rustc_index::bit_set::BitSet; 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_ast as ast;
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet}; 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 as hir;
use rustc_hir::def_id::{DefId, LocalDefId, LocalModDefId}; use rustc_hir::def_id::{DefId, LocalDefId, LocalModDefId};
use rustc_hir::lang_items::LangItem; 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 { if let hir::Defaultness::Default { .. } = impl_.defaultness {
let mut spans = vec![span]; let mut spans = vec![span];
spans.extend(impl_.defaultness_span); spans.extend(impl_.defaultness_span);
res = Err(struct_span_err!( res = Err(struct_span_code_err!(
tcx.dcx(), tcx.dcx(),
spans, spans,
E0750, E0750,
@ -1116,7 +1118,7 @@ fn check_trait(tcx: TyCtxt<'_>, item: &hir::Item<'_>) -> Result<(), ErrorGuarant
|| matches!(trait_def.specialization_kind, TraitSpecializationKind::Marker) || matches!(trait_def.specialization_kind, TraitSpecializationKind::Marker)
{ {
for associated_def_id in &*tcx.associated_item_def_ids(def_id) { for associated_def_id in &*tcx.associated_item_def_ids(def_id) {
struct_span_err!( struct_span_code_err!(
tcx.dcx(), tcx.dcx(),
tcx.def_span(*associated_def_id), tcx.def_span(*associated_def_id),
E0714, E0714,
@ -1610,7 +1612,7 @@ fn check_method_receiver<'tcx>(
} }
fn e0307(tcx: TyCtxt<'_>, span: Span, receiver_ty: Ty<'_>) -> ErrorGuaranteed { 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") .note_mv("type of `self` must be `Self` or a type that dereferences to it")
.help_mv(HELP_FOR_SELF_TYPE) .help_mv(HELP_FOR_SELF_TYPE)
.emit() .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<'_> { 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") .span_label_mv(span, "unused parameter")
} }

View file

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

View file

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

View file

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

View file

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

View file

@ -12,7 +12,7 @@ use crate::constrained_generic_params as cgp;
use min_specialization::check_min_specialization; use min_specialization::check_min_specialization;
use rustc_data_structures::fx::FxHashSet; 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::DefKind;
use rustc_hir::def_id::{LocalDefId, LocalModDefId}; use rustc_hir::def_id::{LocalDefId, LocalModDefId};
use rustc_middle::query::Providers; 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) { 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(), tcx.dcx(),
span, span,
E0207, E0207,

View file

@ -36,7 +36,7 @@
//! ``` //! ```
use crate::FnCtxt; 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 as hir;
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
use rustc_hir::intravisit::{self, Visitor}; 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![] }; let mut visitor = CollectRetsVisitor { ret_exprs: vec![] };
match *cause.code() { match *cause.code() {
ObligationCauseCode::ReturnNoExpression => { ObligationCauseCode::ReturnNoExpression => {
err = struct_span_err!( err = struct_span_code_err!(
fcx.dcx(), fcx.dcx(),
cause.span, cause.span,
E0069, E0069,

View file

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

View file

@ -6,7 +6,8 @@ use crate::method::MethodCallee;
use crate::TupleArgumentsFlag::*; use crate::TupleArgumentsFlag::*;
use crate::{errors, Expectation::*}; use crate::{errors, Expectation::*};
use crate::{ 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_ast as ast;
use rustc_data_structures::fx::FxIndexSet; 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 // 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 // our input types to err_args so we don't blow up the error messages
struct_span_err!( struct_span_code_err!(
tcx.dcx(), tcx.dcx(),
call_span, call_span,
E0059, E0059,
@ -807,7 +808,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
let mut err = if formal_and_expected_inputs.len() == provided_args.len() { let mut err = if formal_and_expected_inputs.len() == provided_args.len() {
struct_span_err!( struct_span_code_err!(
tcx.dcx(), tcx.dcx(),
full_call_span, full_call_span,
E0308, E0308,
@ -1378,7 +1379,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// (issue #88844). // (issue #88844).
guar guar
} }
_ => struct_span_err!( _ => struct_span_code_err!(
self.dcx(), self.dcx(),
path_span, path_span,
E0071, E0071,

View file

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

View file

@ -52,7 +52,7 @@ use crate::expectation::Expectation;
use crate::fn_ctxt::RawTy; use crate::fn_ctxt::RawTy;
use crate::gather_locals::GatherLocalsVisitor; use crate::gather_locals::GatherLocalsVisitor;
use rustc_data_structures::unord::UnordSet; 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 as hir;
use rustc_hir::def::{DefKind, Res}; use rustc_hir::def::{DefKind, Res};
use rustc_hir::intravisit::Visitor; use rustc_hir::intravisit::Visitor;
@ -72,7 +72,7 @@ rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
#[macro_export] #[macro_export]
macro_rules! type_error_struct { macro_rules! type_error_struct {
($dcx:expr, $span:expr, $typ:expr, $code:ident, $($message:tt)*) => ({ ($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() { if $typ.references_error() {
err.downgrade_to_delayed_bug(); 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_data_structures::unord::UnordSet;
use rustc_errors::StashKey; use rustc_errors::StashKey;
use rustc_errors::{ 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 as hir;
use rustc_hir::def::DefKind; use rustc_hir::def::DefKind;
@ -148,7 +148,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
MethodError::Ambiguity(mut sources) => { MethodError::Ambiguity(mut sources) => {
let mut err = struct_span_err!( let mut err = struct_span_code_err!(
self.dcx(), self.dcx(),
item_name.span, item_name.span,
E0034, E0034,
@ -171,7 +171,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
MethodError::PrivateMatch(kind, def_id, out_of_scope_traits) => { MethodError::PrivateMatch(kind, def_id, out_of_scope_traits) => {
let kind = self.tcx.def_kind_descr(kind, def_id); 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(), self.dcx(),
item_name.span, item_name.span,
E0624, E0624,
@ -263,8 +263,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
) -> DiagnosticBuilder<'_> { ) -> DiagnosticBuilder<'_> {
let mut file = None; let mut file = None;
let ty_str = self.tcx.short_ty_string(rcvr_ty, &mut file); let ty_str = self.tcx.short_ty_string(rcvr_ty, &mut file);
let mut err = let mut err = struct_span_code_err!(
struct_span_err!(self.dcx(), rcvr_expr.span, E0599, "cannot write into `{}`", ty_str); self.dcx(),
rcvr_expr.span,
E0599,
"cannot write into `{}`",
ty_str
);
err.span_note( err.span_note(
rcvr_expr.span, rcvr_expr.span,
"must implement `io::Write`, `fmt::Write`, or have a `write_fmt` method", "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() && !actual.has_concrete_skeleton()
&& let SelfSource::MethodCall(expr) = source && let SelfSource::MethodCall(expr) = source
{ {
let mut err = struct_span_err!( let mut err = struct_span_code_err!(
tcx.dcx(), tcx.dcx(),
span, span,
E0689, E0689,

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -11,7 +11,9 @@ use rustc_arena::{DroplessArena, TypedArena};
use rustc_ast::Mutability; use rustc_ast::Mutability;
use rustc_data_structures::fx::FxIndexSet; use rustc_data_structures::fx::FxIndexSet;
use rustc_data_structures::stack::ensure_sufficient_stack; 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 as hir;
use rustc_hir::def::*; use rustc_hir::def::*;
use rustc_hir::def_id::LocalDefId; 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<'_> { 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)] #[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::util::case::Case;
use rustc_ast::{self as ast}; use rustc_ast::{self as ast};
use rustc_ast_pretty::pprust; 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::edit_distance::edit_distance;
use rustc_span::edition::Edition; use rustc_span::edition::Edition;
use rustc_span::source_map; use rustc_span::source_map;
@ -759,7 +759,7 @@ impl<'a> Parser<'a> {
if let token::DocComment(..) = self.token.kind { if let token::DocComment(..) = self.token.kind {
if self.look_ahead(1, |tok| tok == &token::CloseDelim(Delimiter::Brace)) { if self.look_ahead(1, |tok| tok == &token::CloseDelim(Delimiter::Brace)) {
// FIXME: merge with `DocCommentDoesNotDocumentAnything` (E0585) // FIXME: merge with `DocCommentDoesNotDocumentAnything` (E0585)
struct_span_err!( struct_span_code_err!(
self.dcx(), self.dcx(),
self.token.span, self.token.span,
E0584, 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_ast::{Block, Fn, ForeignItem, ForeignItemKind, Impl, Item, ItemKind, NodeId};
use rustc_attr as attr; use rustc_attr as attr;
use rustc_data_structures::sync::Lrc; 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_expand::expand::AstFragment;
use rustc_hir::def::{self, *}; use rustc_hir::def::{self, *};
use rustc_hir::def_id::{DefId, LocalDefId, CRATE_DEF_ID}; 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 { for attr in &item.attrs {
if attr.has_name(sym::macro_use) { if attr.has_name(sym::macro_use) {
if self.parent_scope.module.parent.is_some() { if self.parent_scope.module.parent.is_some() {
struct_span_err!( struct_span_code_err!(
self.r.dcx(), self.r.dcx(),
item.span, item.span,
E0468, E0468,
@ -1024,7 +1024,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
} }
} }
let ill_formed = |span| { 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() { match attr.meta() {
Some(meta) => match meta.kind { Some(meta) => match meta.kind {
@ -1095,8 +1095,13 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
allow_shadowing, allow_shadowing,
); );
} else { } else {
struct_span_err!(self.r.dcx(), ident.span, E0469, "imported macro not found") struct_span_code_err!(
.emit(); 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_ast_pretty::pprust;
use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::fx::FxHashSet;
use rustc_errors::{ 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, DiagnosticBuilder, ErrorGuaranteed, MultiSpan, SuggestionStyle,
}; };
use rustc_feature::BUILTIN_ATTRIBUTES; use rustc_feature::BUILTIN_ATTRIBUTES;
@ -153,7 +153,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
BuiltinLintDiagnostics::AmbiguousGlobImports { diag }, BuiltinLintDiagnostics::AmbiguousGlobImports { diag },
); );
} else { } 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); report_ambiguity_error(&mut err, diag);
err.emit(); err.emit();
} }
@ -254,15 +254,15 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
let msg = format!("the name `{name}` is defined multiple times"); let msg = format!("the name `{name}` is defined multiple times");
let mut err = match (old_binding.is_extern_crate(), new_binding.is_extern_crate()) { 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, _) | (_, true) => match new_binding.is_import() && old_binding.is_import() {
true => struct_span_err!(self.dcx(), span, E0254, "{}", msg), true => struct_span_code_err!(self.dcx(), span, E0254, "{}", msg),
false => struct_span_err!(self.dcx(), span, E0260, "{}", msg), false => struct_span_code_err!(self.dcx(), span, E0260, "{}", msg),
}, },
_ => match (old_binding.is_import_user_facing(), new_binding.is_import_user_facing()) { _ => match (old_binding.is_import_user_facing(), new_binding.is_import_user_facing()) {
(false, false) => struct_span_err!(self.dcx(), span, E0428, "{}", msg), (false, false) => struct_span_code_err!(self.dcx(), span, E0428, "{}", msg),
(true, true) => struct_span_err!(self.dcx(), span, E0252, "{}", msg), (true, true) => struct_span_code_err!(self.dcx(), span, E0252, "{}", msg),
_ => struct_span_err!(self.dcx(), span, E0255, "{}", 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 origin_sp = origin.iter().copied().collect::<Vec<_>>();
let msp = MultiSpan::from_spans(target_sp.clone()); let msp = MultiSpan::from_spans(target_sp.clone());
let mut err = struct_span_err!( let mut err = struct_span_code_err!(
self.dcx(), self.dcx(),
msp, msp,
E0408, E0408,
@ -788,7 +788,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
} }
ResolutionError::FailedToResolve { last_segment, label, suggestion, module } => { ResolutionError::FailedToResolve { last_segment, label, suggestion, module } => {
let mut err = 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); err.span_label(span, label);
if let Some((suggestions, msg, applicability)) = suggestion { if let Some((suggestions, msg, applicability)) = suggestion {
@ -1702,8 +1702,14 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
// Print the primary message. // Print the primary message.
let descr = get_descr(binding); let descr = get_descr(binding);
let mut err = let mut err = struct_span_code_err!(
struct_span_err!(self.dcx(), ident.span, E0603, "{} `{}` is private", descr, ident); self.dcx(),
ident.span,
E0603,
"{} `{}` is private",
descr,
ident
);
err.span_label(ident.span, format!("private {descr}")); err.span_label(ident.span, format!("private {descr}"));
let mut not_publicly_reexported = false; let mut not_publicly_reexported = false;

View file

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

View file

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

View file

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

View file

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

View file

@ -1,7 +1,7 @@
use crate::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; use crate::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
use crate::infer::InferCtxt; use crate::infer::InferCtxt;
use crate::traits::{Obligation, ObligationCause, ObligationCtxt}; 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 as hir;
use rustc_hir::Node; use rustc_hir::Node;
use rustc_middle::ty::{self, Ty}; 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 expected_str = args_str(&expected_args, &found_args);
let found_str = args_str(&found_args, &expected_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(), self.dcx(),
span, span,
E0593, E0593,

View file

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

View file

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

View file

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

View file

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