Rollup merge of #132243 - compiler-errors:no-span, r=jieyouxu
Remove `ObligationCause::span()` method I think it's an incredibly confusing footgun to expose both `obligation_cause.span` and `obligation_cause.span()`. Especially because `ObligationCause::span()` (the method) seems to just be hacking around a single quirk in the way we set up obligation causes for match arms. First commit removes the need for that hack, with only one diagnostic span changing (but IMO not really getting worse -- I'd argue that it was already confusing).
This commit is contained in:
commit
3e3feac7c3
12 changed files with 38 additions and 46 deletions
|
@ -392,7 +392,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
Some(ty) if expected == ty => {
|
||||
let source_map = self.tcx.sess.source_map();
|
||||
err.span_suggestion(
|
||||
source_map.end_point(cause.span()),
|
||||
source_map.end_point(cause.span),
|
||||
"try removing this `?`",
|
||||
"",
|
||||
Applicability::MachineApplicable,
|
||||
|
@ -412,6 +412,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
source,
|
||||
ref prior_non_diverging_arms,
|
||||
scrut_span,
|
||||
expr_span,
|
||||
..
|
||||
}) => match source {
|
||||
hir::MatchSource::TryDesugar(scrut_hir_id) => {
|
||||
|
@ -430,7 +431,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
Some(ty) if expected == ty => {
|
||||
let source_map = self.tcx.sess.source_map();
|
||||
err.span_suggestion(
|
||||
source_map.end_point(cause.span()),
|
||||
source_map.end_point(cause.span),
|
||||
"try removing this `?`",
|
||||
"",
|
||||
Applicability::MachineApplicable,
|
||||
|
@ -460,12 +461,12 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
format!("this and all prior arms are found to be of type `{t}`"),
|
||||
);
|
||||
}
|
||||
let outer = if any_multiline_arm || !source_map.is_multiline(cause.span) {
|
||||
let outer = if any_multiline_arm || !source_map.is_multiline(expr_span) {
|
||||
// Cover just `match` and the scrutinee expression, not
|
||||
// the entire match body, to reduce diagram noise.
|
||||
cause.span.shrink_to_lo().to(scrut_span)
|
||||
expr_span.shrink_to_lo().to(scrut_span)
|
||||
} else {
|
||||
cause.span
|
||||
expr_span
|
||||
};
|
||||
let msg = "`match` arms have incompatible types";
|
||||
err.span_label(outer, msg);
|
||||
|
@ -1148,7 +1149,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
terr: TypeError<'tcx>,
|
||||
prefer_label: bool,
|
||||
) {
|
||||
let span = cause.span();
|
||||
let span = cause.span;
|
||||
|
||||
// For some types of errors, expected-found does not make
|
||||
// sense, so just ignore the values we were given.
|
||||
|
@ -1642,7 +1643,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
terr: TypeError<'tcx>,
|
||||
) -> Vec<TypeErrorAdditionalDiags> {
|
||||
let mut suggestions = Vec::new();
|
||||
let span = trace.cause.span();
|
||||
let span = trace.cause.span;
|
||||
let values = self.resolve_vars_if_possible(trace.values);
|
||||
if let Some((expected, found)) = values.ty() {
|
||||
match (expected.kind(), found.kind()) {
|
||||
|
@ -1792,7 +1793,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
) -> Diag<'a> {
|
||||
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(
|
||||
terr,
|
||||
span,
|
||||
|
|
|
@ -237,7 +237,7 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
|
|||
expected_args: GenericArgsRef<'tcx>,
|
||||
actual_args: GenericArgsRef<'tcx>,
|
||||
) -> Diag<'tcx> {
|
||||
let span = cause.span();
|
||||
let span = cause.span;
|
||||
|
||||
let (leading_ellipsis, satisfy_span, where_span, dup_span, def_id) =
|
||||
if let ObligationCauseCode::WhereClause(def_id, span)
|
||||
|
|
|
@ -1180,7 +1180,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
|
|||
selcx.tcx(),
|
||||
selcx.tcx().require_lang_item(
|
||||
LangItem::Sized,
|
||||
Some(obligation.cause.span()),
|
||||
Some(obligation.cause.span),
|
||||
),
|
||||
[self_ty],
|
||||
),
|
||||
|
@ -1600,7 +1600,7 @@ fn confirm_builtin_candidate<'cx, 'tcx>(
|
|||
// exist. Instead, `Pointee<Metadata = ()>` should be a supertrait of `Sized`.
|
||||
let sized_predicate = ty::TraitRef::new(
|
||||
tcx,
|
||||
tcx.require_lang_item(LangItem::Sized, Some(obligation.cause.span())),
|
||||
tcx.require_lang_item(LangItem::Sized, Some(obligation.cause.span)),
|
||||
[self_ty],
|
||||
);
|
||||
obligations.push(obligation.with(tcx, sized_predicate));
|
||||
|
|
|
@ -90,7 +90,7 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||
assert!(!self.intercrate);
|
||||
let c_pred =
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue