Consolidate obligation cause codes for where clauses
This commit is contained in:
parent
ef15976387
commit
e444017b49
25 changed files with 137 additions and 139 deletions
|
@ -883,9 +883,10 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
err.help("...or use `match` instead of `let...else`");
|
||||
}
|
||||
_ => {
|
||||
if let ObligationCauseCode::SpannedWhereClause(_, span)
|
||||
| ObligationCauseCode::SpannedWhereClauseInExpr(_, span, ..) =
|
||||
if let ObligationCauseCode::WhereClause(_, span)
|
||||
| ObligationCauseCode::WhereClauseInExpr(_, span, ..) =
|
||||
cause.code().peel_derives()
|
||||
&& !span.is_dummy()
|
||||
&& let TypeError::RegionsPlaceholderMismatch = terr
|
||||
{
|
||||
err.span_note(*span, "the lifetime requirement is introduced here");
|
||||
|
|
|
@ -38,11 +38,14 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
|||
let ObligationCauseCode::MatchImpl(parent, impl_def_id) = code else {
|
||||
return None;
|
||||
};
|
||||
let (ObligationCauseCode::SpannedWhereClause(_, binding_span)
|
||||
| ObligationCauseCode::SpannedWhereClauseInExpr(_, binding_span, ..)) = *parent.code()
|
||||
let (ObligationCauseCode::WhereClause(_, binding_span)
|
||||
| ObligationCauseCode::WhereClauseInExpr(_, binding_span, ..)) = *parent.code()
|
||||
else {
|
||||
return None;
|
||||
};
|
||||
if binding_span.is_dummy() {
|
||||
return None;
|
||||
}
|
||||
|
||||
// FIXME: we should point at the lifetime
|
||||
let multi_span: MultiSpan = vec![binding_span].into();
|
||||
|
|
|
@ -10,7 +10,7 @@ use crate::traits::{ObligationCause, ObligationCauseCode};
|
|||
use rustc_data_structures::intern::Interned;
|
||||
use rustc_errors::{Diag, IntoDiagArg};
|
||||
use rustc_hir::def::Namespace;
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_hir::def_id::{DefId, CRATE_DEF_ID};
|
||||
use rustc_middle::ty::error::ExpectedFound;
|
||||
use rustc_middle::ty::print::{FmtPrinter, Print, PrintTraitRefExt as _, RegionHighlightMode};
|
||||
use rustc_middle::ty::GenericArgsRef;
|
||||
|
@ -240,8 +240,9 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
|
|||
let span = cause.span();
|
||||
|
||||
let (leading_ellipsis, satisfy_span, where_span, dup_span, def_id) =
|
||||
if let ObligationCauseCode::WhereClause(def_id)
|
||||
| ObligationCauseCode::WhereClauseInExpr(def_id, ..) = *cause.code()
|
||||
if let ObligationCauseCode::WhereClause(def_id, span)
|
||||
| ObligationCauseCode::WhereClauseInExpr(def_id, span, ..) = *cause.code()
|
||||
&& def_id != CRATE_DEF_ID.to_def_id()
|
||||
{
|
||||
(
|
||||
true,
|
||||
|
|
|
@ -214,7 +214,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
|||
_ => cause.code(),
|
||||
}
|
||||
&& let (
|
||||
&ObligationCauseCode::WhereClause(item_def_id)
|
||||
&ObligationCauseCode::WhereClause(item_def_id, _)
|
||||
| &ObligationCauseCode::WhereClauseInExpr(item_def_id, ..),
|
||||
None,
|
||||
) = (code, override_error_code)
|
||||
|
|
|
@ -357,21 +357,22 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
infer::Subtype(box ref trace)
|
||||
if matches!(
|
||||
&trace.cause.code().peel_derives(),
|
||||
ObligationCauseCode::SpannedWhereClause(..)
|
||||
| ObligationCauseCode::SpannedWhereClauseInExpr(..)
|
||||
ObligationCauseCode::WhereClause(..)
|
||||
| ObligationCauseCode::WhereClauseInExpr(..)
|
||||
) =>
|
||||
{
|
||||
// Hack to get around the borrow checker because trace.cause has an `Rc`.
|
||||
if let ObligationCauseCode::SpannedWhereClause(_, span)
|
||||
| ObligationCauseCode::SpannedWhereClauseInExpr(_, span, ..) =
|
||||
if let ObligationCauseCode::WhereClause(_, span)
|
||||
| ObligationCauseCode::WhereClauseInExpr(_, span, ..) =
|
||||
&trace.cause.code().peel_derives()
|
||||
&& !span.is_dummy()
|
||||
{
|
||||
let span = *span;
|
||||
self.report_concrete_failure(placeholder_origin, sub, sup)
|
||||
.with_span_note(span, "the lifetime requirement is introduced here")
|
||||
} else {
|
||||
unreachable!(
|
||||
"control flow ensures we have a `BindingObligation` or `SpannedWhereClauseInExpr` here..."
|
||||
"control flow ensures we have a `BindingObligation` or `WhereClauseInExpr` here..."
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -103,8 +103,12 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||
cause.span,
|
||||
sup_type,
|
||||
match cause.code().peel_derives() {
|
||||
ObligationCauseCode::SpannedWhereClause(_, span)
|
||||
| ObligationCauseCode::SpannedWhereClauseInExpr(_, span, ..) => Some(*span),
|
||||
ObligationCauseCode::WhereClause(_, span)
|
||||
| ObligationCauseCode::WhereClauseInExpr(_, span, ..)
|
||||
if !span.is_dummy() =>
|
||||
{
|
||||
Some(*span)
|
||||
}
|
||||
_ => None,
|
||||
},
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue