Rename some ObligationCauseCode variants
This commit is contained in:
parent
4bde8a8f4b
commit
534e267d48
33 changed files with 186 additions and 246 deletions
|
@ -883,9 +883,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
err.help("...or use `match` instead of `let...else`");
|
||||
}
|
||||
_ => {
|
||||
if let ObligationCauseCode::BindingObligation(_, span)
|
||||
| ObligationCauseCode::ExprBindingObligation(_, span, ..) =
|
||||
cause.code().peel_derives()
|
||||
if let ObligationCauseCode::Where(_, span)
|
||||
| ObligationCauseCode::WhereInExpr(_, span, ..) = cause.code().peel_derives()
|
||||
&& let TypeError::RegionsPlaceholderMismatch = terr
|
||||
{
|
||||
err.span_note(*span, "the lifetime requirement is introduced here");
|
||||
|
@ -2776,7 +2775,7 @@ impl<'tcx> ObligationCause<'tcx> {
|
|||
match self.code() {
|
||||
ObligationCauseCode::IfExpressionWithNoElse => FailureCode::Error0317,
|
||||
ObligationCauseCode::MainFunctionType => FailureCode::Error0580,
|
||||
ObligationCauseCode::CompareImplItemObligation { .. }
|
||||
ObligationCauseCode::CompareImplItem { .. }
|
||||
| ObligationCauseCode::MatchExpressionArm(_)
|
||||
| ObligationCauseCode::IfExpression { .. }
|
||||
| ObligationCauseCode::LetElse
|
||||
|
@ -2806,15 +2805,15 @@ impl<'tcx> ObligationCause<'tcx> {
|
|||
subdiags: Vec<TypeErrorAdditionalDiags>,
|
||||
) -> ObligationCauseFailureCode {
|
||||
match self.code() {
|
||||
ObligationCauseCode::CompareImplItemObligation { kind: ty::AssocKind::Fn, .. } => {
|
||||
ObligationCauseCode::CompareImplItem { kind: ty::AssocKind::Fn, .. } => {
|
||||
ObligationCauseFailureCode::MethodCompat { span, subdiags }
|
||||
}
|
||||
ObligationCauseCode::CompareImplItemObligation {
|
||||
kind: ty::AssocKind::Type, ..
|
||||
} => ObligationCauseFailureCode::TypeCompat { span, subdiags },
|
||||
ObligationCauseCode::CompareImplItemObligation {
|
||||
kind: ty::AssocKind::Const, ..
|
||||
} => ObligationCauseFailureCode::ConstCompat { span, subdiags },
|
||||
ObligationCauseCode::CompareImplItem { kind: ty::AssocKind::Type, .. } => {
|
||||
ObligationCauseFailureCode::TypeCompat { span, subdiags }
|
||||
}
|
||||
ObligationCauseCode::CompareImplItem { kind: ty::AssocKind::Const, .. } => {
|
||||
ObligationCauseFailureCode::ConstCompat { span, subdiags }
|
||||
}
|
||||
ObligationCauseCode::BlockTailExpression(.., hir::MatchSource::TryDesugar(_)) => {
|
||||
ObligationCauseFailureCode::TryCompat { span, subdiags }
|
||||
}
|
||||
|
@ -2870,15 +2869,15 @@ impl<'tcx> ObligationCause<'tcx> {
|
|||
|
||||
fn as_requirement_str(&self) -> &'static str {
|
||||
match self.code() {
|
||||
ObligationCauseCode::CompareImplItemObligation { kind: ty::AssocKind::Fn, .. } => {
|
||||
ObligationCauseCode::CompareImplItem { kind: ty::AssocKind::Fn, .. } => {
|
||||
"method type is compatible with trait"
|
||||
}
|
||||
ObligationCauseCode::CompareImplItemObligation {
|
||||
kind: ty::AssocKind::Type, ..
|
||||
} => "associated type is compatible with trait",
|
||||
ObligationCauseCode::CompareImplItemObligation {
|
||||
kind: ty::AssocKind::Const, ..
|
||||
} => "const is compatible with trait",
|
||||
ObligationCauseCode::CompareImplItem { kind: ty::AssocKind::Type, .. } => {
|
||||
"associated type is compatible with trait"
|
||||
}
|
||||
ObligationCauseCode::CompareImplItem { kind: ty::AssocKind::Const, .. } => {
|
||||
"const is compatible with trait"
|
||||
}
|
||||
ObligationCauseCode::MainFunctionType => "`main` function has the correct type",
|
||||
ObligationCauseCode::StartFunctionType => "`#[start]` function has the correct type",
|
||||
ObligationCauseCode::LangFunctionType(_) => "lang item function has the correct type",
|
||||
|
@ -2895,15 +2894,11 @@ pub struct ObligationCauseAsDiagArg<'tcx>(pub ObligationCause<'tcx>);
|
|||
impl IntoDiagArg for ObligationCauseAsDiagArg<'_> {
|
||||
fn into_diag_arg(self) -> rustc_errors::DiagArgValue {
|
||||
let kind = match self.0.code() {
|
||||
ObligationCauseCode::CompareImplItemObligation { kind: ty::AssocKind::Fn, .. } => {
|
||||
"method_compat"
|
||||
ObligationCauseCode::CompareImplItem { kind: ty::AssocKind::Fn, .. } => "method_compat",
|
||||
ObligationCauseCode::CompareImplItem { kind: ty::AssocKind::Type, .. } => "type_compat",
|
||||
ObligationCauseCode::CompareImplItem { kind: ty::AssocKind::Const, .. } => {
|
||||
"const_compat"
|
||||
}
|
||||
ObligationCauseCode::CompareImplItemObligation {
|
||||
kind: ty::AssocKind::Type, ..
|
||||
} => "type_compat",
|
||||
ObligationCauseCode::CompareImplItemObligation {
|
||||
kind: ty::AssocKind::Const, ..
|
||||
} => "const_compat",
|
||||
ObligationCauseCode::MainFunctionType => "fn_main_correct_type",
|
||||
ObligationCauseCode::StartFunctionType => "fn_start_correct_type",
|
||||
ObligationCauseCode::LangFunctionType(_) => "fn_lang_correct_type",
|
||||
|
|
|
@ -32,14 +32,14 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
|||
// If we added a "points at argument expression" obligation, we remove it here, we care
|
||||
// about the original obligation only.
|
||||
let code = match cause.code() {
|
||||
ObligationCauseCode::FunctionArgumentObligation { parent_code, .. } => &*parent_code,
|
||||
ObligationCauseCode::FunctionArg { parent_code, .. } => &*parent_code,
|
||||
code => code,
|
||||
};
|
||||
let ObligationCauseCode::MatchImpl(parent, impl_def_id) = code else {
|
||||
return None;
|
||||
};
|
||||
let (ObligationCauseCode::BindingObligation(_, binding_span)
|
||||
| ObligationCauseCode::ExprBindingObligation(_, binding_span, ..)) = *parent.code()
|
||||
let (ObligationCauseCode::Where(_, binding_span)
|
||||
| ObligationCauseCode::WhereInExpr(_, binding_span, ..)) = *parent.code()
|
||||
else {
|
||||
return None;
|
||||
};
|
||||
|
|
|
@ -240,8 +240,8 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
|
|||
let span = cause.span();
|
||||
|
||||
let (leading_ellipsis, satisfy_span, where_span, dup_span, def_id) =
|
||||
if let ObligationCauseCode::ItemObligation(def_id)
|
||||
| ObligationCauseCode::ExprItemObligation(def_id, ..) = *cause.code()
|
||||
if let ObligationCauseCode::MiscItem(def_id)
|
||||
| ObligationCauseCode::MiscItemInExpr(def_id, ..) = *cause.code()
|
||||
{
|
||||
(
|
||||
true,
|
||||
|
|
|
@ -214,8 +214,8 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
|||
_ => cause.code(),
|
||||
}
|
||||
&& let (
|
||||
&ObligationCauseCode::ItemObligation(item_def_id)
|
||||
| &ObligationCauseCode::ExprItemObligation(item_def_id, ..),
|
||||
&ObligationCauseCode::MiscItem(item_def_id)
|
||||
| &ObligationCauseCode::MiscItemInExpr(item_def_id, ..),
|
||||
None,
|
||||
) = (code, override_error_code)
|
||||
{
|
||||
|
|
|
@ -357,13 +357,12 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
infer::Subtype(box ref trace)
|
||||
if matches!(
|
||||
&trace.cause.code().peel_derives(),
|
||||
ObligationCauseCode::BindingObligation(..)
|
||||
| ObligationCauseCode::ExprBindingObligation(..)
|
||||
ObligationCauseCode::Where(..) | ObligationCauseCode::WhereInExpr(..)
|
||||
) =>
|
||||
{
|
||||
// Hack to get around the borrow checker because trace.cause has an `Rc`.
|
||||
if let ObligationCauseCode::BindingObligation(_, span)
|
||||
| ObligationCauseCode::ExprBindingObligation(_, span, ..) =
|
||||
if let ObligationCauseCode::Where(_, span)
|
||||
| ObligationCauseCode::WhereInExpr(_, span, ..) =
|
||||
&trace.cause.code().peel_derives()
|
||||
{
|
||||
let span = *span;
|
||||
|
|
|
@ -629,8 +629,7 @@ impl<T> Trait<T> for X {
|
|||
| hir::Node::ImplItem(hir::ImplItem { kind: hir::ImplItemKind::Fn(..), .. }),
|
||||
)
|
||||
);
|
||||
let impl_comparison =
|
||||
matches!(cause_code, ObligationCauseCode::CompareImplItemObligation { .. });
|
||||
let impl_comparison = matches!(cause_code, ObligationCauseCode::CompareImplItem { .. });
|
||||
let assoc = tcx.associated_item(proj_ty.def_id);
|
||||
if impl_comparison {
|
||||
// We do not want to suggest calling functions when the reason of the
|
||||
|
|
|
@ -167,7 +167,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
exp_span, exp_found.expected, exp_found.found,
|
||||
);
|
||||
|
||||
if let ObligationCauseCode::CompareImplItemObligation { .. } = cause.code() {
|
||||
if let ObligationCauseCode::CompareImplItem { .. } = cause.code() {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -1876,7 +1876,7 @@ impl<'tcx> SubregionOrigin<'tcx> {
|
|||
SubregionOrigin::ReferenceOutlivesReferent(ref_type, cause.span)
|
||||
}
|
||||
|
||||
traits::ObligationCauseCode::CompareImplItemObligation {
|
||||
traits::ObligationCauseCode::CompareImplItem {
|
||||
impl_item_def_id,
|
||||
trait_item_def_id,
|
||||
kind: _,
|
||||
|
|
|
@ -103,8 +103,8 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||
cause.span,
|
||||
sup_type,
|
||||
match cause.code().peel_derives() {
|
||||
ObligationCauseCode::BindingObligation(_, span)
|
||||
| ObligationCauseCode::ExprBindingObligation(_, span, ..) => Some(*span),
|
||||
ObligationCauseCode::Where(_, span)
|
||||
| ObligationCauseCode::WhereInExpr(_, span, ..) => Some(*span),
|
||||
_ => None,
|
||||
},
|
||||
)
|
||||
|
|
|
@ -129,14 +129,12 @@ impl<'tcx> Elaboratable<'tcx> for PredicateObligation<'tcx> {
|
|||
index: usize,
|
||||
) -> Self {
|
||||
let cause = self.cause.clone().derived_cause(parent_trait_pred, |derived| {
|
||||
ObligationCauseCode::ImplDerivedObligation(Box::new(
|
||||
traits::ImplDerivedObligationCause {
|
||||
derived,
|
||||
impl_or_alias_def_id: parent_trait_pred.def_id(),
|
||||
impl_def_predicate_index: Some(index),
|
||||
span,
|
||||
},
|
||||
))
|
||||
ObligationCauseCode::ImplDerived(Box::new(traits::ImplDerivedObligationCause {
|
||||
derived,
|
||||
impl_or_alias_def_id: parent_trait_pred.def_id(),
|
||||
impl_def_predicate_index: Some(index),
|
||||
span,
|
||||
}))
|
||||
});
|
||||
Obligation {
|
||||
cause,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue