Remove ObligationCause::span() method

This commit is contained in:
Michael Goulet 2024-10-27 22:53:14 +00:00
parent 2507e83d7b
commit 7f54b9ecef
9 changed files with 21 additions and 26 deletions

View File

@ -611,7 +611,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
Err(terr) => { Err(terr) => {
let mut diag = struct_span_code_err!( let mut diag = struct_span_code_err!(
tcx.dcx(), tcx.dcx(),
cause.span(), cause.span,
E0053, E0053,
"method `{}` has an incompatible return type for trait", "method `{}` has an incompatible return type for trait",
trait_m.name trait_m.name
@ -1169,7 +1169,7 @@ fn extract_spans_for_error_reporting<'tcx>(
TypeError::ArgumentMutability(i) | TypeError::ArgumentSorts(ExpectedFound { .. }, i) => { TypeError::ArgumentMutability(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.hir().span_if_local(trait_m.def_id)), _ => (cause.span, tcx.hir().span_if_local(trait_m.def_id)),
} }
} }

View File

@ -612,7 +612,7 @@ pub fn check_function_signature<'tcx>(
match err { match err {
TypeError::ArgumentMutability(i) TypeError::ArgumentMutability(i)
| TypeError::ArgumentSorts(ExpectedFound { .. }, i) => args.nth(i).unwrap(), | TypeError::ArgumentSorts(ExpectedFound { .. }, i) => args.nth(i).unwrap(),
_ => cause.span(), _ => cause.span,
} }
} }

View File

@ -2027,7 +2027,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
Err(_) => { Err(_) => {
span_bug!( span_bug!(
cause.span(), cause.span,
"subtyping remaining fields of type changing FRU failed: {target_ty} != {fru_ty}: {}::{}", "subtyping remaining fields of type changing FRU failed: {target_ty} != {fru_ty}: {}::{}",
variant.name, variant.name,
ident.name, ident.name,

View File

@ -550,7 +550,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
// This has/will have errored in wfcheck, which we cannot depend on from here, as typeck on functions // This has/will have errored in wfcheck, which we cannot depend on from here, as typeck on functions
// may run before wfcheck if the function is used in const eval. // may run before wfcheck if the function is used in const eval.
self.dcx().span_delayed_bug( self.dcx().span_delayed_bug(
cause.span(), cause.span,
format!("{self_ty} was a subtype of {method_self_ty} but now is not?"), format!("{self_ty} was a subtype of {method_self_ty} but now is not?"),
); );
} }

View File

@ -92,16 +92,6 @@ impl<'tcx> ObligationCause<'tcx> {
ObligationCause { span, body_id: CRATE_DEF_ID, code: Default::default() } ObligationCause { span, body_id: CRATE_DEF_ID, code: Default::default() }
} }
pub fn span(&self) -> Span {
match *self.code() {
ObligationCauseCode::MatchExpressionArm(box MatchExpressionArmCause {
arm_span,
..
}) => arm_span,
_ => self.span,
}
}
#[inline] #[inline]
pub fn code(&self) -> &ObligationCauseCode<'tcx> { pub fn code(&self) -> &ObligationCauseCode<'tcx> {
&self.code &self.code
@ -517,12 +507,17 @@ pub struct MatchExpressionArmCause<'tcx> {
pub prior_arm_block_id: Option<HirId>, pub prior_arm_block_id: Option<HirId>,
pub prior_arm_ty: Ty<'tcx>, pub prior_arm_ty: Ty<'tcx>,
pub prior_arm_span: Span, pub prior_arm_span: Span,
/// Span of the scrutinee of the match (the matched value).
pub scrut_span: Span, pub scrut_span: Span,
/// Source of the match, i.e. `match` or a desugaring.
pub source: hir::MatchSource, pub source: hir::MatchSource,
// Span of the *whole* match expr /// Span of the *whole* match expr.
pub expr_span: Span, pub expr_span: Span,
/// Spans of the previous arms except for those that diverge (i.e. evaluate to `!`).
///
/// These are used for pointing out errors that may affect several arms.
pub prior_non_diverging_arms: Vec<Span>, pub prior_non_diverging_arms: Vec<Span>,
// Is the expectation of this match expression an RPIT? /// Is the expectation of this match expression an RPIT?
pub tail_defines_return_position_impl_trait: Option<LocalDefId>, pub tail_defines_return_position_impl_trait: Option<LocalDefId>,
} }

View File

@ -392,7 +392,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
Some(ty) if expected == ty => { Some(ty) if expected == ty => {
let source_map = self.tcx.sess.source_map(); let source_map = self.tcx.sess.source_map();
err.span_suggestion( err.span_suggestion(
source_map.end_point(cause.span()), source_map.end_point(cause.span),
"try removing this `?`", "try removing this `?`",
"", "",
Applicability::MachineApplicable, Applicability::MachineApplicable,
@ -431,7 +431,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
Some(ty) if expected == ty => { Some(ty) if expected == ty => {
let source_map = self.tcx.sess.source_map(); let source_map = self.tcx.sess.source_map();
err.span_suggestion( err.span_suggestion(
source_map.end_point(cause.span()), source_map.end_point(cause.span),
"try removing this `?`", "try removing this `?`",
"", "",
Applicability::MachineApplicable, Applicability::MachineApplicable,
@ -1149,7 +1149,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
terr: TypeError<'tcx>, terr: TypeError<'tcx>,
prefer_label: bool, prefer_label: bool,
) { ) {
let span = cause.span(); 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.
@ -1643,7 +1643,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
terr: TypeError<'tcx>, terr: TypeError<'tcx>,
) -> Vec<TypeErrorAdditionalDiags> { ) -> Vec<TypeErrorAdditionalDiags> {
let mut suggestions = Vec::new(); let mut suggestions = Vec::new();
let span = trace.cause.span(); let span = trace.cause.span;
let values = self.resolve_vars_if_possible(trace.values); let values = self.resolve_vars_if_possible(trace.values);
if let Some((expected, found)) = values.ty() { if let Some((expected, found)) = values.ty() {
match (expected.kind(), found.kind()) { match (expected.kind(), found.kind()) {
@ -1793,7 +1793,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
) -> Diag<'a> { ) -> Diag<'a> {
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(); let span = trace.cause.span;
let failure_code = trace.cause.as_failure_code_diag( let failure_code = trace.cause.as_failure_code_diag(
terr, terr,
span, span,

View File

@ -237,7 +237,7 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
expected_args: GenericArgsRef<'tcx>, expected_args: GenericArgsRef<'tcx>,
actual_args: GenericArgsRef<'tcx>, actual_args: GenericArgsRef<'tcx>,
) -> Diag<'tcx> { ) -> Diag<'tcx> {
let span = cause.span(); let span = cause.span;
let (leading_ellipsis, satisfy_span, where_span, dup_span, def_id) = let (leading_ellipsis, satisfy_span, where_span, dup_span, def_id) =
if let ObligationCauseCode::WhereClause(def_id, span) if let ObligationCauseCode::WhereClause(def_id, span)

View File

@ -1180,7 +1180,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
selcx.tcx(), selcx.tcx(),
selcx.tcx().require_lang_item( selcx.tcx().require_lang_item(
LangItem::Sized, LangItem::Sized,
Some(obligation.cause.span()), Some(obligation.cause.span),
), ),
[self_ty], [self_ty],
), ),
@ -1600,7 +1600,7 @@ fn confirm_builtin_candidate<'cx, 'tcx>(
// exist. Instead, `Pointee<Metadata = ()>` should be a supertrait of `Sized`. // exist. Instead, `Pointee<Metadata = ()>` should be a supertrait of `Sized`.
let sized_predicate = ty::TraitRef::new( let sized_predicate = ty::TraitRef::new(
tcx, tcx,
tcx.require_lang_item(LangItem::Sized, Some(obligation.cause.span())), tcx.require_lang_item(LangItem::Sized, Some(obligation.cause.span)),
[self_ty], [self_ty],
); );
obligations.push(obligation.with(tcx, sized_predicate)); obligations.push(obligation.with(tcx, sized_predicate));

View File

@ -90,7 +90,7 @@ impl<'tcx> InferCtxt<'tcx> {
assert!(!self.intercrate); assert!(!self.intercrate);
let c_pred = let c_pred =
self.canonicalize_query(param_env.and(obligation.predicate), &mut _orig_values); self.canonicalize_query(param_env.and(obligation.predicate), &mut _orig_values);
self.tcx.at(obligation.cause.span()).evaluate_obligation(c_pred) self.tcx.at(obligation.cause.span).evaluate_obligation(c_pred)
} }
} }