1
Fork 0

Rollup merge of #98869 - compiler-errors:stop_guessing_head_span, r=cjgillot

Remove some usages of `guess_head_span`

No need to pass things through `guess_head_span` if they already point to the head span.

Only major change is that we point to the head span of `enum`s on some errors now, which I prefer.

r? `@cjgillot`
This commit is contained in:
Dylan DPC 2022-07-15 15:53:37 +05:30 committed by GitHub
commit e0e6f1d1cb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
35 changed files with 162 additions and 223 deletions

View file

@ -714,10 +714,7 @@ impl<'tcx> TypeRelatingDelegate<'tcx> for QueryTypeRelatingDelegate<'_, 'tcx> {
} }
fn const_equate(&mut self, _a: Const<'tcx>, _b: Const<'tcx>) { fn const_equate(&mut self, _a: Const<'tcx>, _b: Const<'tcx>) {
span_bug!( span_bug!(self.cause.span(), "generic_const_exprs: unreachable `const_equate`");
self.cause.span(self.infcx.tcx),
"generic_const_exprs: unreachable `const_equate`"
);
} }
fn normalization() -> NormalizationStrategy { fn normalization() -> NormalizationStrategy {

View file

@ -1435,7 +1435,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
swap_secondary_and_primary: bool, swap_secondary_and_primary: bool,
force_label: bool, force_label: bool,
) { ) {
let span = cause.span(self.tcx); let span = cause.span();
// For some types of errors, expected-found does not make // For some types of errors, expected-found does not make
// sense, so just ignore the values we were given. // sense, so just ignore the values we were given.
@ -2085,7 +2085,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
debug!("report_and_explain_type_error(trace={:?}, terr={:?})", trace, terr); debug!("report_and_explain_type_error(trace={:?}, terr={:?})", trace, terr);
let span = trace.cause.span(self.tcx); let span = trace.cause.span();
let failure_code = trace.cause.as_failure_code(terr); let failure_code = trace.cause.as_failure_code(terr);
let mut diag = match failure_code { let mut diag = match failure_code {
FailureCode::Error0038(did) => { FailureCode::Error0038(did) => {

View file

@ -204,7 +204,7 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
expected_substs: SubstsRef<'tcx>, expected_substs: SubstsRef<'tcx>,
actual_substs: SubstsRef<'tcx>, actual_substs: SubstsRef<'tcx>,
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> { ) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
let span = cause.span(self.tcx()); let span = cause.span();
let msg = format!( let msg = format!(
"implementation of `{}` is not general enough", "implementation of `{}` is not general enough",
self.tcx().def_path_str(trait_def_id), self.tcx().def_path_str(trait_def_id),

View file

@ -18,20 +18,19 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
trait_item_def_id: DefId, trait_item_def_id: DefId,
requirement: &dyn fmt::Display, requirement: &dyn fmt::Display,
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> { ) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
let msg = "impl has stricter requirements than trait"; let mut err = struct_span_err!(
let sp = self.tcx.sess.source_map().guess_head_span(error_span); self.tcx.sess,
error_span,
E0276,
"impl has stricter requirements than trait"
);
let mut err = struct_span_err!(self.tcx.sess, sp, E0276, "{}", msg); if let Some(span) = self.tcx.hir().span_if_local(trait_item_def_id) {
if trait_item_def_id.is_local() {
let item_name = self.tcx.item_name(impl_item_def_id.to_def_id()); let item_name = self.tcx.item_name(impl_item_def_id.to_def_id());
err.span_label( err.span_label(span, format!("definition of `{}` from trait", item_name));
self.tcx.def_span(trait_item_def_id),
format!("definition of `{}` from trait", item_name),
);
} }
err.span_label(sp, format!("impl has extra requirement {}", requirement)); err.span_label(error_span, format!("impl has extra requirement {}", requirement));
err err
} }
@ -48,7 +47,6 @@ 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 span = tcx.sess.source_map().guess_head_span(span);
let mut err = struct_span_err!( let mut err = struct_span_err!(
tcx.sess, tcx.sess,
span, span,

View file

@ -694,9 +694,8 @@ pub trait LintContext: Sized {
} }
if let Some(span) = in_test_module { if let Some(span) = in_test_module {
let def_span = self.sess().source_map().guess_head_span(span);
db.span_help( db.span_help(
span.shrink_to_lo().to(def_span), self.sess().source_map().guess_head_span(span),
"consider adding a `#[cfg(test)]` to the containing module", "consider adding a `#[cfg(test)]` to the containing module",
); );
} }

View file

@ -139,13 +139,8 @@ impl<'tcx> ObligationCause<'tcx> {
ObligationCause { span, body_id: hir::CRATE_HIR_ID, code: Default::default() } ObligationCause { span, body_id: hir::CRATE_HIR_ID, code: Default::default() }
} }
pub fn span(&self, tcx: TyCtxt<'tcx>) -> Span { pub fn span(&self) -> Span {
match *self.code() { match *self.code() {
ObligationCauseCode::CompareImplMethodObligation { .. }
| ObligationCauseCode::MainFunctionType
| ObligationCauseCode::StartFunctionType => {
tcx.sess.source_map().guess_head_span(self.span)
}
ObligationCauseCode::MatchExpressionArm(box MatchExpressionArmCause { ObligationCauseCode::MatchExpressionArm(box MatchExpressionArmCause {
arm_span, arm_span,
.. ..

View file

@ -1759,8 +1759,7 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> {
|| self.tcx.resolutions(()).has_pub_restricted || self.tcx.resolutions(()).has_pub_restricted
{ {
let descr = descr.to_string(); let descr = descr.to_string();
let vis_span = let vis_span = self.tcx.def_span(def_id);
self.tcx.sess.source_map().guess_head_span(self.tcx.def_span(def_id));
if kind == "trait" { if kind == "trait" {
self.tcx.sess.emit_err(InPublicInterfaceTraits { self.tcx.sess.emit_err(InPublicInterfaceTraits {
span, span,

View file

@ -823,10 +823,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind) => { ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind) => {
let found_kind = self.closure_kind(closure_substs).unwrap(); let found_kind = self.closure_kind(closure_substs).unwrap();
let closure_span = let closure_span = self.tcx.def_span(closure_def_id);
self.tcx.sess.source_map().guess_head_span(
self.tcx.hir().span_if_local(closure_def_id).unwrap(),
);
let mut err = struct_span_err!( let mut err = struct_span_err!(
self.tcx.sess, self.tcx.sess,
closure_span, closure_span,
@ -951,9 +948,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
_ => None, _ => None,
}; };
let found_span = found_did let found_span = found_did.and_then(|did| self.tcx.hir().span_if_local(did));
.and_then(|did| self.tcx.hir().span_if_local(did))
.map(|sp| self.tcx.sess.source_map().guess_head_span(sp)); // the sp could be an fn def
if self.reported_closure_mismatch.borrow().contains(&(span, found_span)) { if self.reported_closure_mismatch.borrow().contains(&(span, found_span)) {
// We check closures twice, with obligations flowing in different directions, // We check closures twice, with obligations flowing in different directions,
@ -1089,7 +1084,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
kind: hir::ExprKind::Closure(&hir::Closure { body, fn_decl_span, .. }), kind: hir::ExprKind::Closure(&hir::Closure { body, fn_decl_span, .. }),
.. ..
}) => ( }) => (
sm.guess_head_span(fn_decl_span), fn_decl_span,
hir.body(body) hir.body(body)
.params .params
.iter() .iter()

View file

@ -1543,7 +1543,6 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
ty::Generator(..) => "generator", ty::Generator(..) => "generator",
_ => "function", _ => "function",
}; };
let span = self.tcx.sess.source_map().guess_head_span(span);
let mut err = struct_span_err!( let mut err = struct_span_err!(
self.tcx.sess, self.tcx.sess,
span, span,

View file

@ -603,7 +603,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
), ),
(Err(ErrorHandled::Linted), _) | (_, Err(ErrorHandled::Linted)) => { (Err(ErrorHandled::Linted), _) | (_, Err(ErrorHandled::Linted)) => {
span_bug!( span_bug!(
obligation.cause.span(self.selcx.tcx()), obligation.cause.span(),
"ConstEquate: const_eval_resolve returned an unexpected error" "ConstEquate: const_eval_resolve returned an unexpected error"
) )
} }

View file

@ -84,7 +84,7 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'cx, 'tcx> {
// Run canonical query. If overflow occurs, rerun from scratch but this time // Run canonical query. If overflow occurs, rerun from scratch but this time
// in standard trait query mode so that overflow is handled appropriately // in standard trait query mode so that overflow is handled appropriately
// within `SelectionContext`. // within `SelectionContext`.
self.tcx.at(obligation.cause.span(self.tcx)).evaluate_obligation(c_pred) self.tcx.at(obligation.cause.span()).evaluate_obligation(c_pred)
} }
// Helper function that canonicalizes and runs the query. If an // Helper function that canonicalizes and runs the query. If an

View file

@ -742,7 +742,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
| (_, Err(ErrorHandled::Reported(_))) => Ok(EvaluatedToErr), | (_, Err(ErrorHandled::Reported(_))) => Ok(EvaluatedToErr),
(Err(ErrorHandled::Linted), _) | (_, Err(ErrorHandled::Linted)) => { (Err(ErrorHandled::Linted), _) | (_, Err(ErrorHandled::Linted)) => {
span_bug!( span_bug!(
obligation.cause.span(self.tcx()), obligation.cause.span(),
"ConstEquate: const_eval_resolve returned an unexpected error" "ConstEquate: const_eval_resolve returned an unexpected error"
) )
} }

View file

@ -1958,11 +1958,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
); );
} }
if adt_def.did().is_local() { if let Some(sp) = tcx.hir().span_if_local(adt_def.did()) {
err.span_label( err.span_label(sp, format!("variant `{}` not found here", assoc_ident));
tcx.def_span(adt_def.did()),
format!("variant `{assoc_ident}` not found for this enum"),
);
} }
err.emit() err.emit()

View file

@ -1,6 +1,6 @@
use crate::check::coercion::{AsCoercionSite, CoerceMany}; use crate::check::coercion::{AsCoercionSite, CoerceMany};
use crate::check::{Diverges, Expectation, FnCtxt, Needs}; use crate::check::{Diverges, Expectation, FnCtxt, Needs};
use rustc_errors::{Applicability, Diagnostic, MultiSpan}; use rustc_errors::{Applicability, MultiSpan};
use rustc_hir::{self as hir, ExprKind}; use rustc_hir::{self as hir, ExprKind};
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
use rustc_infer::traits::Obligation; use rustc_infer::traits::Obligation;
@ -127,7 +127,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
&cause, &cause,
Some(&arm.body), Some(&arm.body),
arm_ty, arm_ty,
Some(&mut |err: &mut Diagnostic| { Some(&mut |err| {
let Some(ret) = self.ret_type_span else { let Some(ret) = self.ret_type_span else {
return; return;
}; };

View file

@ -375,8 +375,9 @@ fn check_alloc_error_fn(
} }
} }
fn check_struct(tcx: TyCtxt<'_>, def_id: LocalDefId, span: Span) { fn check_struct(tcx: TyCtxt<'_>, def_id: LocalDefId) {
let def = tcx.adt_def(def_id); let def = tcx.adt_def(def_id);
let span = tcx.def_span(def_id);
def.destructor(tcx); // force the destructor to be evaluated def.destructor(tcx); // force the destructor to be evaluated
check_representable(tcx, span, def_id); check_representable(tcx, span, def_id);
@ -388,8 +389,9 @@ fn check_struct(tcx: TyCtxt<'_>, def_id: LocalDefId, span: Span) {
check_packed(tcx, span, def); check_packed(tcx, span, def);
} }
fn check_union(tcx: TyCtxt<'_>, def_id: LocalDefId, span: Span) { fn check_union(tcx: TyCtxt<'_>, def_id: LocalDefId) {
let def = tcx.adt_def(def_id); let def = tcx.adt_def(def_id);
let span = tcx.def_span(def_id);
def.destructor(tcx); // force the destructor to be evaluated def.destructor(tcx); // force the destructor to be evaluated
check_representable(tcx, span, def_id); check_representable(tcx, span, def_id);
check_transparent(tcx, span, def); check_transparent(tcx, span, def);
@ -471,13 +473,14 @@ fn check_union_fields(tcx: TyCtxt<'_>, span: Span, item_def_id: LocalDefId) -> b
} }
/// Check that a `static` is inhabited. /// Check that a `static` is inhabited.
fn check_static_inhabited<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId, span: Span) { fn check_static_inhabited<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) {
// Make sure statics are inhabited. // Make sure statics are inhabited.
// Other parts of the compiler assume that there are no uninhabited places. In principle it // Other parts of the compiler assume that there are no uninhabited places. In principle it
// would be enough to check this for `extern` statics, as statics with an initializer will // would be enough to check this for `extern` statics, as statics with an initializer will
// have UB during initialization if they are uninhabited, but there also seems to be no good // have UB during initialization if they are uninhabited, but there also seems to be no good
// reason to allow any statics to be uninhabited. // reason to allow any statics to be uninhabited.
let ty = tcx.type_of(def_id); let ty = tcx.type_of(def_id);
let span = tcx.def_span(def_id);
let layout = match tcx.layout_of(ParamEnv::reveal_all().and(ty)) { let layout = match tcx.layout_of(ParamEnv::reveal_all().and(ty)) {
Ok(l) => l, Ok(l) => l,
// Foreign statics that overflow their allowed size should emit an error // Foreign statics that overflow their allowed size should emit an error
@ -524,9 +527,9 @@ pub(super) fn check_opaque<'tcx>(
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
def_id: LocalDefId, def_id: LocalDefId,
substs: SubstsRef<'tcx>, substs: SubstsRef<'tcx>,
span: Span,
origin: &hir::OpaqueTyOrigin, origin: &hir::OpaqueTyOrigin,
) { ) {
let span = tcx.def_span(def_id);
check_opaque_for_inheriting_lifetimes(tcx, def_id, span); check_opaque_for_inheriting_lifetimes(tcx, def_id, span);
if tcx.type_of(def_id).references_error() { if tcx.type_of(def_id).references_error() {
return; return;
@ -785,8 +788,8 @@ fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, id: hir::ItemId) {
match tcx.def_kind(id.def_id) { match tcx.def_kind(id.def_id) {
DefKind::Static(..) => { DefKind::Static(..) => {
tcx.ensure().typeck(id.def_id); tcx.ensure().typeck(id.def_id);
maybe_check_static_with_link_section(tcx, id.def_id, tcx.def_span(id.def_id)); maybe_check_static_with_link_section(tcx, id.def_id);
check_static_inhabited(tcx, id.def_id, tcx.def_span(id.def_id)); check_static_inhabited(tcx, id.def_id);
} }
DefKind::Const => { DefKind::Const => {
tcx.ensure().typeck(id.def_id); tcx.ensure().typeck(id.def_id);
@ -796,7 +799,7 @@ fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, id: hir::ItemId) {
let hir::ItemKind::Enum(ref enum_definition, _) = item.kind else { let hir::ItemKind::Enum(ref enum_definition, _) = item.kind else {
return; return;
}; };
check_enum(tcx, item.span, &enum_definition.variants, item.def_id); check_enum(tcx, &enum_definition.variants, item.def_id);
} }
DefKind::Fn => {} // entirely within check_item_body DefKind::Fn => {} // entirely within check_item_body
DefKind::Impl => { DefKind::Impl => {
@ -847,10 +850,10 @@ fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, id: hir::ItemId) {
} }
} }
DefKind::Struct => { DefKind::Struct => {
check_struct(tcx, id.def_id, tcx.def_span(id.def_id)); check_struct(tcx, id.def_id);
} }
DefKind::Union => { DefKind::Union => {
check_union(tcx, id.def_id, tcx.def_span(id.def_id)); check_union(tcx, id.def_id);
} }
DefKind::OpaqueTy => { DefKind::OpaqueTy => {
let item = tcx.hir().item(id); let item = tcx.hir().item(id);
@ -863,7 +866,7 @@ fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, id: hir::ItemId) {
// See https://github.com/rust-lang/rust/issues/75100 // See https://github.com/rust-lang/rust/issues/75100
if !tcx.sess.opts.actually_rustdoc { if !tcx.sess.opts.actually_rustdoc {
let substs = InternalSubsts::identity_for_item(tcx, item.def_id.to_def_id()); let substs = InternalSubsts::identity_for_item(tcx, item.def_id.to_def_id());
check_opaque(tcx, item.def_id, substs, item.span, &origin); check_opaque(tcx, item.def_id, substs, &origin);
} }
} }
DefKind::TyAlias => { DefKind::TyAlias => {
@ -927,7 +930,7 @@ fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, id: hir::ItemId) {
require_c_abi_if_c_variadic(tcx, fn_decl, abi, item.span); require_c_abi_if_c_variadic(tcx, fn_decl, abi, item.span);
} }
hir::ForeignItemKind::Static(..) => { hir::ForeignItemKind::Static(..) => {
check_static_inhabited(tcx, def_id, item.span); check_static_inhabited(tcx, def_id);
} }
_ => {} _ => {}
} }
@ -1328,7 +1331,6 @@ pub(super) fn check_transparent<'tcx>(tcx: TyCtxt<'tcx>, sp: Span, adt: ty::AdtD
if !adt.repr().transparent() { if !adt.repr().transparent() {
return; return;
} }
let sp = tcx.sess.source_map().guess_head_span(sp);
if adt.is_union() && !tcx.features().transparent_unions { if adt.is_union() && !tcx.features().transparent_unions {
feature_err( feature_err(
@ -1442,13 +1444,9 @@ pub(super) fn check_transparent<'tcx>(tcx: TyCtxt<'tcx>, sp: Span, adt: ty::AdtD
} }
#[allow(trivial_numeric_casts)] #[allow(trivial_numeric_casts)]
fn check_enum<'tcx>( fn check_enum<'tcx>(tcx: TyCtxt<'tcx>, vs: &'tcx [hir::Variant<'tcx>], def_id: LocalDefId) {
tcx: TyCtxt<'tcx>,
sp: Span,
vs: &'tcx [hir::Variant<'tcx>],
def_id: LocalDefId,
) {
let def = tcx.adt_def(def_id); let def = tcx.adt_def(def_id);
let sp = tcx.def_span(def_id);
def.destructor(tcx); // force the destructor to be evaluated def.destructor(tcx); // force the destructor to be evaluated
if vs.is_empty() { if vs.is_empty() {

View file

@ -171,14 +171,7 @@ fn compare_predicate_entailment<'tcx>(
let trait_m_predicates = tcx.predicates_of(trait_m.def_id); let trait_m_predicates = tcx.predicates_of(trait_m.def_id);
// Check region bounds. // Check region bounds.
check_region_bounds_on_impl_item( check_region_bounds_on_impl_item(tcx, impl_m, trait_m, &trait_m_generics, &impl_m_generics)?;
tcx,
impl_m_span,
impl_m,
trait_m,
&trait_m_generics,
&impl_m_generics,
)?;
// Create obligations for each predicate declared by the impl // Create obligations for each predicate declared by the impl
// definition in the context of the trait's parameter // definition in the context of the trait's parameter
@ -298,7 +291,7 @@ fn compare_predicate_entailment<'tcx>(
let mut diag = struct_span_err!( let mut diag = struct_span_err!(
tcx.sess, tcx.sess,
cause.span(tcx), cause.span(),
E0053, E0053,
"method `{}` has an incompatible type for trait", "method `{}` has an incompatible type for trait",
trait_m.name trait_m.name
@ -410,7 +403,6 @@ fn compare_predicate_entailment<'tcx>(
fn check_region_bounds_on_impl_item<'tcx>( fn check_region_bounds_on_impl_item<'tcx>(
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
span: Span,
impl_m: &ty::AssocItem, impl_m: &ty::AssocItem,
trait_m: &ty::AssocItem, trait_m: &ty::AssocItem,
trait_generics: &ty::Generics, trait_generics: &ty::Generics,
@ -436,21 +428,25 @@ fn check_region_bounds_on_impl_item<'tcx>(
// are zero. Since I don't quite know how to phrase things at // are zero. Since I don't quite know how to phrase things at
// the moment, give a kind of vague error message. // the moment, give a kind of vague error message.
if trait_params != impl_params { if trait_params != impl_params {
let item_kind = assoc_item_kind_str(impl_m); let span = tcx
let def_span = tcx.sess.source_map().guess_head_span(span); .hir()
let span = impl_m .get_generics(impl_m.def_id.expect_local())
.def_id .expect("expected impl item to have generics or else we can't compare them")
.as_local() .span;
.and_then(|did| tcx.hir().get_generics(did)) let generics_span = if let Some(local_def_id) = trait_m.def_id.as_local() {
.map_or(def_span, |g| g.span); Some(
let generics_span = trait_m.def_id.as_local().map(|did| { tcx.hir()
let def_sp = tcx.def_span(did); .get_generics(local_def_id)
tcx.hir().get_generics(did).map_or(def_sp, |g| g.span) .expect("expected trait item to have generics or else we can't compare them")
}); .span,
)
} else {
None
};
let reported = tcx.sess.emit_err(LifetimesOrBoundsMismatchOnTrait { let reported = tcx.sess.emit_err(LifetimesOrBoundsMismatchOnTrait {
span, span,
item_kind, item_kind: assoc_item_kind_str(impl_m),
ident: impl_m.ident(tcx), ident: impl_m.ident(tcx),
generics_span, generics_span,
}); });
@ -490,7 +486,7 @@ fn extract_spans_for_error_reporting<'a, 'tcx>(
TypeError::ArgumentSorts(ExpectedFound { .. }, i) => { TypeError::ArgumentSorts(ExpectedFound { .. }, i) => {
(impl_args.nth(i).unwrap(), trait_args.and_then(|mut args| args.nth(i))) (impl_args.nth(i).unwrap(), trait_args.and_then(|mut args| args.nth(i)))
} }
_ => (cause.span(tcx), tcx.hir().span_if_local(trait_m.def_id)), _ => (cause.span(), tcx.hir().span_if_local(trait_m.def_id)),
} }
} }
@ -1199,7 +1195,6 @@ fn compare_type_predicate_entailment<'tcx>(
check_region_bounds_on_impl_item( check_region_bounds_on_impl_item(
tcx, tcx,
impl_ty_span,
impl_ty, impl_ty,
trait_ty, trait_ty,
&trait_ty_generics, &trait_ty_generics,

View file

@ -183,8 +183,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} else if let (ty::FnDef(def_id, ..), true) = } else if let (ty::FnDef(def_id, ..), true) =
(&found.kind(), self.suggest_fn_call(err, expr, expected, found)) (&found.kind(), self.suggest_fn_call(err, expr, expected, found))
{ {
if def_id.is_local() { if let Some(sp) = self.tcx.hir().span_if_local(*def_id) {
err.span_label(self.tcx.def_span(def_id), &format!("{} defined here", found)); err.span_label(sp, format!("{found} defined here"));
} }
} else if !self.check_for_cast(err, expr, found, expected, expected_ty_expr) { } else if !self.check_for_cast(err, expr, found, expected, expected_ty_expr) {
let is_struct_pat_shorthand_field = let is_struct_pat_shorthand_field =

View file

@ -534,7 +534,7 @@ fn fn_maybe_err(tcx: TyCtxt<'_>, sp: Span, abi: Abi) {
} }
} }
fn maybe_check_static_with_link_section(tcx: TyCtxt<'_>, id: LocalDefId, span: Span) { fn maybe_check_static_with_link_section(tcx: TyCtxt<'_>, id: LocalDefId) {
// Only restricted on wasm target for now // Only restricted on wasm target for now
if !tcx.sess.target.is_like_wasm { if !tcx.sess.target.is_like_wasm {
return; return;
@ -560,7 +560,7 @@ fn maybe_check_static_with_link_section(tcx: TyCtxt<'_>, id: LocalDefId, span: S
let msg = "statics with a custom `#[link_section]` must be a \ let msg = "statics with a custom `#[link_section]` must be a \
simple list of bytes on the wasm target with no \ simple list of bytes on the wasm target with no \
extra levels of indirection such as references"; extra levels of indirection such as references";
tcx.sess.span_err(span, msg); tcx.sess.span_err(tcx.def_span(id), msg);
} }
} }
@ -621,9 +621,8 @@ fn missing_items_err(
// adding the associated item at the end of its body. // adding the associated item at the end of its body.
let sugg_sp = full_impl_span.with_lo(hi).with_hi(hi); let sugg_sp = full_impl_span.with_lo(hi).with_hi(hi);
// Obtain the level of indentation ending in `sugg_sp`. // Obtain the level of indentation ending in `sugg_sp`.
let indentation = tcx.sess.source_map().span_to_margin(sugg_sp).unwrap_or(0); let padding =
// Make the whitespace that will make the suggestion have the right indentation. tcx.sess.source_map().indentation_before(sugg_sp).unwrap_or_else(|| String::new());
let padding: String = " ".repeat(indentation);
for trait_item in missing_items { for trait_item in missing_items {
let snippet = suggestion_signature(trait_item, tcx); let snippet = suggestion_signature(trait_item, tcx);

View file

@ -1838,7 +1838,7 @@ fn check_false_global_bounds(fcx: &FnCtxt<'_, '_>, mut span: Span, id: hir::HirI
if let Some(hir::Generics { predicates, .. }) = if let Some(hir::Generics { predicates, .. }) =
hir_node.and_then(|node| node.generics()) hir_node.and_then(|node| node.generics())
{ {
let obligation_span = obligation.cause.span(fcx.tcx); let obligation_span = obligation.cause.span();
span = predicates span = predicates
.iter() .iter()

View file

@ -76,17 +76,17 @@ impl<'tcx> InherentOverlapChecker<'tcx> {
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_err!(
self.tcx.sess, self.tcx.sess,
self.tcx.span_of_impl(item1.def_id).unwrap(), self.tcx.def_span(item1.def_id),
E0592, E0592,
"duplicate definitions with name `{}`", "duplicate definitions with name `{}`",
name name
); );
err.span_label( err.span_label(
self.tcx.span_of_impl(item1.def_id).unwrap(), self.tcx.def_span(item1.def_id),
format!("duplicate definitions for `{}`", name), format!("duplicate definitions for `{}`", name),
); );
err.span_label( err.span_label(
self.tcx.span_of_impl(item2.def_id).unwrap(), self.tcx.def_span(item2.def_id),
format!("other definition for `{}`", name), format!("other definition for `{}`", name),
); );

View file

@ -1,13 +1,8 @@
error[E0732]: `#[repr(inttype)]` must be specified error[E0732]: `#[repr(inttype)]` must be specified
--> $DIR/arbitrary_enum_discriminant-no-repr.rs:4:1 --> $DIR/arbitrary_enum_discriminant-no-repr.rs:4:1
| |
LL | / enum Enum { LL | enum Enum {
LL | | | ^^^^^^^^^
LL | | Unit = 1,
LL | | Tuple() = 2,
LL | | Struct{} = 3,
LL | | }
| |_^
error: aborting due to previous error error: aborting due to previous error

View file

@ -1,16 +1,14 @@
error[E0081]: discriminant value `0` assigned more than once error[E0081]: discriminant value `0` assigned more than once
--> $DIR/enum-discrim-autosizing.rs:6:1 --> $DIR/enum-discrim-autosizing.rs:6:1
| |
LL | / enum Eu64 { LL | enum Eu64 {
LL | | | ^^^^^^^^^
LL | | Au64 = 0, LL |
| | - first assignment of `0` LL | Au64 = 0,
LL | | | - first assignment of `0`
LL | | Bu64 = 0x8000_0000_0000_0000 LL |
| | --------------------- second assignment of `0` (overflowed from `9223372036854775808`) LL | Bu64 = 0x8000_0000_0000_0000
LL | | | --------------------- second assignment of `0` (overflowed from `9223372036854775808`)
LL | | }
| |_^
error: aborting due to previous error error: aborting due to previous error

View file

@ -1,48 +1,41 @@
error[E0081]: discriminant value `3` assigned more than once error[E0081]: discriminant value `3` assigned more than once
--> $DIR/E0081.rs:1:1 --> $DIR/E0081.rs:1:1
| |
LL | / enum Enum { LL | enum Enum {
LL | | | ^^^^^^^^^
LL | | P = 3, LL |
| | - first assignment of `3` LL | P = 3,
LL | | | - first assignment of `3`
LL | | X = 3, LL |
| | - second assignment of `3` LL | X = 3,
LL | | | - second assignment of `3`
LL | | Y = 5
LL | | }
| |_^
error[E0081]: discriminant value `1` assigned more than once error[E0081]: discriminant value `1` assigned more than once
--> $DIR/E0081.rs:11:1 --> $DIR/E0081.rs:11:1
| |
LL | / enum EnumOverflowRepr { LL | enum EnumOverflowRepr {
LL | | | ^^^^^^^^^^^^^^^^^^^^^
LL | | P = 257, LL |
| | --- first assignment of `1` (overflowed from `257`) LL | P = 257,
LL | | | --- first assignment of `1` (overflowed from `257`)
LL | | X = 513, LL |
| | --- second assignment of `1` (overflowed from `513`) LL | X = 513,
LL | | | --- second assignment of `1` (overflowed from `513`)
LL | | }
| |_^
error[E0081]: discriminant value `-1` assigned more than once error[E0081]: discriminant value `-1` assigned more than once
--> $DIR/E0081.rs:20:1 --> $DIR/E0081.rs:20:1
| |
LL | / enum NegDisEnum { LL | enum NegDisEnum {
LL | | | ^^^^^^^^^^^^^^^
LL | | First = -1, LL |
| | -- first assignment of `-1` LL | First = -1,
LL | | | -- first assignment of `-1`
LL | | Second = -2, LL |
| | ----------- assigned discriminant for `Last` was incremented from this discriminant LL | Second = -2,
LL | | | ----------- assigned discriminant for `Last` was incremented from this discriminant
LL | | Last, LL |
| | ---- second assignment of `-1` LL | Last,
LL | | | ---- second assignment of `-1`
LL | | }
| |_^
error: aborting due to 3 previous errors error: aborting due to 3 previous errors

View file

@ -4,7 +4,7 @@ error[E0084]: unsupported representation for zero-variant enum
LL | #[repr(i32)] LL | #[repr(i32)]
| ^^^^^^^^^^^^ | ^^^^^^^^^^^^
LL | enum Foo {} LL | enum Foo {}
| ----------- zero-variant enum | -------- zero-variant enum
error: aborting due to previous error error: aborting due to previous error

View file

@ -1,10 +1,8 @@
error[E0658]: repr with 128-bit type is unstable error[E0658]: repr with 128-bit type is unstable
--> $DIR/E0658.rs:2:1 --> $DIR/E0658.rs:2:1
| |
LL | / enum Foo { LL | enum Foo {
LL | | Bar(u64), | ^^^^^^^^
LL | | }
| |_^
| |
= note: see issue #56071 <https://github.com/rust-lang/rust/issues/56071> for more information = note: see issue #56071 <https://github.com/rust-lang/rust/issues/56071> for more information
= help: add `#![feature(repr128)]` to the crate attributes to enable = help: add `#![feature(repr128)]` to the crate attributes to enable

View file

@ -2,19 +2,19 @@ error: extern static is too large for the current architecture
--> $DIR/extern-static-size-overflow.rs:38:5 --> $DIR/extern-static-size-overflow.rs:38:5
| |
LL | static BAZ: [u8; max_size()]; LL | static BAZ: [u8; max_size()];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: extern static is too large for the current architecture error: extern static is too large for the current architecture
--> $DIR/extern-static-size-overflow.rs:39:5 --> $DIR/extern-static-size-overflow.rs:39:5
| |
LL | static UWU: [usize; usize::MAX]; LL | static UWU: [usize; usize::MAX];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: extern static is too large for the current architecture error: extern static is too large for the current architecture
--> $DIR/extern-static-size-overflow.rs:40:5 --> $DIR/extern-static-size-overflow.rs:40:5
| |
LL | static A: ReallyBig; LL | static A: ReallyBig;
| ^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^
error: aborting due to 3 previous errors error: aborting due to 3 previous errors

View file

@ -1,10 +1,8 @@
error[E0658]: repr with 128-bit type is unstable error[E0658]: repr with 128-bit type is unstable
--> $DIR/feature-gate-repr128.rs:2:1 --> $DIR/feature-gate-repr128.rs:2:1
| |
LL | / enum A { LL | enum A {
LL | | A(u64) | ^^^^^^
LL | | }
| |_^
| |
= note: see issue #56071 <https://github.com/rust-lang/rust/issues/56071> for more information = note: see issue #56071 <https://github.com/rust-lang/rust/issues/56071> for more information
= help: add `#![feature(repr128)]` to the crate attributes to enable = help: add `#![feature(repr128)]` to the crate attributes to enable

View file

@ -1,53 +1,39 @@
error[E0081]: discriminant value `1` assigned more than once error[E0081]: discriminant value `1` assigned more than once
--> $DIR/issue-15524.rs:3:1 --> $DIR/issue-15524.rs:3:1
| |
LL | / enum Foo { LL | enum Foo {
LL | | | ^^^^^^^^
LL | | ...
LL | | LL | A = 1,
LL | | A = 1, | - first assignment of `1`
| | - first assignment of `1` LL | B = 1,
LL | | B = 1, | - second assignment of `1`
| | - second assignment of `1`
... |
LL | |
LL | | }
| |_^
error[E0081]: discriminant value `1` assigned more than once error[E0081]: discriminant value `1` assigned more than once
--> $DIR/issue-15524.rs:3:1 --> $DIR/issue-15524.rs:3:1
| |
LL | / enum Foo { LL | enum Foo {
LL | | | ^^^^^^^^
LL | | ...
LL | | LL | A = 1,
LL | | A = 1, | - first assignment of `1`
| | - first assignment of `1` LL | B = 1,
LL | | B = 1, LL | C = 0,
LL | | C = 0, | ----- assigned discriminant for `D` was incremented from this discriminant
| | ----- assigned discriminant for `D` was incremented from this discriminant LL | D,
LL | | D, | - second assignment of `1`
| | - second assignment of `1`
... |
LL | |
LL | | }
| |_^
error[E0081]: discriminant value `1` assigned more than once error[E0081]: discriminant value `1` assigned more than once
--> $DIR/issue-15524.rs:3:1 --> $DIR/issue-15524.rs:3:1
| |
LL | / enum Foo { LL | enum Foo {
LL | | | ^^^^^^^^
LL | | ...
LL | | LL | A = 1,
LL | | A = 1, | - first assignment of `1`
| | - first assignment of `1` ...
... | LL | E = N,
LL | | E = N, | - second assignment of `1`
| | - second assignment of `1`
LL | |
LL | | }
| |_^
error: aborting due to 3 previous errors error: aborting due to 3 previous errors

View file

@ -2,7 +2,7 @@ error[E0599]: no variant named `B` found for enum `S`
--> $DIR/issue-34209.rs:7:12 --> $DIR/issue-34209.rs:7:12
| |
LL | enum S { LL | enum S {
| ------ variant `B` not found for this enum | ------ variant `B` not found here
... ...
LL | S::B {} => {}, LL | S::B {} => {},
| ^ help: there is a variant with a similar name: `A` | ^ help: there is a variant with a similar name: `A`

View file

@ -22,7 +22,7 @@ LL | #[repr(simd)]
| ^^^^^^^^^^^^^ | ^^^^^^^^^^^^^
... ...
LL | enum Es {} LL | enum Es {}
| ---------- zero-variant enum | ------- zero-variant enum
error: aborting due to 3 previous errors error: aborting due to 3 previous errors

View file

@ -34,7 +34,7 @@ error[E0084]: unsupported representation for zero-variant enum
LL | #[repr(transparent)] LL | #[repr(transparent)]
| ^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^
LL | enum Void {} LL | enum Void {}
| ------------ zero-variant enum | --------- zero-variant enum
error[E0731]: transparent enum needs exactly one variant, but has 0 error[E0731]: transparent enum needs exactly one variant, but has 0
--> $DIR/repr-transparent.rs:45:1 --> $DIR/repr-transparent.rs:45:1

View file

@ -2,7 +2,7 @@ error: static of uninhabited type
--> $DIR/uninhabited-static.rs:6:5 --> $DIR/uninhabited-static.rs:6:5
| |
LL | static VOID: Void; LL | static VOID: Void;
| ^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^
| |
note: the lint level is defined here note: the lint level is defined here
--> $DIR/uninhabited-static.rs:2:9 --> $DIR/uninhabited-static.rs:2:9
@ -17,7 +17,7 @@ error: static of uninhabited type
--> $DIR/uninhabited-static.rs:8:5 --> $DIR/uninhabited-static.rs:8:5
| |
LL | static NEVER: !; LL | static NEVER: !;
| ^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^
| |
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #74840 <https://github.com/rust-lang/rust/issues/74840> = note: for more information, see issue #74840 <https://github.com/rust-lang/rust/issues/74840>

View file

@ -2,7 +2,7 @@ error[E0599]: no variant named `Squareee` found for enum `Shape`
--> $DIR/suggest-variants.rs:12:41 --> $DIR/suggest-variants.rs:12:41
| |
LL | enum Shape { LL | enum Shape {
| ---------- variant `Squareee` not found for this enum | ---------- variant `Squareee` not found here
... ...
LL | println!("My shape is {:?}", Shape::Squareee { size: 5}); LL | println!("My shape is {:?}", Shape::Squareee { size: 5});
| ^^^^^^^^ help: there is a variant with a similar name: `Square` | ^^^^^^^^ help: there is a variant with a similar name: `Square`
@ -11,7 +11,7 @@ error[E0599]: no variant named `Circl` found for enum `Shape`
--> $DIR/suggest-variants.rs:13:41 --> $DIR/suggest-variants.rs:13:41
| |
LL | enum Shape { LL | enum Shape {
| ---------- variant `Circl` not found for this enum | ---------- variant `Circl` not found here
... ...
LL | println!("My shape is {:?}", Shape::Circl { size: 5}); LL | println!("My shape is {:?}", Shape::Circl { size: 5});
| ^^^^^ help: there is a variant with a similar name: `Circle` | ^^^^^ help: there is a variant with a similar name: `Circle`
@ -20,7 +20,7 @@ error[E0599]: no variant named `Rombus` found for enum `Shape`
--> $DIR/suggest-variants.rs:14:41 --> $DIR/suggest-variants.rs:14:41
| |
LL | enum Shape { LL | enum Shape {
| ---------- variant `Rombus` not found for this enum | ---------- variant `Rombus` not found here
... ...
LL | println!("My shape is {:?}", Shape::Rombus{ size: 5}); LL | println!("My shape is {:?}", Shape::Rombus{ size: 5});
| ^^^^^^ variant not found in `Shape` | ^^^^^^ variant not found in `Shape`

View file

@ -1,17 +1,13 @@
error[E0081]: discriminant value `0` assigned more than once error[E0081]: discriminant value `0` assigned more than once
--> $DIR/tag-variant-disr-dup.rs:3:1 --> $DIR/tag-variant-disr-dup.rs:3:1
| |
LL | / enum Color { LL | enum Color {
LL | | | ^^^^^^^^^^
LL | | Red = 0xff0000, ...
LL | | Green = 0x00ff00, LL | Black = 0x000000,
LL | | Blue = 0x0000ff, | -------- first assignment of `0`
LL | | Black = 0x000000, LL | White = 0x000000,
| | -------- first assignment of `0` | -------- second assignment of `0`
LL | | White = 0x000000,
| | -------- second assignment of `0`
LL | | }
| |_^
error: aborting due to previous error error: aborting due to previous error

View file

@ -31,8 +31,12 @@ LL | trait Trait: Sized {}
error[E0038]: the trait `Trait` cannot be made into an object error[E0038]: the trait `Trait` cannot be made into an object
--> $DIR/wf-unsafe-trait-obj-match.rs:25:25 --> $DIR/wf-unsafe-trait-obj-match.rs:25:25
| |
LL | let t: &dyn Trait = match opt() { LL | let t: &dyn Trait = match opt() {
| ^^^^^^^^^^^ `Trait` cannot be made into an object | _________________________^
LL | | Some(()) => &S,
LL | | None => &R,
LL | | };
| |_____^ `Trait` cannot be made into an object
| |
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety> note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $DIR/wf-unsafe-trait-obj-match.rs:6:14 --> $DIR/wf-unsafe-trait-obj-match.rs:6:14