Remove glob imports for ObligationCauseCode
This commit is contained in:
parent
04c049498d
commit
4bde8a8f4b
24 changed files with 279 additions and 178 deletions
|
@ -2773,19 +2773,17 @@ pub enum FailureCode {
|
|||
#[extension(pub trait ObligationCauseExt<'tcx>)]
|
||||
impl<'tcx> ObligationCause<'tcx> {
|
||||
fn as_failure_code(&self, terr: TypeError<'tcx>) -> FailureCode {
|
||||
use self::FailureCode::*;
|
||||
use crate::traits::ObligationCauseCode::*;
|
||||
match self.code() {
|
||||
IfExpressionWithNoElse => Error0317,
|
||||
MainFunctionType => Error0580,
|
||||
CompareImplItemObligation { .. }
|
||||
| MatchExpressionArm(_)
|
||||
| IfExpression { .. }
|
||||
| LetElse
|
||||
| StartFunctionType
|
||||
| LangFunctionType(_)
|
||||
| IntrinsicType
|
||||
| MethodReceiver => Error0308,
|
||||
ObligationCauseCode::IfExpressionWithNoElse => FailureCode::Error0317,
|
||||
ObligationCauseCode::MainFunctionType => FailureCode::Error0580,
|
||||
ObligationCauseCode::CompareImplItemObligation { .. }
|
||||
| ObligationCauseCode::MatchExpressionArm(_)
|
||||
| ObligationCauseCode::IfExpression { .. }
|
||||
| ObligationCauseCode::LetElse
|
||||
| ObligationCauseCode::StartFunctionType
|
||||
| ObligationCauseCode::LangFunctionType(_)
|
||||
| ObligationCauseCode::IntrinsicType
|
||||
| ObligationCauseCode::MethodReceiver => FailureCode::Error0308,
|
||||
|
||||
// In the case where we have no more specific thing to
|
||||
// say, also take a look at the error code, maybe we can
|
||||
|
@ -2794,10 +2792,10 @@ impl<'tcx> ObligationCause<'tcx> {
|
|||
TypeError::CyclicTy(ty)
|
||||
if ty.is_closure() || ty.is_coroutine() || ty.is_coroutine_closure() =>
|
||||
{
|
||||
Error0644
|
||||
FailureCode::Error0644
|
||||
}
|
||||
TypeError::IntrinsicCast => Error0308,
|
||||
_ => Error0308,
|
||||
TypeError::IntrinsicCast => FailureCode::Error0308,
|
||||
_ => FailureCode::Error0308,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -2807,36 +2805,51 @@ impl<'tcx> ObligationCause<'tcx> {
|
|||
span: Span,
|
||||
subdiags: Vec<TypeErrorAdditionalDiags>,
|
||||
) -> ObligationCauseFailureCode {
|
||||
use crate::traits::ObligationCauseCode::*;
|
||||
match self.code() {
|
||||
CompareImplItemObligation { kind: ty::AssocKind::Fn, .. } => {
|
||||
ObligationCauseCode::CompareImplItemObligation { kind: ty::AssocKind::Fn, .. } => {
|
||||
ObligationCauseFailureCode::MethodCompat { span, subdiags }
|
||||
}
|
||||
CompareImplItemObligation { kind: ty::AssocKind::Type, .. } => {
|
||||
ObligationCauseFailureCode::TypeCompat { span, subdiags }
|
||||
}
|
||||
CompareImplItemObligation { kind: ty::AssocKind::Const, .. } => {
|
||||
ObligationCauseFailureCode::ConstCompat { span, subdiags }
|
||||
}
|
||||
BlockTailExpression(.., hir::MatchSource::TryDesugar(_)) => {
|
||||
ObligationCauseCode::CompareImplItemObligation {
|
||||
kind: ty::AssocKind::Type, ..
|
||||
} => ObligationCauseFailureCode::TypeCompat { span, subdiags },
|
||||
ObligationCauseCode::CompareImplItemObligation {
|
||||
kind: ty::AssocKind::Const, ..
|
||||
} => ObligationCauseFailureCode::ConstCompat { span, subdiags },
|
||||
ObligationCauseCode::BlockTailExpression(.., hir::MatchSource::TryDesugar(_)) => {
|
||||
ObligationCauseFailureCode::TryCompat { span, subdiags }
|
||||
}
|
||||
MatchExpressionArm(box MatchExpressionArmCause { source, .. }) => match source {
|
||||
ObligationCauseCode::MatchExpressionArm(box MatchExpressionArmCause {
|
||||
source, ..
|
||||
}) => match source {
|
||||
hir::MatchSource::TryDesugar(_) => {
|
||||
ObligationCauseFailureCode::TryCompat { span, subdiags }
|
||||
}
|
||||
_ => ObligationCauseFailureCode::MatchCompat { span, subdiags },
|
||||
},
|
||||
IfExpression { .. } => ObligationCauseFailureCode::IfElseDifferent { span, subdiags },
|
||||
IfExpressionWithNoElse => ObligationCauseFailureCode::NoElse { span },
|
||||
LetElse => ObligationCauseFailureCode::NoDiverge { span, subdiags },
|
||||
MainFunctionType => ObligationCauseFailureCode::FnMainCorrectType { span },
|
||||
StartFunctionType => ObligationCauseFailureCode::FnStartCorrectType { span, subdiags },
|
||||
&LangFunctionType(lang_item_name) => {
|
||||
ObligationCauseCode::IfExpression { .. } => {
|
||||
ObligationCauseFailureCode::IfElseDifferent { span, subdiags }
|
||||
}
|
||||
ObligationCauseCode::IfExpressionWithNoElse => {
|
||||
ObligationCauseFailureCode::NoElse { span }
|
||||
}
|
||||
ObligationCauseCode::LetElse => {
|
||||
ObligationCauseFailureCode::NoDiverge { span, subdiags }
|
||||
}
|
||||
ObligationCauseCode::MainFunctionType => {
|
||||
ObligationCauseFailureCode::FnMainCorrectType { span }
|
||||
}
|
||||
ObligationCauseCode::StartFunctionType => {
|
||||
ObligationCauseFailureCode::FnStartCorrectType { span, subdiags }
|
||||
}
|
||||
&ObligationCauseCode::LangFunctionType(lang_item_name) => {
|
||||
ObligationCauseFailureCode::FnLangCorrectType { span, subdiags, lang_item_name }
|
||||
}
|
||||
IntrinsicType => ObligationCauseFailureCode::IntrinsicCorrectType { span, subdiags },
|
||||
MethodReceiver => ObligationCauseFailureCode::MethodCorrectType { span, subdiags },
|
||||
ObligationCauseCode::IntrinsicType => {
|
||||
ObligationCauseFailureCode::IntrinsicCorrectType { span, subdiags }
|
||||
}
|
||||
ObligationCauseCode::MethodReceiver => {
|
||||
ObligationCauseFailureCode::MethodCorrectType { span, subdiags }
|
||||
}
|
||||
|
||||
// In the case where we have no more specific thing to
|
||||
// say, also take a look at the error code, maybe we can
|
||||
|
@ -2856,22 +2869,21 @@ impl<'tcx> ObligationCause<'tcx> {
|
|||
}
|
||||
|
||||
fn as_requirement_str(&self) -> &'static str {
|
||||
use crate::traits::ObligationCauseCode::*;
|
||||
match self.code() {
|
||||
CompareImplItemObligation { kind: ty::AssocKind::Fn, .. } => {
|
||||
ObligationCauseCode::CompareImplItemObligation { kind: ty::AssocKind::Fn, .. } => {
|
||||
"method type is compatible with trait"
|
||||
}
|
||||
CompareImplItemObligation { kind: ty::AssocKind::Type, .. } => {
|
||||
"associated type is compatible with trait"
|
||||
}
|
||||
CompareImplItemObligation { kind: ty::AssocKind::Const, .. } => {
|
||||
"const is compatible with trait"
|
||||
}
|
||||
MainFunctionType => "`main` function has the correct type",
|
||||
StartFunctionType => "`#[start]` function has the correct type",
|
||||
LangFunctionType(_) => "lang item function has the correct type",
|
||||
IntrinsicType => "intrinsic has the correct type",
|
||||
MethodReceiver => "method receiver has the correct type",
|
||||
ObligationCauseCode::CompareImplItemObligation {
|
||||
kind: ty::AssocKind::Type, ..
|
||||
} => "associated type is compatible with trait",
|
||||
ObligationCauseCode::CompareImplItemObligation {
|
||||
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",
|
||||
ObligationCauseCode::IntrinsicType => "intrinsic has the correct type",
|
||||
ObligationCauseCode::MethodReceiver => "method receiver has the correct type",
|
||||
_ => "types are compatible",
|
||||
}
|
||||
}
|
||||
|
@ -2882,16 +2894,21 @@ pub struct ObligationCauseAsDiagArg<'tcx>(pub ObligationCause<'tcx>);
|
|||
|
||||
impl IntoDiagArg for ObligationCauseAsDiagArg<'_> {
|
||||
fn into_diag_arg(self) -> rustc_errors::DiagArgValue {
|
||||
use crate::traits::ObligationCauseCode::*;
|
||||
let kind = match self.0.code() {
|
||||
CompareImplItemObligation { kind: ty::AssocKind::Fn, .. } => "method_compat",
|
||||
CompareImplItemObligation { kind: ty::AssocKind::Type, .. } => "type_compat",
|
||||
CompareImplItemObligation { kind: ty::AssocKind::Const, .. } => "const_compat",
|
||||
MainFunctionType => "fn_main_correct_type",
|
||||
StartFunctionType => "fn_start_correct_type",
|
||||
LangFunctionType(_) => "fn_lang_correct_type",
|
||||
IntrinsicType => "intrinsic_correct_type",
|
||||
MethodReceiver => "method_correct_type",
|
||||
ObligationCauseCode::CompareImplItemObligation { kind: ty::AssocKind::Fn, .. } => {
|
||||
"method_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",
|
||||
ObligationCauseCode::IntrinsicType => "intrinsic_correct_type",
|
||||
ObligationCauseCode::MethodReceiver => "method_correct_type",
|
||||
_ => "other",
|
||||
}
|
||||
.into();
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use smallvec::smallvec;
|
||||
|
||||
use crate::infer::outlives::components::{push_outlives_components, Component};
|
||||
use crate::traits::{self, Obligation, PredicateObligation};
|
||||
use crate::traits::{self, Obligation, ObligationCauseCode, PredicateObligation};
|
||||
use rustc_data_structures::fx::FxHashSet;
|
||||
use rustc_middle::ty::{self, ToPredicate, Ty, TyCtxt};
|
||||
use rustc_span::symbol::Ident;
|
||||
|
@ -129,12 +129,14 @@ impl<'tcx> Elaboratable<'tcx> for PredicateObligation<'tcx> {
|
|||
index: usize,
|
||||
) -> Self {
|
||||
let cause = self.cause.clone().derived_cause(parent_trait_pred, |derived| {
|
||||
traits::ImplDerivedObligation(Box::new(traits::ImplDerivedObligationCause {
|
||||
derived,
|
||||
impl_or_alias_def_id: parent_trait_pred.def_id(),
|
||||
impl_def_predicate_index: Some(index),
|
||||
span,
|
||||
}))
|
||||
ObligationCauseCode::ImplDerivedObligation(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