Auto merge of #119751 - nnethercote:error-api-fixes, r=oli-obk
Diagnostic API fixes Some improvements to diagnostic APIs: improve some naming, use shortcuts in more places, and add a couple of missing methods. r? `@compiler-errors`
This commit is contained in:
commit
a2d9d73e60
135 changed files with 766 additions and 756 deletions
|
@ -122,8 +122,8 @@ pub fn is_const_evaluatable<'tcx>(
|
|||
if span == rustc_span::DUMMY_SP { tcx.def_span(uv.def) } else { span },
|
||||
"failed to evaluate generic const expression",
|
||||
)
|
||||
.note_mv("the crate this constant originates from uses `#![feature(generic_const_exprs)]`")
|
||||
.span_suggestion_verbose_mv(
|
||||
.with_note("the crate this constant originates from uses `#![feature(generic_const_exprs)]`")
|
||||
.with_span_suggestion_verbose(
|
||||
rustc_span::DUMMY_SP,
|
||||
"consider enabling this feature",
|
||||
"#![feature(generic_const_exprs)]\n",
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
|
||||
use crate::infer::InferCtxt;
|
||||
use crate::traits::{Obligation, ObligationCause, ObligationCtxt};
|
||||
use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder};
|
||||
use rustc_errors::{pluralize, struct_span_code_err, Applicability, DiagnosticBuilder};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::Node;
|
||||
use rustc_middle::ty::{self, Ty};
|
||||
|
@ -140,7 +140,7 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
|
|||
let expected_str = args_str(&expected_args, &found_args);
|
||||
let found_str = args_str(&found_args, &expected_args);
|
||||
|
||||
let mut err = struct_span_err!(
|
||||
let mut err = struct_span_code_err!(
|
||||
self.dcx(),
|
||||
span,
|
||||
E0593,
|
||||
|
|
|
@ -6,7 +6,7 @@ use rustc_ast::AttrKind;
|
|||
use rustc_ast::{Attribute, MetaItem, NestedMetaItem};
|
||||
use rustc_attr as attr;
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_errors::{struct_span_err, ErrorGuaranteed};
|
||||
use rustc_errors::{struct_span_code_err, ErrorGuaranteed};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def_id::{DefId, LocalDefId};
|
||||
use rustc_middle::ty::GenericArgsRef;
|
||||
|
@ -14,7 +14,7 @@ use rustc_middle::ty::{self, GenericParamDefKind, TyCtxt};
|
|||
use rustc_parse_format::{ParseMode, Parser, Piece, Position};
|
||||
use rustc_session::lint::builtin::UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES;
|
||||
use rustc_span::symbol::{kw, sym, Symbol};
|
||||
use rustc_span::{Span, DUMMY_SP};
|
||||
use rustc_span::Span;
|
||||
use std::iter;
|
||||
|
||||
use crate::errors::{
|
||||
|
@ -657,9 +657,7 @@ impl<'tcx> OnUnimplementedDirective {
|
|||
|
||||
Ok(None)
|
||||
} else {
|
||||
let reported = tcx
|
||||
.dcx()
|
||||
.span_delayed_bug(DUMMY_SP, "of_item: neither meta_item_list nor value_str");
|
||||
let reported = tcx.dcx().delayed_bug("of_item: neither meta_item_list nor value_str");
|
||||
return Err(reported);
|
||||
};
|
||||
debug!("of_item({:?}) = {:?}", item_def_id, result);
|
||||
|
@ -797,7 +795,7 @@ impl<'tcx> OnUnimplementedFormatString {
|
|||
},
|
||||
);
|
||||
} else {
|
||||
result = Err(struct_span_err!(
|
||||
result = Err(struct_span_code_err!(
|
||||
tcx.dcx(),
|
||||
self.span,
|
||||
E0230,
|
||||
|
@ -816,7 +814,7 @@ impl<'tcx> OnUnimplementedFormatString {
|
|||
}
|
||||
// `{:1}` and `{}` are not to be used
|
||||
Position::ArgumentIs(..) | Position::ArgumentImplicitlyIs(_) => {
|
||||
let reported = struct_span_err!(
|
||||
let reported = struct_span_code_err!(
|
||||
tcx.dcx(),
|
||||
self.span,
|
||||
E0231,
|
||||
|
|
|
@ -13,7 +13,7 @@ use hir::def::CtorOf;
|
|||
use rustc_data_structures::fx::FxHashSet;
|
||||
use rustc_data_structures::stack::ensure_sufficient_stack;
|
||||
use rustc_errors::{
|
||||
error_code, pluralize, struct_span_err, Applicability, Diagnostic, DiagnosticBuilder,
|
||||
error_code, pluralize, struct_span_code_err, Applicability, Diagnostic, DiagnosticBuilder,
|
||||
MultiSpan, Style, SuggestionStyle,
|
||||
};
|
||||
use rustc_hir as hir;
|
||||
|
@ -2145,7 +2145,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
ty::Coroutine(..) => "coroutine",
|
||||
_ => "function",
|
||||
};
|
||||
let mut err = struct_span_err!(
|
||||
let mut err = struct_span_code_err!(
|
||||
self.dcx(),
|
||||
span,
|
||||
E0631,
|
||||
|
|
|
@ -19,7 +19,7 @@ use crate::traits::{
|
|||
};
|
||||
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
|
||||
use rustc_errors::{
|
||||
pluralize, struct_span_err, Applicability, Diagnostic, DiagnosticBuilder, ErrorGuaranteed,
|
||||
pluralize, struct_span_code_err, Applicability, Diagnostic, DiagnosticBuilder, ErrorGuaranteed,
|
||||
MultiSpan, StashKey, Style,
|
||||
};
|
||||
use rustc_hir as hir;
|
||||
|
@ -228,7 +228,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
self.dcx().span_delayed_bug(DUMMY_SP, "expected fulfillment errors")
|
||||
self.dcx().delayed_bug("expected fulfillment errors")
|
||||
}
|
||||
|
||||
/// Reports that an overflow has occurred and halts compilation. We
|
||||
|
@ -280,7 +280,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
predicate.print(&mut cx).unwrap();
|
||||
pred_str = cx.into_buffer();
|
||||
}
|
||||
let mut err = struct_span_err!(
|
||||
let mut err = struct_span_code_err!(
|
||||
self.dcx(),
|
||||
span,
|
||||
E0275,
|
||||
|
@ -525,7 +525,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
(err_msg, None)
|
||||
};
|
||||
|
||||
let mut err = struct_span_err!(self.dcx(), span, E0277, "{}", err_msg);
|
||||
let mut err = struct_span_code_err!(self.dcx(), span, E0277, "{}", err_msg);
|
||||
|
||||
let mut suggested = false;
|
||||
if is_try_conversion {
|
||||
|
@ -1236,7 +1236,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
span_bug!(span, "const param tys cannot mention other generic parameters");
|
||||
}
|
||||
ty::Float(_) => {
|
||||
struct_span_err!(
|
||||
struct_span_code_err!(
|
||||
self.dcx(),
|
||||
span,
|
||||
E0741,
|
||||
|
@ -1244,7 +1244,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
)
|
||||
}
|
||||
ty::FnPtr(_) => {
|
||||
struct_span_err!(
|
||||
struct_span_code_err!(
|
||||
self.dcx(),
|
||||
span,
|
||||
E0741,
|
||||
|
@ -1252,7 +1252,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
)
|
||||
}
|
||||
ty::RawPtr(_) => {
|
||||
struct_span_err!(
|
||||
struct_span_code_err!(
|
||||
self.dcx(),
|
||||
span,
|
||||
E0741,
|
||||
|
@ -1261,7 +1261,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
}
|
||||
ty::Adt(def, _) => {
|
||||
// We should probably see if we're *allowed* to derive `ConstParamTy` on the type...
|
||||
let mut diag = struct_span_err!(
|
||||
let mut diag = struct_span_code_err!(
|
||||
self.dcx(),
|
||||
span,
|
||||
E0741,
|
||||
|
@ -1293,7 +1293,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
diag
|
||||
}
|
||||
_ => {
|
||||
struct_span_err!(
|
||||
struct_span_code_err!(
|
||||
self.dcx(),
|
||||
span,
|
||||
E0741,
|
||||
|
@ -1731,7 +1731,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
cx.into_buffer()
|
||||
}))
|
||||
});
|
||||
let mut diag = struct_span_err!(self.dcx(), obligation.cause.span, E0271, "{msg}");
|
||||
let mut diag = struct_span_code_err!(self.dcx(), obligation.cause.span, E0271, "{msg}");
|
||||
|
||||
let secondary_span = (|| {
|
||||
let ty::PredicateKind::Clause(ty::ClauseKind::Projection(proj)) =
|
||||
|
@ -2421,7 +2421,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
true,
|
||||
)
|
||||
} else {
|
||||
struct_span_err!(
|
||||
struct_span_code_err!(
|
||||
self.dcx(),
|
||||
span,
|
||||
E0283,
|
||||
|
@ -2661,17 +2661,17 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
ErrorCode::E0284,
|
||||
true,
|
||||
)
|
||||
.note_mv(format!("cannot satisfy `{predicate}`"))
|
||||
.with_note(format!("cannot satisfy `{predicate}`"))
|
||||
} else {
|
||||
// If we can't find a substitution, just print a generic error
|
||||
struct_span_err!(
|
||||
struct_span_code_err!(
|
||||
self.dcx(),
|
||||
span,
|
||||
E0284,
|
||||
"type annotations needed: cannot satisfy `{}`",
|
||||
predicate,
|
||||
)
|
||||
.span_label_mv(span, format!("cannot satisfy `{predicate}`"))
|
||||
.with_span_label(span, format!("cannot satisfy `{predicate}`"))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2691,28 +2691,28 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
err
|
||||
} else {
|
||||
// If we can't find a substitution, just print a generic error
|
||||
struct_span_err!(
|
||||
struct_span_code_err!(
|
||||
self.dcx(),
|
||||
span,
|
||||
E0284,
|
||||
"type annotations needed: cannot satisfy `{}`",
|
||||
predicate,
|
||||
)
|
||||
.span_label_mv(span, format!("cannot satisfy `{predicate}`"))
|
||||
.with_span_label(span, format!("cannot satisfy `{predicate}`"))
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
if self.dcx().has_errors().is_some() || self.tainted_by_errors().is_some() {
|
||||
return;
|
||||
}
|
||||
struct_span_err!(
|
||||
struct_span_code_err!(
|
||||
self.dcx(),
|
||||
span,
|
||||
E0284,
|
||||
"type annotations needed: cannot satisfy `{}`",
|
||||
predicate,
|
||||
)
|
||||
.span_label_mv(span, format!("cannot satisfy `{predicate}`"))
|
||||
.with_span_label(span, format!("cannot satisfy `{predicate}`"))
|
||||
}
|
||||
};
|
||||
self.note_obligation_cause(&mut err, obligation);
|
||||
|
@ -3552,7 +3552,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
//
|
||||
// Note that with `feature(generic_const_exprs)` this case should not
|
||||
// be reachable.
|
||||
.note_mv("this may fail depending on what value the parameter takes")
|
||||
.with_note("this may fail depending on what value the parameter takes")
|
||||
.emit();
|
||||
return None;
|
||||
}
|
||||
|
|
|
@ -286,10 +286,8 @@ impl<'cx, 'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for QueryNormalizer<'cx, 'tcx>
|
|||
// Rustdoc normalizes possibly not well-formed types, so only
|
||||
// treat this as a bug if we're not in rustdoc.
|
||||
if !tcx.sess.opts.actually_rustdoc {
|
||||
tcx.dcx().span_delayed_bug(
|
||||
DUMMY_SP,
|
||||
format!("unexpected ambiguity: {c_data:?} {result:?}"),
|
||||
);
|
||||
tcx.dcx()
|
||||
.delayed_bug(format!("unexpected ambiguity: {c_data:?} {result:?}"));
|
||||
}
|
||||
return Err(NoSolution);
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ use rustc_errors::ErrorGuaranteed;
|
|||
use rustc_infer::infer::region_constraints::RegionConstraintData;
|
||||
use rustc_middle::traits::query::NoSolution;
|
||||
use rustc_middle::ty::{TyCtxt, TypeFoldable};
|
||||
use rustc_span::{Span, DUMMY_SP};
|
||||
use rustc_span::Span;
|
||||
|
||||
use std::fmt;
|
||||
|
||||
|
@ -88,10 +88,9 @@ where
|
|||
if errors.is_empty() {
|
||||
Ok(value)
|
||||
} else {
|
||||
Err(infcx.dcx().span_delayed_bug(
|
||||
DUMMY_SP,
|
||||
format!("errors selecting obligation during MIR typeck: {errors:?}"),
|
||||
))
|
||||
Err(infcx
|
||||
.dcx()
|
||||
.delayed_bug(format!("errors selecting obligation during MIR typeck: {errors:?}")))
|
||||
}
|
||||
})?;
|
||||
|
||||
|
|
|
@ -969,7 +969,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
self.tcx().def_span(impl_def_id),
|
||||
"multiple drop impls found",
|
||||
)
|
||||
.span_note_mv(
|
||||
.with_span_note(
|
||||
self.tcx().def_span(old_impl_def_id),
|
||||
"other impl here",
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue